@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.11.rc.004'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.11.rc.004'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | placeholder="Datetime Description (optional)"><?php echo $DTT_description; ?></textarea> |
9 | 9 | </div> |
10 | 10 | <?php do_action( |
11 | - 'AHEE__event_tickets_datetime_attached_tickets_row_template__advanced_details_after_dtt_description', |
|
12 | - $dtt_row, |
|
13 | - $DTT_ID |
|
14 | - ); ?> |
|
11 | + 'AHEE__event_tickets_datetime_attached_tickets_row_template__advanced_details_after_dtt_description', |
|
12 | + $dtt_row, |
|
13 | + $DTT_ID |
|
14 | + ); ?> |
|
15 | 15 | <h4 class="datetime-tickets-heading"><?php esc_html_e('Assigned Tickets', 'event_espresso'); ?></h4> |
16 | 16 | |
17 | 17 | <ul class="datetime-tickets-list"> |
@@ -21,28 +21,28 @@ discard block |
||
21 | 21 | |
22 | 22 | <div class="add-datetime-ticket-container"> |
23 | 23 | <h4 class="datetime-tickets-heading"><?php |
24 | - esc_html_e( |
|
25 | - 'Add New Ticket', |
|
26 | - 'event_espresso' |
|
27 | - ); ?></h4><?php echo $add_new_datetime_ticket_help_link; ?><br> |
|
24 | + esc_html_e( |
|
25 | + 'Add New Ticket', |
|
26 | + 'event_espresso' |
|
27 | + ); ?></h4><?php echo $add_new_datetime_ticket_help_link; ?><br> |
|
28 | 28 | <table class="add-new-ticket-table"> |
29 | 29 | <thead> |
30 | 30 | <tr valign="top"> |
31 | 31 | <td><span class="ANT_TKT_name_label"><?php |
32 | - esc_html_e( |
|
33 | - 'Ticket Name', |
|
34 | - 'event_espresso' |
|
35 | - ); ?></span></td> |
|
32 | + esc_html_e( |
|
33 | + 'Ticket Name', |
|
34 | + 'event_espresso' |
|
35 | + ); ?></span></td> |
|
36 | 36 | <td><span class="ANT_TKT_goes_on_sale_label"><?php |
37 | - esc_html_e( |
|
38 | - 'Sale Starts', |
|
39 | - 'event_espresso' |
|
40 | - ); ?></span></td> |
|
37 | + esc_html_e( |
|
38 | + 'Sale Starts', |
|
39 | + 'event_espresso' |
|
40 | + ); ?></span></td> |
|
41 | 41 | <td><span class="ANT_TKT_sell_until_label"><?php |
42 | - esc_html_e( |
|
43 | - 'Sell Until', |
|
44 | - 'event_espresso' |
|
45 | - ); ?></span></td> |
|
42 | + esc_html_e( |
|
43 | + 'Sell Until', |
|
44 | + 'event_espresso' |
|
45 | + ); ?></span></td> |
|
46 | 46 | <td><span class="ANT_TKT_price_label"><?php esc_html_e('Price', 'event_espresso'); ?></span> |
47 | 47 | </td> |
48 | 48 | <td><span class="ANT_TKT_qty_label"><?php esc_html_e('Qty', 'event_espresso'); ?></span></td> |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | <div class="ee-editor-footer-container"> |
93 | 93 | <div class="ee-editor-id-container"> |
94 | 94 | <span class="ee-item-id"><?php |
95 | - echo $DTT_ID |
|
96 | - ? sprintf( |
|
97 | - esc_html__('Datetime ID: %d', 'event_espresso'), |
|
98 | - $DTT_ID |
|
99 | - ) |
|
100 | - : ''; ?></span> |
|
95 | + echo $DTT_ID |
|
96 | + ? sprintf( |
|
97 | + esc_html__('Datetime ID: %d', 'event_espresso'), |
|
98 | + $DTT_ID |
|
99 | + ) |
|
100 | + : ''; ?></span> |
|
101 | 101 | </div> |
102 | 102 | <div class="save-cancel-button-container"> |
103 | 103 | <button data-context="short-ticket" data-datetime-row="<?php echo $dtt_row; ?>" |
@@ -15,2201 +15,2201 @@ |
||
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This property is just used to hold the status of whether an event is currently being |
|
20 | - * created (true) or edited (false) |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $_is_creating_event; |
|
18 | + /** |
|
19 | + * This property is just used to hold the status of whether an event is currently being |
|
20 | + * created (true) or edited (false) |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $_is_creating_event; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Used to contain the format strings for date and time that will be used for php date and |
|
29 | - * time. |
|
30 | - * Is set in the _set_hooks_properties() method. |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $_date_format_strings; |
|
27 | + /** |
|
28 | + * Used to contain the format strings for date and time that will be used for php date and |
|
29 | + * time. |
|
30 | + * Is set in the _set_hooks_properties() method. |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $_date_format_strings; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var string $_date_time_format |
|
38 | - */ |
|
39 | - protected $_date_time_format; |
|
36 | + /** |
|
37 | + * @var string $_date_time_format |
|
38 | + */ |
|
39 | + protected $_date_time_format; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @throws InvalidArgumentException |
|
44 | - * @throws InvalidInterfaceException |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - */ |
|
47 | - protected function _set_hooks_properties() |
|
48 | - { |
|
49 | - $this->_name = 'pricing'; |
|
50 | - // capability check |
|
51 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
52 | - 'ee_read_default_prices', |
|
53 | - 'advanced_ticket_datetime_metabox' |
|
54 | - )) { |
|
55 | - return; |
|
56 | - } |
|
57 | - $this->_setup_metaboxes(); |
|
58 | - $this->_set_date_time_formats(); |
|
59 | - $this->_validate_format_strings(); |
|
60 | - $this->_set_scripts_styles(); |
|
61 | - // commented out temporarily until logic is implemented in callback |
|
62 | - // add_action( |
|
63 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
64 | - // array($this, 'autosave_handling') |
|
65 | - // ); |
|
66 | - add_filter( |
|
67 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
68 | - array($this, 'caf_updates') |
|
69 | - ); |
|
70 | - } |
|
42 | + /** |
|
43 | + * @throws InvalidArgumentException |
|
44 | + * @throws InvalidInterfaceException |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + */ |
|
47 | + protected function _set_hooks_properties() |
|
48 | + { |
|
49 | + $this->_name = 'pricing'; |
|
50 | + // capability check |
|
51 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
52 | + 'ee_read_default_prices', |
|
53 | + 'advanced_ticket_datetime_metabox' |
|
54 | + )) { |
|
55 | + return; |
|
56 | + } |
|
57 | + $this->_setup_metaboxes(); |
|
58 | + $this->_set_date_time_formats(); |
|
59 | + $this->_validate_format_strings(); |
|
60 | + $this->_set_scripts_styles(); |
|
61 | + // commented out temporarily until logic is implemented in callback |
|
62 | + // add_action( |
|
63 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
64 | + // array($this, 'autosave_handling') |
|
65 | + // ); |
|
66 | + add_filter( |
|
67 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
68 | + array($this, 'caf_updates') |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - protected function _setup_metaboxes() |
|
77 | - { |
|
78 | - // if we were going to add our own metaboxes we'd use the below. |
|
79 | - $this->_metaboxes = array( |
|
80 | - 0 => array( |
|
81 | - 'page_route' => array('edit', 'create_new'), |
|
82 | - 'func' => 'pricing_metabox', |
|
83 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
84 | - 'priority' => 'high', |
|
85 | - 'context' => 'normal', |
|
86 | - ), |
|
87 | - ); |
|
88 | - $this->_remove_metaboxes = array( |
|
89 | - 0 => array( |
|
90 | - 'page_route' => array('edit', 'create_new'), |
|
91 | - 'id' => 'espresso_event_editor_tickets', |
|
92 | - 'context' => 'normal', |
|
93 | - ), |
|
94 | - ); |
|
95 | - } |
|
73 | + /** |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + protected function _setup_metaboxes() |
|
77 | + { |
|
78 | + // if we were going to add our own metaboxes we'd use the below. |
|
79 | + $this->_metaboxes = array( |
|
80 | + 0 => array( |
|
81 | + 'page_route' => array('edit', 'create_new'), |
|
82 | + 'func' => 'pricing_metabox', |
|
83 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
84 | + 'priority' => 'high', |
|
85 | + 'context' => 'normal', |
|
86 | + ), |
|
87 | + ); |
|
88 | + $this->_remove_metaboxes = array( |
|
89 | + 0 => array( |
|
90 | + 'page_route' => array('edit', 'create_new'), |
|
91 | + 'id' => 'espresso_event_editor_tickets', |
|
92 | + 'context' => 'normal', |
|
93 | + ), |
|
94 | + ); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - protected function _set_date_time_formats() |
|
102 | - { |
|
103 | - /** |
|
104 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
105 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
106 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
107 | - * |
|
108 | - * @since 4.6.7 |
|
109 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
110 | - */ |
|
111 | - $this->_date_format_strings = apply_filters( |
|
112 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
113 | - array( |
|
114 | - 'date' => 'Y-m-d', |
|
115 | - 'time' => 'h:i a', |
|
116 | - ) |
|
117 | - ); |
|
118 | - // validate |
|
119 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
120 | - ? $this->_date_format_strings['date'] |
|
121 | - : null; |
|
122 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
123 | - ? $this->_date_format_strings['time'] |
|
124 | - : null; |
|
125 | - $this->_date_time_format = $this->_date_format_strings['date'] |
|
126 | - . ' ' |
|
127 | - . $this->_date_format_strings['time']; |
|
128 | - } |
|
98 | + /** |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + protected function _set_date_time_formats() |
|
102 | + { |
|
103 | + /** |
|
104 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
105 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
106 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
107 | + * |
|
108 | + * @since 4.6.7 |
|
109 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
110 | + */ |
|
111 | + $this->_date_format_strings = apply_filters( |
|
112 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
113 | + array( |
|
114 | + 'date' => 'Y-m-d', |
|
115 | + 'time' => 'h:i a', |
|
116 | + ) |
|
117 | + ); |
|
118 | + // validate |
|
119 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
120 | + ? $this->_date_format_strings['date'] |
|
121 | + : null; |
|
122 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
123 | + ? $this->_date_format_strings['time'] |
|
124 | + : null; |
|
125 | + $this->_date_time_format = $this->_date_format_strings['date'] |
|
126 | + . ' ' |
|
127 | + . $this->_date_format_strings['time']; |
|
128 | + } |
|
129 | 129 | |
130 | 130 | |
131 | - /** |
|
132 | - * @return void |
|
133 | - */ |
|
134 | - protected function _validate_format_strings() |
|
135 | - { |
|
136 | - // validate format strings |
|
137 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
138 | - $this->_date_time_format |
|
139 | - ); |
|
140 | - if (is_array($format_validation)) { |
|
141 | - $msg = '<p>'; |
|
142 | - $msg .= sprintf( |
|
143 | - esc_html__( |
|
144 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
145 | - 'event_espresso' |
|
146 | - ), |
|
147 | - $this->_date_time_format |
|
148 | - ); |
|
149 | - $msg .= '</p><ul>'; |
|
150 | - foreach ($format_validation as $error) { |
|
151 | - $msg .= '<li>' . $error . '</li>'; |
|
152 | - } |
|
153 | - $msg .= '</ul><p>'; |
|
154 | - $msg .= sprintf( |
|
155 | - esc_html__( |
|
156 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - '<span style="color:#D54E21;">', |
|
160 | - '</span>' |
|
161 | - ); |
|
162 | - $msg .= '</p>'; |
|
163 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
164 | - $this->_date_format_strings = array( |
|
165 | - 'date' => 'Y-m-d', |
|
166 | - 'time' => 'h:i a', |
|
167 | - ); |
|
168 | - } |
|
169 | - } |
|
131 | + /** |
|
132 | + * @return void |
|
133 | + */ |
|
134 | + protected function _validate_format_strings() |
|
135 | + { |
|
136 | + // validate format strings |
|
137 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
138 | + $this->_date_time_format |
|
139 | + ); |
|
140 | + if (is_array($format_validation)) { |
|
141 | + $msg = '<p>'; |
|
142 | + $msg .= sprintf( |
|
143 | + esc_html__( |
|
144 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
145 | + 'event_espresso' |
|
146 | + ), |
|
147 | + $this->_date_time_format |
|
148 | + ); |
|
149 | + $msg .= '</p><ul>'; |
|
150 | + foreach ($format_validation as $error) { |
|
151 | + $msg .= '<li>' . $error . '</li>'; |
|
152 | + } |
|
153 | + $msg .= '</ul><p>'; |
|
154 | + $msg .= sprintf( |
|
155 | + esc_html__( |
|
156 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + '<span style="color:#D54E21;">', |
|
160 | + '</span>' |
|
161 | + ); |
|
162 | + $msg .= '</p>'; |
|
163 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
164 | + $this->_date_format_strings = array( |
|
165 | + 'date' => 'Y-m-d', |
|
166 | + 'time' => 'h:i a', |
|
167 | + ); |
|
168 | + } |
|
169 | + } |
|
170 | 170 | |
171 | 171 | |
172 | - /** |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - protected function _set_scripts_styles() |
|
176 | - { |
|
177 | - $this->_scripts_styles = array( |
|
178 | - 'registers' => array( |
|
179 | - 'ee-tickets-datetimes-css' => array( |
|
180 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
181 | - 'type' => 'css', |
|
182 | - ), |
|
183 | - 'ee-dtt-ticket-metabox' => array( |
|
184 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
185 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
186 | - ), |
|
187 | - ), |
|
188 | - 'deregisters' => array( |
|
189 | - 'event-editor-css' => array('type' => 'css'), |
|
190 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
191 | - ), |
|
192 | - 'enqueues' => array( |
|
193 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
194 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
195 | - ), |
|
196 | - 'localize' => array( |
|
197 | - 'ee-dtt-ticket-metabox' => array( |
|
198 | - 'DTT_TRASH_BLOCK' => array( |
|
199 | - 'main_warning' => esc_html__( |
|
200 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
201 | - 'event_espresso' |
|
202 | - ), |
|
203 | - 'after_warning' => esc_html__( |
|
204 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
205 | - 'event_espresso' |
|
206 | - ), |
|
207 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
208 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
209 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
210 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
211 | - 'single_warning_from_tkt' => esc_html__( |
|
212 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
213 | - 'event_espresso' |
|
214 | - ), |
|
215 | - 'single_warning_from_dtt' => esc_html__( |
|
216 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
217 | - 'event_espresso' |
|
218 | - ), |
|
219 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
220 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
221 | - ), |
|
222 | - 'DTT_ERROR_MSG' => array( |
|
223 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
224 | - 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
225 | - . '<button class="button-secondary ee-modal-cancel">' |
|
226 | - . esc_html__('Dismiss', 'event_espresso') |
|
227 | - . '</button></div>', |
|
228 | - ), |
|
229 | - 'DTT_OVERSELL_WARNING' => array( |
|
230 | - 'datetime_ticket' => esc_html__( |
|
231 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
232 | - 'event_espresso' |
|
233 | - ), |
|
234 | - 'ticket_datetime' => esc_html__( |
|
235 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
236 | - 'event_espresso' |
|
237 | - ), |
|
238 | - ), |
|
239 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
240 | - $this->_date_format_strings['date'], |
|
241 | - $this->_date_format_strings['time'] |
|
242 | - ), |
|
243 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
244 | - ), |
|
245 | - ), |
|
246 | - ); |
|
247 | - } |
|
172 | + /** |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + protected function _set_scripts_styles() |
|
176 | + { |
|
177 | + $this->_scripts_styles = array( |
|
178 | + 'registers' => array( |
|
179 | + 'ee-tickets-datetimes-css' => array( |
|
180 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
181 | + 'type' => 'css', |
|
182 | + ), |
|
183 | + 'ee-dtt-ticket-metabox' => array( |
|
184 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
185 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
186 | + ), |
|
187 | + ), |
|
188 | + 'deregisters' => array( |
|
189 | + 'event-editor-css' => array('type' => 'css'), |
|
190 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
191 | + ), |
|
192 | + 'enqueues' => array( |
|
193 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
194 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
195 | + ), |
|
196 | + 'localize' => array( |
|
197 | + 'ee-dtt-ticket-metabox' => array( |
|
198 | + 'DTT_TRASH_BLOCK' => array( |
|
199 | + 'main_warning' => esc_html__( |
|
200 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
201 | + 'event_espresso' |
|
202 | + ), |
|
203 | + 'after_warning' => esc_html__( |
|
204 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
205 | + 'event_espresso' |
|
206 | + ), |
|
207 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
208 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
209 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
210 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
211 | + 'single_warning_from_tkt' => esc_html__( |
|
212 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
213 | + 'event_espresso' |
|
214 | + ), |
|
215 | + 'single_warning_from_dtt' => esc_html__( |
|
216 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
217 | + 'event_espresso' |
|
218 | + ), |
|
219 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
220 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
221 | + ), |
|
222 | + 'DTT_ERROR_MSG' => array( |
|
223 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
224 | + 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
225 | + . '<button class="button-secondary ee-modal-cancel">' |
|
226 | + . esc_html__('Dismiss', 'event_espresso') |
|
227 | + . '</button></div>', |
|
228 | + ), |
|
229 | + 'DTT_OVERSELL_WARNING' => array( |
|
230 | + 'datetime_ticket' => esc_html__( |
|
231 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
232 | + 'event_espresso' |
|
233 | + ), |
|
234 | + 'ticket_datetime' => esc_html__( |
|
235 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
236 | + 'event_espresso' |
|
237 | + ), |
|
238 | + ), |
|
239 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
240 | + $this->_date_format_strings['date'], |
|
241 | + $this->_date_format_strings['time'] |
|
242 | + ), |
|
243 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
244 | + ), |
|
245 | + ), |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * @param array $update_callbacks |
|
252 | - * @return array |
|
253 | - */ |
|
254 | - public function caf_updates(array $update_callbacks) |
|
255 | - { |
|
256 | - foreach ($update_callbacks as $key => $callback) { |
|
257 | - if ($callback[1] === '_default_tickets_update') { |
|
258 | - unset($update_callbacks[ $key ]); |
|
259 | - } |
|
260 | - } |
|
261 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
262 | - return $update_callbacks; |
|
263 | - } |
|
250 | + /** |
|
251 | + * @param array $update_callbacks |
|
252 | + * @return array |
|
253 | + */ |
|
254 | + public function caf_updates(array $update_callbacks) |
|
255 | + { |
|
256 | + foreach ($update_callbacks as $key => $callback) { |
|
257 | + if ($callback[1] === '_default_tickets_update') { |
|
258 | + unset($update_callbacks[ $key ]); |
|
259 | + } |
|
260 | + } |
|
261 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
262 | + return $update_callbacks; |
|
263 | + } |
|
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
268 | - * |
|
269 | - * @param EE_Event $event The Event object we're attaching data to |
|
270 | - * @param array $data The request data from the form |
|
271 | - * @throws ReflectionException |
|
272 | - * @throws Exception |
|
273 | - * @throws InvalidInterfaceException |
|
274 | - * @throws InvalidDataTypeException |
|
275 | - * @throws EE_Error |
|
276 | - * @throws InvalidArgumentException |
|
277 | - */ |
|
278 | - public function datetime_and_tickets_caf_update($event, $data) |
|
279 | - { |
|
280 | - // first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | - // next tackle the tickets (and prices?) |
|
283 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | - } |
|
266 | + /** |
|
267 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
268 | + * |
|
269 | + * @param EE_Event $event The Event object we're attaching data to |
|
270 | + * @param array $data The request data from the form |
|
271 | + * @throws ReflectionException |
|
272 | + * @throws Exception |
|
273 | + * @throws InvalidInterfaceException |
|
274 | + * @throws InvalidDataTypeException |
|
275 | + * @throws EE_Error |
|
276 | + * @throws InvalidArgumentException |
|
277 | + */ |
|
278 | + public function datetime_and_tickets_caf_update($event, $data) |
|
279 | + { |
|
280 | + // first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | + // next tackle the tickets (and prices?) |
|
283 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | + } |
|
285 | 285 | |
286 | 286 | |
287 | - /** |
|
288 | - * update event_datetimes |
|
289 | - * |
|
290 | - * @param EE_Event $event Event being updated |
|
291 | - * @param array $data the request data from the form |
|
292 | - * @return EE_Datetime[] |
|
293 | - * @throws Exception |
|
294 | - * @throws ReflectionException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - * @throws InvalidArgumentException |
|
298 | - * @throws EE_Error |
|
299 | - */ |
|
300 | - protected function _update_datetimes($event, $data) |
|
301 | - { |
|
302 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
303 | - $saved_dtt_ids = array(); |
|
304 | - $saved_dtt_objs = array(); |
|
305 | - if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
306 | - throw new InvalidArgumentException( |
|
307 | - esc_html__( |
|
308 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
309 | - 'event_espresso' |
|
310 | - ) |
|
311 | - ); |
|
312 | - } |
|
313 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
314 | - // trim all values to ensure any excess whitespace is removed. |
|
315 | - $datetime_data = array_map( |
|
316 | - function ($datetime_data) { |
|
317 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
318 | - }, |
|
319 | - $datetime_data |
|
320 | - ); |
|
321 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
322 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
323 | - ? $datetime_data['DTT_EVT_end'] |
|
324 | - : $datetime_data['DTT_EVT_start']; |
|
325 | - $datetime_values = array( |
|
326 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
327 | - ? $datetime_data['DTT_ID'] |
|
328 | - : null, |
|
329 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
330 | - ? $datetime_data['DTT_name'] |
|
331 | - : '', |
|
332 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
333 | - ? $datetime_data['DTT_description'] |
|
334 | - : '', |
|
335 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
336 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
337 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
338 | - ? EE_INF |
|
339 | - : $datetime_data['DTT_reg_limit'], |
|
340 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
341 | - ? $row |
|
342 | - : $datetime_data['DTT_order'], |
|
343 | - ); |
|
344 | - // if we have an id then let's get existing object first and then set the new values. |
|
345 | - // Otherwise we instantiate a new object for save. |
|
346 | - if (! empty($datetime_data['DTT_ID'])) { |
|
347 | - $datetime = EE_Registry::instance() |
|
348 | - ->load_model('Datetime', array($timezone)) |
|
349 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
350 | - // set date and time format according to what is set in this class. |
|
351 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
352 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
353 | - foreach ($datetime_values as $field => $value) { |
|
354 | - $datetime->set($field, $value); |
|
355 | - } |
|
356 | - // make sure the $dtt_id here is saved just in case |
|
357 | - // after the add_relation_to() the autosave replaces it. |
|
358 | - // We need to do this so we dont' TRASH the parent DTT. |
|
359 | - // (save the ID for both key and value to avoid duplications) |
|
360 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
361 | - } else { |
|
362 | - $datetime = EE_Registry::instance()->load_class( |
|
363 | - 'Datetime', |
|
364 | - array( |
|
365 | - $datetime_values, |
|
366 | - $timezone, |
|
367 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
368 | - ), |
|
369 | - false, |
|
370 | - false |
|
371 | - ); |
|
372 | - foreach ($datetime_values as $field => $value) { |
|
373 | - $datetime->set($field, $value); |
|
374 | - } |
|
375 | - } |
|
376 | - $datetime->save(); |
|
377 | - do_action( |
|
378 | - 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
379 | - $datetime, |
|
380 | - $row, |
|
381 | - $datetime_data, |
|
382 | - $data |
|
383 | - ); |
|
384 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
385 | - // before going any further make sure our dates are setup correctly |
|
386 | - // so that the end date is always equal or greater than the start date. |
|
387 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
388 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
389 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
390 | - $datetime->save(); |
|
391 | - } |
|
392 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
393 | - // because it is possible there was a new one created for the autosave. |
|
394 | - // (save the ID for both key and value to avoid duplications) |
|
395 | - $DTT_ID = $datetime->ID(); |
|
396 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
397 | - $saved_dtt_objs[ $row ] = $datetime; |
|
398 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
399 | - } |
|
400 | - $event->save(); |
|
401 | - // now we need to REMOVE any datetimes that got deleted. |
|
402 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
403 | - // So its safe to permanently delete at this point. |
|
404 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
405 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
406 | - if (is_array($old_datetimes)) { |
|
407 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
408 | - foreach ($datetimes_to_delete as $id) { |
|
409 | - $id = absint($id); |
|
410 | - if (empty($id)) { |
|
411 | - continue; |
|
412 | - } |
|
413 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
414 | - // remove tkt relationships. |
|
415 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
416 | - foreach ($related_tickets as $tkt) { |
|
417 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
418 | - } |
|
419 | - $event->_remove_relation_to($id, 'Datetime'); |
|
420 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
421 | - } |
|
422 | - } |
|
423 | - return $saved_dtt_objs; |
|
424 | - } |
|
287 | + /** |
|
288 | + * update event_datetimes |
|
289 | + * |
|
290 | + * @param EE_Event $event Event being updated |
|
291 | + * @param array $data the request data from the form |
|
292 | + * @return EE_Datetime[] |
|
293 | + * @throws Exception |
|
294 | + * @throws ReflectionException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + * @throws InvalidArgumentException |
|
298 | + * @throws EE_Error |
|
299 | + */ |
|
300 | + protected function _update_datetimes($event, $data) |
|
301 | + { |
|
302 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
303 | + $saved_dtt_ids = array(); |
|
304 | + $saved_dtt_objs = array(); |
|
305 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
306 | + throw new InvalidArgumentException( |
|
307 | + esc_html__( |
|
308 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
309 | + 'event_espresso' |
|
310 | + ) |
|
311 | + ); |
|
312 | + } |
|
313 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
314 | + // trim all values to ensure any excess whitespace is removed. |
|
315 | + $datetime_data = array_map( |
|
316 | + function ($datetime_data) { |
|
317 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
318 | + }, |
|
319 | + $datetime_data |
|
320 | + ); |
|
321 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
322 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
323 | + ? $datetime_data['DTT_EVT_end'] |
|
324 | + : $datetime_data['DTT_EVT_start']; |
|
325 | + $datetime_values = array( |
|
326 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
327 | + ? $datetime_data['DTT_ID'] |
|
328 | + : null, |
|
329 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
330 | + ? $datetime_data['DTT_name'] |
|
331 | + : '', |
|
332 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
333 | + ? $datetime_data['DTT_description'] |
|
334 | + : '', |
|
335 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
336 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
337 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
338 | + ? EE_INF |
|
339 | + : $datetime_data['DTT_reg_limit'], |
|
340 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
341 | + ? $row |
|
342 | + : $datetime_data['DTT_order'], |
|
343 | + ); |
|
344 | + // if we have an id then let's get existing object first and then set the new values. |
|
345 | + // Otherwise we instantiate a new object for save. |
|
346 | + if (! empty($datetime_data['DTT_ID'])) { |
|
347 | + $datetime = EE_Registry::instance() |
|
348 | + ->load_model('Datetime', array($timezone)) |
|
349 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
350 | + // set date and time format according to what is set in this class. |
|
351 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
352 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
353 | + foreach ($datetime_values as $field => $value) { |
|
354 | + $datetime->set($field, $value); |
|
355 | + } |
|
356 | + // make sure the $dtt_id here is saved just in case |
|
357 | + // after the add_relation_to() the autosave replaces it. |
|
358 | + // We need to do this so we dont' TRASH the parent DTT. |
|
359 | + // (save the ID for both key and value to avoid duplications) |
|
360 | + $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
361 | + } else { |
|
362 | + $datetime = EE_Registry::instance()->load_class( |
|
363 | + 'Datetime', |
|
364 | + array( |
|
365 | + $datetime_values, |
|
366 | + $timezone, |
|
367 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
368 | + ), |
|
369 | + false, |
|
370 | + false |
|
371 | + ); |
|
372 | + foreach ($datetime_values as $field => $value) { |
|
373 | + $datetime->set($field, $value); |
|
374 | + } |
|
375 | + } |
|
376 | + $datetime->save(); |
|
377 | + do_action( |
|
378 | + 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
379 | + $datetime, |
|
380 | + $row, |
|
381 | + $datetime_data, |
|
382 | + $data |
|
383 | + ); |
|
384 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
385 | + // before going any further make sure our dates are setup correctly |
|
386 | + // so that the end date is always equal or greater than the start date. |
|
387 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
388 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
389 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
390 | + $datetime->save(); |
|
391 | + } |
|
392 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
393 | + // because it is possible there was a new one created for the autosave. |
|
394 | + // (save the ID for both key and value to avoid duplications) |
|
395 | + $DTT_ID = $datetime->ID(); |
|
396 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
397 | + $saved_dtt_objs[ $row ] = $datetime; |
|
398 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
399 | + } |
|
400 | + $event->save(); |
|
401 | + // now we need to REMOVE any datetimes that got deleted. |
|
402 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
403 | + // So its safe to permanently delete at this point. |
|
404 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
405 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
406 | + if (is_array($old_datetimes)) { |
|
407 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
408 | + foreach ($datetimes_to_delete as $id) { |
|
409 | + $id = absint($id); |
|
410 | + if (empty($id)) { |
|
411 | + continue; |
|
412 | + } |
|
413 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
414 | + // remove tkt relationships. |
|
415 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
416 | + foreach ($related_tickets as $tkt) { |
|
417 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
418 | + } |
|
419 | + $event->_remove_relation_to($id, 'Datetime'); |
|
420 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
421 | + } |
|
422 | + } |
|
423 | + return $saved_dtt_objs; |
|
424 | + } |
|
425 | 425 | |
426 | 426 | |
427 | - /** |
|
428 | - * update tickets |
|
429 | - * |
|
430 | - * @param EE_Event $event Event object being updated |
|
431 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
432 | - * @param array $data incoming request data |
|
433 | - * @return EE_Ticket[] |
|
434 | - * @throws Exception |
|
435 | - * @throws ReflectionException |
|
436 | - * @throws InvalidInterfaceException |
|
437 | - * @throws InvalidDataTypeException |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws EE_Error |
|
440 | - */ |
|
441 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
442 | - { |
|
443 | - $new_tkt = null; |
|
444 | - $new_default = null; |
|
445 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
446 | - $data = stripslashes_deep($data); |
|
447 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
448 | - $saved_tickets = $datetimes_on_existing = array(); |
|
449 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
450 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
451 | - throw new InvalidArgumentException( |
|
452 | - esc_html__( |
|
453 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
454 | - 'event_espresso' |
|
455 | - ) |
|
456 | - ); |
|
457 | - } |
|
458 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
459 | - $update_prices = $create_new_TKT = false; |
|
460 | - // figure out what datetimes were added to the ticket |
|
461 | - // and what datetimes were removed from the ticket in the session. |
|
462 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
463 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
464 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
465 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
466 | - // trim inputs to ensure any excess whitespace is removed. |
|
467 | - $tkt = array_map( |
|
468 | - function ($ticket_data) { |
|
469 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
470 | - }, |
|
471 | - $tkt |
|
472 | - ); |
|
473 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
474 | - // because we're doing calculations prior to using the models. |
|
475 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
476 | - $ticket_price = isset($tkt['TKT_price']) |
|
477 | - ? round((float) $tkt['TKT_price'], 3) |
|
478 | - : 0; |
|
479 | - // note incoming base price needs converted from localized value. |
|
480 | - $base_price = isset($tkt['TKT_base_price']) |
|
481 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
482 | - : 0; |
|
483 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
484 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
485 | - ? $base_price |
|
486 | - : $ticket_price; |
|
487 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
488 | - ? $tkt['TKT_base_price_ID'] |
|
489 | - : 0; |
|
490 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
491 | - ? $data['edit_prices'][ $row ] |
|
492 | - : array(); |
|
493 | - $now = null; |
|
494 | - if (empty($tkt['TKT_start_date'])) { |
|
495 | - // lets' use now in the set timezone. |
|
496 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
497 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
498 | - } |
|
499 | - if (empty($tkt['TKT_end_date'])) { |
|
500 | - /** |
|
501 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
502 | - */ |
|
503 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
504 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
505 | - } |
|
506 | - $TKT_values = array( |
|
507 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
508 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
509 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
510 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
511 | - && $tkt['TKT_description'] !== esc_html__( |
|
512 | - 'You can modify this description', |
|
513 | - 'event_espresso' |
|
514 | - ) |
|
515 | - ? $tkt['TKT_description'] |
|
516 | - : '', |
|
517 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
518 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
519 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
520 | - ? EE_INF |
|
521 | - : $tkt['TKT_qty'], |
|
522 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
523 | - ? EE_INF |
|
524 | - : $tkt['TKT_uses'], |
|
525 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
526 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
527 | - 'TKT_row' => $row, |
|
528 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
529 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
530 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
531 | - 'TKT_price' => $ticket_price, |
|
532 | - ); |
|
533 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
534 | - // which means in turn that the prices will become new prices as well. |
|
535 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
536 | - $TKT_values['TKT_ID'] = 0; |
|
537 | - $TKT_values['TKT_is_default'] = 0; |
|
538 | - $update_prices = true; |
|
539 | - } |
|
540 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
541 | - // we actually do our saves ahead of doing any add_relations to |
|
542 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
543 | - // but DID have it's items modified. |
|
544 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
545 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
546 | - if (absint($TKT_values['TKT_ID'])) { |
|
547 | - $ticket = EE_Registry::instance() |
|
548 | - ->load_model('Ticket', array($timezone)) |
|
549 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
550 | - if ($ticket instanceof EE_Ticket) { |
|
551 | - $ticket = $this->_update_ticket_datetimes( |
|
552 | - $ticket, |
|
553 | - $saved_datetimes, |
|
554 | - $datetimes_added, |
|
555 | - $datetimes_removed |
|
556 | - ); |
|
557 | - // are there any registrations using this ticket ? |
|
558 | - $tickets_sold = $ticket->count_related( |
|
559 | - 'Registration', |
|
560 | - array( |
|
561 | - array( |
|
562 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
563 | - ), |
|
564 | - ) |
|
565 | - ); |
|
566 | - // set ticket formats |
|
567 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
568 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
569 | - // let's just check the total price for the existing ticket |
|
570 | - // and determine if it matches the new total price. |
|
571 | - // if they are different then we create a new ticket (if tickets sold) |
|
572 | - // if they aren't different then we go ahead and modify existing ticket. |
|
573 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
574 | - // set new values |
|
575 | - foreach ($TKT_values as $field => $value) { |
|
576 | - if ($field === 'TKT_qty') { |
|
577 | - $ticket->set_qty($value); |
|
578 | - } else { |
|
579 | - $ticket->set($field, $value); |
|
580 | - } |
|
581 | - } |
|
582 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
583 | - // Otherwise we have to create a new ticket. |
|
584 | - if ($create_new_TKT) { |
|
585 | - $new_tkt = $this->_duplicate_ticket( |
|
586 | - $ticket, |
|
587 | - $price_rows, |
|
588 | - $ticket_price, |
|
589 | - $base_price, |
|
590 | - $base_price_id |
|
591 | - ); |
|
592 | - } |
|
593 | - } |
|
594 | - } else { |
|
595 | - // no TKT_id so a new TKT |
|
596 | - $ticket = EE_Ticket::new_instance( |
|
597 | - $TKT_values, |
|
598 | - $timezone, |
|
599 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
600 | - ); |
|
601 | - if ($ticket instanceof EE_Ticket) { |
|
602 | - // make sure ticket has an ID of setting relations won't work |
|
603 | - $ticket->save(); |
|
604 | - $ticket = $this->_update_ticket_datetimes( |
|
605 | - $ticket, |
|
606 | - $saved_datetimes, |
|
607 | - $datetimes_added, |
|
608 | - $datetimes_removed |
|
609 | - ); |
|
610 | - $update_prices = true; |
|
611 | - } |
|
612 | - } |
|
613 | - // make sure any current values have been saved. |
|
614 | - // $ticket->save(); |
|
615 | - // before going any further make sure our dates are setup correctly |
|
616 | - // so that the end date is always equal or greater than the start date. |
|
617 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
618 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
619 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
620 | - } |
|
621 | - // let's make sure the base price is handled |
|
622 | - $ticket = ! $create_new_TKT |
|
623 | - ? $this->_add_prices_to_ticket( |
|
624 | - array(), |
|
625 | - $ticket, |
|
626 | - $update_prices, |
|
627 | - $base_price, |
|
628 | - $base_price_id |
|
629 | - ) |
|
630 | - : $ticket; |
|
631 | - // add/update price_modifiers |
|
632 | - $ticket = ! $create_new_TKT |
|
633 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
634 | - : $ticket; |
|
635 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
636 | - $ticket->ensure_TKT_Price_correct(); |
|
637 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
638 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
639 | - $update_prices = true; |
|
640 | - $new_default = clone $ticket; |
|
641 | - $new_default->set('TKT_ID', 0); |
|
642 | - $new_default->set('TKT_is_default', 1); |
|
643 | - $new_default->set('TKT_row', 1); |
|
644 | - $new_default->set('TKT_price', $ticket_price); |
|
645 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
646 | - // (note this is just removing the cached relations in the object) |
|
647 | - $new_default->_remove_relations('Datetime'); |
|
648 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
649 | - $new_default = $this->_add_prices_to_ticket( |
|
650 | - $price_rows, |
|
651 | - $new_default, |
|
652 | - $update_prices |
|
653 | - ); |
|
654 | - // don't forget the base price! |
|
655 | - $new_default = $this->_add_prices_to_ticket( |
|
656 | - array(), |
|
657 | - $new_default, |
|
658 | - $update_prices, |
|
659 | - $base_price, |
|
660 | - $base_price_id |
|
661 | - ); |
|
662 | - $new_default->save(); |
|
663 | - do_action( |
|
664 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
665 | - $new_default, |
|
666 | - $row, |
|
667 | - $ticket, |
|
668 | - $data |
|
669 | - ); |
|
670 | - } |
|
671 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
672 | - // for the given dtt that are related to the current ticket. |
|
673 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
674 | - // what current ticket the archived tickets are related to |
|
675 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
676 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
677 | - // save existing TKT |
|
678 | - $ticket->save(); |
|
679 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
680 | - // save new TKT |
|
681 | - $new_tkt->save(); |
|
682 | - // add new ticket to array |
|
683 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
684 | - do_action( |
|
685 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
686 | - $new_tkt, |
|
687 | - $row, |
|
688 | - $tkt, |
|
689 | - $data |
|
690 | - ); |
|
691 | - } else { |
|
692 | - // add tkt to saved tkts |
|
693 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
694 | - do_action( |
|
695 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
696 | - $ticket, |
|
697 | - $row, |
|
698 | - $tkt, |
|
699 | - $data |
|
700 | - ); |
|
701 | - } |
|
702 | - } |
|
703 | - // now we need to handle tickets actually "deleted permanently". |
|
704 | - // There are cases where we'd want this to happen |
|
705 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
706 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
707 | - // No sense in keeping all the related data in the db! |
|
708 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
709 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
710 | - foreach ($tickets_removed as $id) { |
|
711 | - $id = absint($id); |
|
712 | - // get the ticket for this id |
|
713 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
714 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
715 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
716 | - continue; |
|
717 | - } |
|
718 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
719 | - // because we don't actually permanently delete these tickets. |
|
720 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
721 | - $tkt_to_remove->delete(); |
|
722 | - continue; |
|
723 | - } |
|
724 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
725 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
726 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
727 | - foreach ($datetimes as $datetime) { |
|
728 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
729 | - } |
|
730 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
731 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
732 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
733 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
734 | - // finally let's delete this ticket |
|
735 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
736 | - $tkt_to_remove->delete_permanently(); |
|
737 | - } |
|
738 | - return $saved_tickets; |
|
739 | - } |
|
427 | + /** |
|
428 | + * update tickets |
|
429 | + * |
|
430 | + * @param EE_Event $event Event object being updated |
|
431 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
432 | + * @param array $data incoming request data |
|
433 | + * @return EE_Ticket[] |
|
434 | + * @throws Exception |
|
435 | + * @throws ReflectionException |
|
436 | + * @throws InvalidInterfaceException |
|
437 | + * @throws InvalidDataTypeException |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws EE_Error |
|
440 | + */ |
|
441 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
442 | + { |
|
443 | + $new_tkt = null; |
|
444 | + $new_default = null; |
|
445 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
446 | + $data = stripslashes_deep($data); |
|
447 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
448 | + $saved_tickets = $datetimes_on_existing = array(); |
|
449 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
450 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
451 | + throw new InvalidArgumentException( |
|
452 | + esc_html__( |
|
453 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
454 | + 'event_espresso' |
|
455 | + ) |
|
456 | + ); |
|
457 | + } |
|
458 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
459 | + $update_prices = $create_new_TKT = false; |
|
460 | + // figure out what datetimes were added to the ticket |
|
461 | + // and what datetimes were removed from the ticket in the session. |
|
462 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
463 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
464 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
465 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
466 | + // trim inputs to ensure any excess whitespace is removed. |
|
467 | + $tkt = array_map( |
|
468 | + function ($ticket_data) { |
|
469 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
470 | + }, |
|
471 | + $tkt |
|
472 | + ); |
|
473 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
474 | + // because we're doing calculations prior to using the models. |
|
475 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
476 | + $ticket_price = isset($tkt['TKT_price']) |
|
477 | + ? round((float) $tkt['TKT_price'], 3) |
|
478 | + : 0; |
|
479 | + // note incoming base price needs converted from localized value. |
|
480 | + $base_price = isset($tkt['TKT_base_price']) |
|
481 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
482 | + : 0; |
|
483 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
484 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
485 | + ? $base_price |
|
486 | + : $ticket_price; |
|
487 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
488 | + ? $tkt['TKT_base_price_ID'] |
|
489 | + : 0; |
|
490 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
491 | + ? $data['edit_prices'][ $row ] |
|
492 | + : array(); |
|
493 | + $now = null; |
|
494 | + if (empty($tkt['TKT_start_date'])) { |
|
495 | + // lets' use now in the set timezone. |
|
496 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
497 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
498 | + } |
|
499 | + if (empty($tkt['TKT_end_date'])) { |
|
500 | + /** |
|
501 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
502 | + */ |
|
503 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
504 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
505 | + } |
|
506 | + $TKT_values = array( |
|
507 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
508 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
509 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
510 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
511 | + && $tkt['TKT_description'] !== esc_html__( |
|
512 | + 'You can modify this description', |
|
513 | + 'event_espresso' |
|
514 | + ) |
|
515 | + ? $tkt['TKT_description'] |
|
516 | + : '', |
|
517 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
518 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
519 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
520 | + ? EE_INF |
|
521 | + : $tkt['TKT_qty'], |
|
522 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
523 | + ? EE_INF |
|
524 | + : $tkt['TKT_uses'], |
|
525 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
526 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
527 | + 'TKT_row' => $row, |
|
528 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
529 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
530 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
531 | + 'TKT_price' => $ticket_price, |
|
532 | + ); |
|
533 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
534 | + // which means in turn that the prices will become new prices as well. |
|
535 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
536 | + $TKT_values['TKT_ID'] = 0; |
|
537 | + $TKT_values['TKT_is_default'] = 0; |
|
538 | + $update_prices = true; |
|
539 | + } |
|
540 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
541 | + // we actually do our saves ahead of doing any add_relations to |
|
542 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
543 | + // but DID have it's items modified. |
|
544 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
545 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
546 | + if (absint($TKT_values['TKT_ID'])) { |
|
547 | + $ticket = EE_Registry::instance() |
|
548 | + ->load_model('Ticket', array($timezone)) |
|
549 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
550 | + if ($ticket instanceof EE_Ticket) { |
|
551 | + $ticket = $this->_update_ticket_datetimes( |
|
552 | + $ticket, |
|
553 | + $saved_datetimes, |
|
554 | + $datetimes_added, |
|
555 | + $datetimes_removed |
|
556 | + ); |
|
557 | + // are there any registrations using this ticket ? |
|
558 | + $tickets_sold = $ticket->count_related( |
|
559 | + 'Registration', |
|
560 | + array( |
|
561 | + array( |
|
562 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
563 | + ), |
|
564 | + ) |
|
565 | + ); |
|
566 | + // set ticket formats |
|
567 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
568 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
569 | + // let's just check the total price for the existing ticket |
|
570 | + // and determine if it matches the new total price. |
|
571 | + // if they are different then we create a new ticket (if tickets sold) |
|
572 | + // if they aren't different then we go ahead and modify existing ticket. |
|
573 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
574 | + // set new values |
|
575 | + foreach ($TKT_values as $field => $value) { |
|
576 | + if ($field === 'TKT_qty') { |
|
577 | + $ticket->set_qty($value); |
|
578 | + } else { |
|
579 | + $ticket->set($field, $value); |
|
580 | + } |
|
581 | + } |
|
582 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
583 | + // Otherwise we have to create a new ticket. |
|
584 | + if ($create_new_TKT) { |
|
585 | + $new_tkt = $this->_duplicate_ticket( |
|
586 | + $ticket, |
|
587 | + $price_rows, |
|
588 | + $ticket_price, |
|
589 | + $base_price, |
|
590 | + $base_price_id |
|
591 | + ); |
|
592 | + } |
|
593 | + } |
|
594 | + } else { |
|
595 | + // no TKT_id so a new TKT |
|
596 | + $ticket = EE_Ticket::new_instance( |
|
597 | + $TKT_values, |
|
598 | + $timezone, |
|
599 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
600 | + ); |
|
601 | + if ($ticket instanceof EE_Ticket) { |
|
602 | + // make sure ticket has an ID of setting relations won't work |
|
603 | + $ticket->save(); |
|
604 | + $ticket = $this->_update_ticket_datetimes( |
|
605 | + $ticket, |
|
606 | + $saved_datetimes, |
|
607 | + $datetimes_added, |
|
608 | + $datetimes_removed |
|
609 | + ); |
|
610 | + $update_prices = true; |
|
611 | + } |
|
612 | + } |
|
613 | + // make sure any current values have been saved. |
|
614 | + // $ticket->save(); |
|
615 | + // before going any further make sure our dates are setup correctly |
|
616 | + // so that the end date is always equal or greater than the start date. |
|
617 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
618 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
619 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
620 | + } |
|
621 | + // let's make sure the base price is handled |
|
622 | + $ticket = ! $create_new_TKT |
|
623 | + ? $this->_add_prices_to_ticket( |
|
624 | + array(), |
|
625 | + $ticket, |
|
626 | + $update_prices, |
|
627 | + $base_price, |
|
628 | + $base_price_id |
|
629 | + ) |
|
630 | + : $ticket; |
|
631 | + // add/update price_modifiers |
|
632 | + $ticket = ! $create_new_TKT |
|
633 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
634 | + : $ticket; |
|
635 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
636 | + $ticket->ensure_TKT_Price_correct(); |
|
637 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
638 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
639 | + $update_prices = true; |
|
640 | + $new_default = clone $ticket; |
|
641 | + $new_default->set('TKT_ID', 0); |
|
642 | + $new_default->set('TKT_is_default', 1); |
|
643 | + $new_default->set('TKT_row', 1); |
|
644 | + $new_default->set('TKT_price', $ticket_price); |
|
645 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
646 | + // (note this is just removing the cached relations in the object) |
|
647 | + $new_default->_remove_relations('Datetime'); |
|
648 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
649 | + $new_default = $this->_add_prices_to_ticket( |
|
650 | + $price_rows, |
|
651 | + $new_default, |
|
652 | + $update_prices |
|
653 | + ); |
|
654 | + // don't forget the base price! |
|
655 | + $new_default = $this->_add_prices_to_ticket( |
|
656 | + array(), |
|
657 | + $new_default, |
|
658 | + $update_prices, |
|
659 | + $base_price, |
|
660 | + $base_price_id |
|
661 | + ); |
|
662 | + $new_default->save(); |
|
663 | + do_action( |
|
664 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
665 | + $new_default, |
|
666 | + $row, |
|
667 | + $ticket, |
|
668 | + $data |
|
669 | + ); |
|
670 | + } |
|
671 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
672 | + // for the given dtt that are related to the current ticket. |
|
673 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
674 | + // what current ticket the archived tickets are related to |
|
675 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
676 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
677 | + // save existing TKT |
|
678 | + $ticket->save(); |
|
679 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
680 | + // save new TKT |
|
681 | + $new_tkt->save(); |
|
682 | + // add new ticket to array |
|
683 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
684 | + do_action( |
|
685 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
686 | + $new_tkt, |
|
687 | + $row, |
|
688 | + $tkt, |
|
689 | + $data |
|
690 | + ); |
|
691 | + } else { |
|
692 | + // add tkt to saved tkts |
|
693 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
694 | + do_action( |
|
695 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
696 | + $ticket, |
|
697 | + $row, |
|
698 | + $tkt, |
|
699 | + $data |
|
700 | + ); |
|
701 | + } |
|
702 | + } |
|
703 | + // now we need to handle tickets actually "deleted permanently". |
|
704 | + // There are cases where we'd want this to happen |
|
705 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
706 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
707 | + // No sense in keeping all the related data in the db! |
|
708 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
709 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
710 | + foreach ($tickets_removed as $id) { |
|
711 | + $id = absint($id); |
|
712 | + // get the ticket for this id |
|
713 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
714 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
715 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
716 | + continue; |
|
717 | + } |
|
718 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
719 | + // because we don't actually permanently delete these tickets. |
|
720 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
721 | + $tkt_to_remove->delete(); |
|
722 | + continue; |
|
723 | + } |
|
724 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
725 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
726 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
727 | + foreach ($datetimes as $datetime) { |
|
728 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
729 | + } |
|
730 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
731 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
732 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
733 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
734 | + // finally let's delete this ticket |
|
735 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
736 | + $tkt_to_remove->delete_permanently(); |
|
737 | + } |
|
738 | + return $saved_tickets; |
|
739 | + } |
|
740 | 740 | |
741 | 741 | |
742 | - /** |
|
743 | - * @access protected |
|
744 | - * @param EE_Ticket $ticket |
|
745 | - * @param \EE_Datetime[] $saved_datetimes |
|
746 | - * @param \EE_Datetime[] $added_datetimes |
|
747 | - * @param \EE_Datetime[] $removed_datetimes |
|
748 | - * @return EE_Ticket |
|
749 | - * @throws EE_Error |
|
750 | - */ |
|
751 | - protected function _update_ticket_datetimes( |
|
752 | - EE_Ticket $ticket, |
|
753 | - $saved_datetimes = array(), |
|
754 | - $added_datetimes = array(), |
|
755 | - $removed_datetimes = array() |
|
756 | - ) { |
|
757 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
758 | - // and removing the ticket from datetimes it got removed from. |
|
759 | - // first let's add datetimes |
|
760 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
761 | - foreach ($added_datetimes as $row_id) { |
|
762 | - $row_id = (int) $row_id; |
|
763 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
764 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
765 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
766 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
767 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
768 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
769 | - } |
|
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - // then remove datetimes |
|
774 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
775 | - foreach ($removed_datetimes as $row_id) { |
|
776 | - $row_id = (int) $row_id; |
|
777 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
778 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
779 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
780 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
781 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
782 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
783 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
784 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
785 | - } |
|
786 | - } |
|
787 | - } |
|
788 | - } |
|
789 | - // cap ticket qty by datetime reg limits |
|
790 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
791 | - return $ticket; |
|
792 | - } |
|
742 | + /** |
|
743 | + * @access protected |
|
744 | + * @param EE_Ticket $ticket |
|
745 | + * @param \EE_Datetime[] $saved_datetimes |
|
746 | + * @param \EE_Datetime[] $added_datetimes |
|
747 | + * @param \EE_Datetime[] $removed_datetimes |
|
748 | + * @return EE_Ticket |
|
749 | + * @throws EE_Error |
|
750 | + */ |
|
751 | + protected function _update_ticket_datetimes( |
|
752 | + EE_Ticket $ticket, |
|
753 | + $saved_datetimes = array(), |
|
754 | + $added_datetimes = array(), |
|
755 | + $removed_datetimes = array() |
|
756 | + ) { |
|
757 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
758 | + // and removing the ticket from datetimes it got removed from. |
|
759 | + // first let's add datetimes |
|
760 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
761 | + foreach ($added_datetimes as $row_id) { |
|
762 | + $row_id = (int) $row_id; |
|
763 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
764 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
765 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
766 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
767 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
768 | + $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
769 | + } |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + // then remove datetimes |
|
774 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
775 | + foreach ($removed_datetimes as $row_id) { |
|
776 | + $row_id = (int) $row_id; |
|
777 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
778 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
779 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
780 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
781 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
782 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
783 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
784 | + $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
785 | + } |
|
786 | + } |
|
787 | + } |
|
788 | + } |
|
789 | + // cap ticket qty by datetime reg limits |
|
790 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
791 | + return $ticket; |
|
792 | + } |
|
793 | 793 | |
794 | 794 | |
795 | - /** |
|
796 | - * @access protected |
|
797 | - * @param EE_Ticket $ticket |
|
798 | - * @param array $price_rows |
|
799 | - * @param int $ticket_price |
|
800 | - * @param int $base_price |
|
801 | - * @param int $base_price_id |
|
802 | - * @return EE_Ticket |
|
803 | - * @throws ReflectionException |
|
804 | - * @throws InvalidArgumentException |
|
805 | - * @throws InvalidInterfaceException |
|
806 | - * @throws InvalidDataTypeException |
|
807 | - * @throws EE_Error |
|
808 | - */ |
|
809 | - protected function _duplicate_ticket( |
|
810 | - EE_Ticket $ticket, |
|
811 | - $price_rows = array(), |
|
812 | - $ticket_price = 0, |
|
813 | - $base_price = 0, |
|
814 | - $base_price_id = 0 |
|
815 | - ) { |
|
816 | - // create new ticket that's a copy of the existing |
|
817 | - // except a new id of course (and not archived) |
|
818 | - // AND has the new TKT_price associated with it. |
|
819 | - $new_ticket = clone $ticket; |
|
820 | - $new_ticket->set('TKT_ID', 0); |
|
821 | - $new_ticket->set_deleted(0); |
|
822 | - $new_ticket->set_price($ticket_price); |
|
823 | - $new_ticket->set_sold(0); |
|
824 | - // let's get a new ID for this ticket |
|
825 | - $new_ticket->save(); |
|
826 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
827 | - $datetimes_on_existing = $ticket->datetimes(); |
|
828 | - $new_ticket = $this->_update_ticket_datetimes( |
|
829 | - $new_ticket, |
|
830 | - $datetimes_on_existing, |
|
831 | - array_keys($datetimes_on_existing) |
|
832 | - ); |
|
833 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
834 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
835 | - // available. |
|
836 | - if ($ticket->sold() > 0) { |
|
837 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
838 | - $new_ticket->set_qty($new_qty); |
|
839 | - } |
|
840 | - // now we update the prices just for this ticket |
|
841 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
842 | - // and we update the base price |
|
843 | - $new_ticket = $this->_add_prices_to_ticket( |
|
844 | - array(), |
|
845 | - $new_ticket, |
|
846 | - true, |
|
847 | - $base_price, |
|
848 | - $base_price_id |
|
849 | - ); |
|
850 | - return $new_ticket; |
|
851 | - } |
|
795 | + /** |
|
796 | + * @access protected |
|
797 | + * @param EE_Ticket $ticket |
|
798 | + * @param array $price_rows |
|
799 | + * @param int $ticket_price |
|
800 | + * @param int $base_price |
|
801 | + * @param int $base_price_id |
|
802 | + * @return EE_Ticket |
|
803 | + * @throws ReflectionException |
|
804 | + * @throws InvalidArgumentException |
|
805 | + * @throws InvalidInterfaceException |
|
806 | + * @throws InvalidDataTypeException |
|
807 | + * @throws EE_Error |
|
808 | + */ |
|
809 | + protected function _duplicate_ticket( |
|
810 | + EE_Ticket $ticket, |
|
811 | + $price_rows = array(), |
|
812 | + $ticket_price = 0, |
|
813 | + $base_price = 0, |
|
814 | + $base_price_id = 0 |
|
815 | + ) { |
|
816 | + // create new ticket that's a copy of the existing |
|
817 | + // except a new id of course (and not archived) |
|
818 | + // AND has the new TKT_price associated with it. |
|
819 | + $new_ticket = clone $ticket; |
|
820 | + $new_ticket->set('TKT_ID', 0); |
|
821 | + $new_ticket->set_deleted(0); |
|
822 | + $new_ticket->set_price($ticket_price); |
|
823 | + $new_ticket->set_sold(0); |
|
824 | + // let's get a new ID for this ticket |
|
825 | + $new_ticket->save(); |
|
826 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
827 | + $datetimes_on_existing = $ticket->datetimes(); |
|
828 | + $new_ticket = $this->_update_ticket_datetimes( |
|
829 | + $new_ticket, |
|
830 | + $datetimes_on_existing, |
|
831 | + array_keys($datetimes_on_existing) |
|
832 | + ); |
|
833 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
834 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
835 | + // available. |
|
836 | + if ($ticket->sold() > 0) { |
|
837 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
838 | + $new_ticket->set_qty($new_qty); |
|
839 | + } |
|
840 | + // now we update the prices just for this ticket |
|
841 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
842 | + // and we update the base price |
|
843 | + $new_ticket = $this->_add_prices_to_ticket( |
|
844 | + array(), |
|
845 | + $new_ticket, |
|
846 | + true, |
|
847 | + $base_price, |
|
848 | + $base_price_id |
|
849 | + ); |
|
850 | + return $new_ticket; |
|
851 | + } |
|
852 | 852 | |
853 | 853 | |
854 | - /** |
|
855 | - * This attaches a list of given prices to a ticket. |
|
856 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
857 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
858 | - * price info and prices are automatically "archived" via the ticket. |
|
859 | - * |
|
860 | - * @access private |
|
861 | - * @param array $prices Array of prices from the form. |
|
862 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
863 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
864 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
865 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
866 | - * @return EE_Ticket |
|
867 | - * @throws ReflectionException |
|
868 | - * @throws InvalidArgumentException |
|
869 | - * @throws InvalidInterfaceException |
|
870 | - * @throws InvalidDataTypeException |
|
871 | - * @throws EE_Error |
|
872 | - */ |
|
873 | - protected function _add_prices_to_ticket( |
|
874 | - $prices = array(), |
|
875 | - EE_Ticket $ticket, |
|
876 | - $new_prices = false, |
|
877 | - $base_price = false, |
|
878 | - $base_price_id = false |
|
879 | - ) { |
|
880 | - // let's just get any current prices that may exist on the given ticket |
|
881 | - // so we can remove any prices that got trashed in this session. |
|
882 | - $current_prices_on_ticket = $base_price !== false |
|
883 | - ? $ticket->base_price(true) |
|
884 | - : $ticket->price_modifiers(); |
|
885 | - $updated_prices = array(); |
|
886 | - // if $base_price ! FALSE then updating a base price. |
|
887 | - if ($base_price !== false) { |
|
888 | - $prices[1] = array( |
|
889 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
890 | - 'PRT_ID' => 1, |
|
891 | - 'PRC_amount' => $base_price, |
|
892 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
893 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
894 | - ); |
|
895 | - } |
|
896 | - // possibly need to save tkt |
|
897 | - if (! $ticket->ID()) { |
|
898 | - $ticket->save(); |
|
899 | - } |
|
900 | - foreach ($prices as $row => $prc) { |
|
901 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
902 | - if (empty($prt_id)) { |
|
903 | - continue; |
|
904 | - } //prices MUST have a price type id. |
|
905 | - $PRC_values = array( |
|
906 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
907 | - 'PRT_ID' => $prt_id, |
|
908 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
909 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
910 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
911 | - 'PRC_is_default' => false, |
|
912 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
913 | - 'PRC_order' => $row, |
|
914 | - ); |
|
915 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
916 | - $PRC_values['PRC_ID'] = 0; |
|
917 | - $price = EE_Registry::instance()->load_class( |
|
918 | - 'Price', |
|
919 | - array($PRC_values), |
|
920 | - false, |
|
921 | - false |
|
922 | - ); |
|
923 | - } else { |
|
924 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
925 | - // update this price with new values |
|
926 | - foreach ($PRC_values as $field => $value) { |
|
927 | - $price->set($field, $value); |
|
928 | - } |
|
929 | - } |
|
930 | - $price->save(); |
|
931 | - $updated_prices[ $price->ID() ] = $price; |
|
932 | - $ticket->_add_relation_to($price, 'Price'); |
|
933 | - } |
|
934 | - // now let's remove any prices that got removed from the ticket |
|
935 | - if (! empty($current_prices_on_ticket)) { |
|
936 | - $current = array_keys($current_prices_on_ticket); |
|
937 | - $updated = array_keys($updated_prices); |
|
938 | - $prices_to_remove = array_diff($current, $updated); |
|
939 | - if (! empty($prices_to_remove)) { |
|
940 | - foreach ($prices_to_remove as $prc_id) { |
|
941 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
942 | - $ticket->_remove_relation_to($p, 'Price'); |
|
943 | - // delete permanently the price |
|
944 | - $p->delete_permanently(); |
|
945 | - } |
|
946 | - } |
|
947 | - } |
|
948 | - return $ticket; |
|
949 | - } |
|
854 | + /** |
|
855 | + * This attaches a list of given prices to a ticket. |
|
856 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
857 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
858 | + * price info and prices are automatically "archived" via the ticket. |
|
859 | + * |
|
860 | + * @access private |
|
861 | + * @param array $prices Array of prices from the form. |
|
862 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
863 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
864 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
865 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
866 | + * @return EE_Ticket |
|
867 | + * @throws ReflectionException |
|
868 | + * @throws InvalidArgumentException |
|
869 | + * @throws InvalidInterfaceException |
|
870 | + * @throws InvalidDataTypeException |
|
871 | + * @throws EE_Error |
|
872 | + */ |
|
873 | + protected function _add_prices_to_ticket( |
|
874 | + $prices = array(), |
|
875 | + EE_Ticket $ticket, |
|
876 | + $new_prices = false, |
|
877 | + $base_price = false, |
|
878 | + $base_price_id = false |
|
879 | + ) { |
|
880 | + // let's just get any current prices that may exist on the given ticket |
|
881 | + // so we can remove any prices that got trashed in this session. |
|
882 | + $current_prices_on_ticket = $base_price !== false |
|
883 | + ? $ticket->base_price(true) |
|
884 | + : $ticket->price_modifiers(); |
|
885 | + $updated_prices = array(); |
|
886 | + // if $base_price ! FALSE then updating a base price. |
|
887 | + if ($base_price !== false) { |
|
888 | + $prices[1] = array( |
|
889 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
890 | + 'PRT_ID' => 1, |
|
891 | + 'PRC_amount' => $base_price, |
|
892 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
893 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
894 | + ); |
|
895 | + } |
|
896 | + // possibly need to save tkt |
|
897 | + if (! $ticket->ID()) { |
|
898 | + $ticket->save(); |
|
899 | + } |
|
900 | + foreach ($prices as $row => $prc) { |
|
901 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
902 | + if (empty($prt_id)) { |
|
903 | + continue; |
|
904 | + } //prices MUST have a price type id. |
|
905 | + $PRC_values = array( |
|
906 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
907 | + 'PRT_ID' => $prt_id, |
|
908 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
909 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
910 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
911 | + 'PRC_is_default' => false, |
|
912 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
913 | + 'PRC_order' => $row, |
|
914 | + ); |
|
915 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
916 | + $PRC_values['PRC_ID'] = 0; |
|
917 | + $price = EE_Registry::instance()->load_class( |
|
918 | + 'Price', |
|
919 | + array($PRC_values), |
|
920 | + false, |
|
921 | + false |
|
922 | + ); |
|
923 | + } else { |
|
924 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
925 | + // update this price with new values |
|
926 | + foreach ($PRC_values as $field => $value) { |
|
927 | + $price->set($field, $value); |
|
928 | + } |
|
929 | + } |
|
930 | + $price->save(); |
|
931 | + $updated_prices[ $price->ID() ] = $price; |
|
932 | + $ticket->_add_relation_to($price, 'Price'); |
|
933 | + } |
|
934 | + // now let's remove any prices that got removed from the ticket |
|
935 | + if (! empty($current_prices_on_ticket)) { |
|
936 | + $current = array_keys($current_prices_on_ticket); |
|
937 | + $updated = array_keys($updated_prices); |
|
938 | + $prices_to_remove = array_diff($current, $updated); |
|
939 | + if (! empty($prices_to_remove)) { |
|
940 | + foreach ($prices_to_remove as $prc_id) { |
|
941 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
942 | + $ticket->_remove_relation_to($p, 'Price'); |
|
943 | + // delete permanently the price |
|
944 | + $p->delete_permanently(); |
|
945 | + } |
|
946 | + } |
|
947 | + } |
|
948 | + return $ticket; |
|
949 | + } |
|
950 | 950 | |
951 | 951 | |
952 | - /** |
|
953 | - * @param Events_Admin_Page $event_admin_obj |
|
954 | - * @return Events_Admin_Page |
|
955 | - */ |
|
956 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
957 | - { |
|
958 | - return $event_admin_obj; |
|
959 | - // doing nothing for the moment. |
|
960 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
961 | - // (use the set_template_args() method) |
|
962 | - /** |
|
963 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
964 | - * 1. TKT_is_default_selector (visible) |
|
965 | - * 2. TKT_is_default (hidden) |
|
966 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
967 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
968 | - * this ticket to be saved as a default. |
|
969 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
970 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
971 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
972 | - * the TKT HAS been saved as a default.. |
|
973 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
974 | - * On Autosave: |
|
975 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
976 | - * then set the TKT_is_default to false. |
|
977 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
978 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
979 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
980 | - */ |
|
981 | - } |
|
952 | + /** |
|
953 | + * @param Events_Admin_Page $event_admin_obj |
|
954 | + * @return Events_Admin_Page |
|
955 | + */ |
|
956 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
957 | + { |
|
958 | + return $event_admin_obj; |
|
959 | + // doing nothing for the moment. |
|
960 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
961 | + // (use the set_template_args() method) |
|
962 | + /** |
|
963 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
964 | + * 1. TKT_is_default_selector (visible) |
|
965 | + * 2. TKT_is_default (hidden) |
|
966 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
967 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
968 | + * this ticket to be saved as a default. |
|
969 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
970 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
971 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
972 | + * the TKT HAS been saved as a default.. |
|
973 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
974 | + * On Autosave: |
|
975 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
976 | + * then set the TKT_is_default to false. |
|
977 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
978 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
979 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
980 | + */ |
|
981 | + } |
|
982 | 982 | |
983 | 983 | |
984 | - /** |
|
985 | - * @throws ReflectionException |
|
986 | - * @throws InvalidArgumentException |
|
987 | - * @throws InvalidInterfaceException |
|
988 | - * @throws InvalidDataTypeException |
|
989 | - * @throws DomainException |
|
990 | - * @throws EE_Error |
|
991 | - */ |
|
992 | - public function pricing_metabox() |
|
993 | - { |
|
994 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
995 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
996 | - // set is_creating_event property. |
|
997 | - $EVT_ID = $event->ID(); |
|
998 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
999 | - // default main template args |
|
1000 | - $main_template_args = array( |
|
1001 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
1002 | - 'event_editor_event_datetimes_help_tab', |
|
1003 | - $this->_adminpage_obj->page_slug, |
|
1004 | - $this->_adminpage_obj->get_req_action(), |
|
1005 | - false, |
|
1006 | - false |
|
1007 | - ), |
|
1008 | - // todo need to add a filter to the template for the help text |
|
1009 | - // in the Events_Admin_Page core file so we can add further help |
|
1010 | - 'existing_datetime_ids' => '', |
|
1011 | - 'total_dtt_rows' => 1, |
|
1012 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1013 | - 'add_new_dtt_info', |
|
1014 | - $this->_adminpage_obj->page_slug, |
|
1015 | - $this->_adminpage_obj->get_req_action(), |
|
1016 | - false, |
|
1017 | - false |
|
1018 | - ), |
|
1019 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1020 | - 'datetime_rows' => '', |
|
1021 | - 'show_tickets_container' => '', |
|
1022 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1023 | - 'ticket_rows' => '', |
|
1024 | - 'existing_ticket_ids' => '', |
|
1025 | - 'total_ticket_rows' => 1, |
|
1026 | - 'ticket_js_structure' => '', |
|
1027 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1028 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1029 | - ); |
|
1030 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1031 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1032 | - /** |
|
1033 | - * 1. Start with retrieving Datetimes |
|
1034 | - * 2. For each datetime get related tickets |
|
1035 | - * 3. For each ticket get related prices |
|
1036 | - */ |
|
1037 | - /** @var EEM_Datetime $datetime_model */ |
|
1038 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1039 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1040 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1041 | - /** |
|
1042 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1043 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1044 | - */ |
|
1045 | - $datetime_row = 1; |
|
1046 | - foreach ($datetimes as $datetime) { |
|
1047 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1048 | - $datetime->set('DTT_order', $datetime_row); |
|
1049 | - $existing_datetime_ids[] = $DTT_ID; |
|
1050 | - // tickets attached |
|
1051 | - $related_tickets = $datetime->ID() > 0 |
|
1052 | - ? $datetime->get_many_related( |
|
1053 | - 'Ticket', |
|
1054 | - array( |
|
1055 | - array( |
|
1056 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1057 | - ), |
|
1058 | - 'default_where_conditions' => 'none', |
|
1059 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1060 | - ) |
|
1061 | - ) |
|
1062 | - : array(); |
|
1063 | - // if there are no related tickets this is likely a new event OR autodraft |
|
1064 | - // event so we need to generate the default tickets because datetimes |
|
1065 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1066 | - // datetime on the event. |
|
1067 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
1068 | - /** @var EEM_Ticket $ticket_model */ |
|
1069 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1070 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1071 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1072 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1073 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1074 | - $main_default_ticket = reset($related_tickets); |
|
1075 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1076 | - foreach ($default_prices as $default_price) { |
|
1077 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1078 | - continue; |
|
1079 | - } |
|
1080 | - $main_default_ticket->cache('Price', $default_price); |
|
1081 | - } |
|
1082 | - } |
|
1083 | - } |
|
1084 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1085 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1086 | - // So we're going to temporarily cache some of that information. |
|
1087 | - // loop through and setup the ticket rows and make sure the order is set. |
|
1088 | - foreach ($related_tickets as $ticket) { |
|
1089 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1090 | - $ticket_row = $ticket->get('TKT_row'); |
|
1091 | - // we only want unique tickets in our final display!! |
|
1092 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1093 | - $existing_ticket_ids[] = $TKT_ID; |
|
1094 | - $all_tickets[] = $ticket; |
|
1095 | - } |
|
1096 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1097 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1098 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1099 | - if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
1100 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1101 | - ) { |
|
1102 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1103 | - } |
|
1104 | - } |
|
1105 | - $datetime_row++; |
|
1106 | - } |
|
1107 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1108 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1109 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1110 | - // sort $all_tickets by order |
|
1111 | - usort( |
|
1112 | - $all_tickets, |
|
1113 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1114 | - $a_order = (int) $a->get('TKT_order'); |
|
1115 | - $b_order = (int) $b->get('TKT_order'); |
|
1116 | - if ($a_order === $b_order) { |
|
1117 | - return 0; |
|
1118 | - } |
|
1119 | - return ($a_order < $b_order) ? -1 : 1; |
|
1120 | - } |
|
1121 | - ); |
|
1122 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1123 | - // and ticket rows so we start our dtt loop again. |
|
1124 | - $datetime_row = 1; |
|
1125 | - foreach ($datetimes as $datetime) { |
|
1126 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1127 | - $datetime_row, |
|
1128 | - $datetime, |
|
1129 | - $datetime_tickets, |
|
1130 | - $all_tickets, |
|
1131 | - false, |
|
1132 | - $datetimes |
|
1133 | - ); |
|
1134 | - $datetime_row++; |
|
1135 | - } |
|
1136 | - // then loop through all tickets for the ticket rows. |
|
1137 | - $ticket_row = 1; |
|
1138 | - foreach ($all_tickets as $ticket) { |
|
1139 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1140 | - $ticket_row, |
|
1141 | - $ticket, |
|
1142 | - $ticket_datetimes, |
|
1143 | - $datetimes, |
|
1144 | - false, |
|
1145 | - $all_tickets |
|
1146 | - ); |
|
1147 | - $ticket_row++; |
|
1148 | - } |
|
1149 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1150 | - EEH_Template::display_template( |
|
1151 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1152 | - $main_template_args |
|
1153 | - ); |
|
1154 | - } |
|
984 | + /** |
|
985 | + * @throws ReflectionException |
|
986 | + * @throws InvalidArgumentException |
|
987 | + * @throws InvalidInterfaceException |
|
988 | + * @throws InvalidDataTypeException |
|
989 | + * @throws DomainException |
|
990 | + * @throws EE_Error |
|
991 | + */ |
|
992 | + public function pricing_metabox() |
|
993 | + { |
|
994 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
995 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
996 | + // set is_creating_event property. |
|
997 | + $EVT_ID = $event->ID(); |
|
998 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
999 | + // default main template args |
|
1000 | + $main_template_args = array( |
|
1001 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
1002 | + 'event_editor_event_datetimes_help_tab', |
|
1003 | + $this->_adminpage_obj->page_slug, |
|
1004 | + $this->_adminpage_obj->get_req_action(), |
|
1005 | + false, |
|
1006 | + false |
|
1007 | + ), |
|
1008 | + // todo need to add a filter to the template for the help text |
|
1009 | + // in the Events_Admin_Page core file so we can add further help |
|
1010 | + 'existing_datetime_ids' => '', |
|
1011 | + 'total_dtt_rows' => 1, |
|
1012 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1013 | + 'add_new_dtt_info', |
|
1014 | + $this->_adminpage_obj->page_slug, |
|
1015 | + $this->_adminpage_obj->get_req_action(), |
|
1016 | + false, |
|
1017 | + false |
|
1018 | + ), |
|
1019 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1020 | + 'datetime_rows' => '', |
|
1021 | + 'show_tickets_container' => '', |
|
1022 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1023 | + 'ticket_rows' => '', |
|
1024 | + 'existing_ticket_ids' => '', |
|
1025 | + 'total_ticket_rows' => 1, |
|
1026 | + 'ticket_js_structure' => '', |
|
1027 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1028 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1029 | + ); |
|
1030 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1031 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1032 | + /** |
|
1033 | + * 1. Start with retrieving Datetimes |
|
1034 | + * 2. For each datetime get related tickets |
|
1035 | + * 3. For each ticket get related prices |
|
1036 | + */ |
|
1037 | + /** @var EEM_Datetime $datetime_model */ |
|
1038 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1039 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1040 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1041 | + /** |
|
1042 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1043 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1044 | + */ |
|
1045 | + $datetime_row = 1; |
|
1046 | + foreach ($datetimes as $datetime) { |
|
1047 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1048 | + $datetime->set('DTT_order', $datetime_row); |
|
1049 | + $existing_datetime_ids[] = $DTT_ID; |
|
1050 | + // tickets attached |
|
1051 | + $related_tickets = $datetime->ID() > 0 |
|
1052 | + ? $datetime->get_many_related( |
|
1053 | + 'Ticket', |
|
1054 | + array( |
|
1055 | + array( |
|
1056 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1057 | + ), |
|
1058 | + 'default_where_conditions' => 'none', |
|
1059 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1060 | + ) |
|
1061 | + ) |
|
1062 | + : array(); |
|
1063 | + // if there are no related tickets this is likely a new event OR autodraft |
|
1064 | + // event so we need to generate the default tickets because datetimes |
|
1065 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1066 | + // datetime on the event. |
|
1067 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
1068 | + /** @var EEM_Ticket $ticket_model */ |
|
1069 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1070 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1071 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1072 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1073 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1074 | + $main_default_ticket = reset($related_tickets); |
|
1075 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1076 | + foreach ($default_prices as $default_price) { |
|
1077 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1078 | + continue; |
|
1079 | + } |
|
1080 | + $main_default_ticket->cache('Price', $default_price); |
|
1081 | + } |
|
1082 | + } |
|
1083 | + } |
|
1084 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1085 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1086 | + // So we're going to temporarily cache some of that information. |
|
1087 | + // loop through and setup the ticket rows and make sure the order is set. |
|
1088 | + foreach ($related_tickets as $ticket) { |
|
1089 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1090 | + $ticket_row = $ticket->get('TKT_row'); |
|
1091 | + // we only want unique tickets in our final display!! |
|
1092 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1093 | + $existing_ticket_ids[] = $TKT_ID; |
|
1094 | + $all_tickets[] = $ticket; |
|
1095 | + } |
|
1096 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1097 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1098 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1099 | + if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
1100 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1101 | + ) { |
|
1102 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1103 | + } |
|
1104 | + } |
|
1105 | + $datetime_row++; |
|
1106 | + } |
|
1107 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1108 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1109 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1110 | + // sort $all_tickets by order |
|
1111 | + usort( |
|
1112 | + $all_tickets, |
|
1113 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1114 | + $a_order = (int) $a->get('TKT_order'); |
|
1115 | + $b_order = (int) $b->get('TKT_order'); |
|
1116 | + if ($a_order === $b_order) { |
|
1117 | + return 0; |
|
1118 | + } |
|
1119 | + return ($a_order < $b_order) ? -1 : 1; |
|
1120 | + } |
|
1121 | + ); |
|
1122 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1123 | + // and ticket rows so we start our dtt loop again. |
|
1124 | + $datetime_row = 1; |
|
1125 | + foreach ($datetimes as $datetime) { |
|
1126 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1127 | + $datetime_row, |
|
1128 | + $datetime, |
|
1129 | + $datetime_tickets, |
|
1130 | + $all_tickets, |
|
1131 | + false, |
|
1132 | + $datetimes |
|
1133 | + ); |
|
1134 | + $datetime_row++; |
|
1135 | + } |
|
1136 | + // then loop through all tickets for the ticket rows. |
|
1137 | + $ticket_row = 1; |
|
1138 | + foreach ($all_tickets as $ticket) { |
|
1139 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1140 | + $ticket_row, |
|
1141 | + $ticket, |
|
1142 | + $ticket_datetimes, |
|
1143 | + $datetimes, |
|
1144 | + false, |
|
1145 | + $all_tickets |
|
1146 | + ); |
|
1147 | + $ticket_row++; |
|
1148 | + } |
|
1149 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1150 | + EEH_Template::display_template( |
|
1151 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1152 | + $main_template_args |
|
1153 | + ); |
|
1154 | + } |
|
1155 | 1155 | |
1156 | 1156 | |
1157 | - /** |
|
1158 | - * @param int $datetime_row |
|
1159 | - * @param EE_Datetime $datetime |
|
1160 | - * @param array $datetime_tickets |
|
1161 | - * @param array $all_tickets |
|
1162 | - * @param bool $default |
|
1163 | - * @param array $all_datetimes |
|
1164 | - * @return mixed |
|
1165 | - * @throws DomainException |
|
1166 | - * @throws EE_Error |
|
1167 | - */ |
|
1168 | - protected function _get_datetime_row( |
|
1169 | - $datetime_row, |
|
1170 | - EE_Datetime $datetime, |
|
1171 | - $datetime_tickets = array(), |
|
1172 | - $all_tickets = array(), |
|
1173 | - $default = false, |
|
1174 | - $all_datetimes = array() |
|
1175 | - ) { |
|
1176 | - $dtt_display_template_args = array( |
|
1177 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1178 | - $datetime_row, |
|
1179 | - $datetime, |
|
1180 | - $default, |
|
1181 | - $all_datetimes |
|
1182 | - ), |
|
1183 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1184 | - $datetime_row, |
|
1185 | - $datetime, |
|
1186 | - $datetime_tickets, |
|
1187 | - $all_tickets, |
|
1188 | - $default |
|
1189 | - ), |
|
1190 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1191 | - ); |
|
1192 | - return EEH_Template::display_template( |
|
1193 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1194 | - $dtt_display_template_args, |
|
1195 | - true |
|
1196 | - ); |
|
1197 | - } |
|
1157 | + /** |
|
1158 | + * @param int $datetime_row |
|
1159 | + * @param EE_Datetime $datetime |
|
1160 | + * @param array $datetime_tickets |
|
1161 | + * @param array $all_tickets |
|
1162 | + * @param bool $default |
|
1163 | + * @param array $all_datetimes |
|
1164 | + * @return mixed |
|
1165 | + * @throws DomainException |
|
1166 | + * @throws EE_Error |
|
1167 | + */ |
|
1168 | + protected function _get_datetime_row( |
|
1169 | + $datetime_row, |
|
1170 | + EE_Datetime $datetime, |
|
1171 | + $datetime_tickets = array(), |
|
1172 | + $all_tickets = array(), |
|
1173 | + $default = false, |
|
1174 | + $all_datetimes = array() |
|
1175 | + ) { |
|
1176 | + $dtt_display_template_args = array( |
|
1177 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1178 | + $datetime_row, |
|
1179 | + $datetime, |
|
1180 | + $default, |
|
1181 | + $all_datetimes |
|
1182 | + ), |
|
1183 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1184 | + $datetime_row, |
|
1185 | + $datetime, |
|
1186 | + $datetime_tickets, |
|
1187 | + $all_tickets, |
|
1188 | + $default |
|
1189 | + ), |
|
1190 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1191 | + ); |
|
1192 | + return EEH_Template::display_template( |
|
1193 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1194 | + $dtt_display_template_args, |
|
1195 | + true |
|
1196 | + ); |
|
1197 | + } |
|
1198 | 1198 | |
1199 | 1199 | |
1200 | - /** |
|
1201 | - * This method is used to generate a dtt fields edit row. |
|
1202 | - * The same row is used to generate a row with valid DTT objects |
|
1203 | - * and the default row that is used as the skeleton by the js. |
|
1204 | - * |
|
1205 | - * @param int $datetime_row The row number for the row being generated. |
|
1206 | - * @param EE_Datetime $datetime |
|
1207 | - * @param bool $default Whether a default row is being generated or not. |
|
1208 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1209 | - * @return string |
|
1210 | - * @throws DomainException |
|
1211 | - * @throws EE_Error |
|
1212 | - */ |
|
1213 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1214 | - { |
|
1215 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1216 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1217 | - $template_args = array( |
|
1218 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1219 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1220 | - 'edit_dtt_expanded' => '', |
|
1221 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1222 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1223 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1224 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1225 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1226 | - 'DTT_reg_limit' => $default |
|
1227 | - ? '' |
|
1228 | - : $datetime->get_pretty( |
|
1229 | - 'DTT_reg_limit', |
|
1230 | - 'input' |
|
1231 | - ), |
|
1232 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1233 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1234 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1235 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1236 | - ? '' |
|
1237 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1238 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1239 | - ? 'ee-lock-icon' |
|
1240 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1241 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1242 | - ? '' |
|
1243 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1244 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1245 | - REG_ADMIN_URL |
|
1246 | - ), |
|
1247 | - ); |
|
1248 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1249 | - ? ' style="display:none"' |
|
1250 | - : ''; |
|
1251 | - // allow filtering of template args at this point. |
|
1252 | - $template_args = apply_filters( |
|
1253 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1254 | - $template_args, |
|
1255 | - $datetime_row, |
|
1256 | - $datetime, |
|
1257 | - $default, |
|
1258 | - $all_datetimes, |
|
1259 | - $this->_is_creating_event |
|
1260 | - ); |
|
1261 | - return EEH_Template::display_template( |
|
1262 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1263 | - $template_args, |
|
1264 | - true |
|
1265 | - ); |
|
1266 | - } |
|
1200 | + /** |
|
1201 | + * This method is used to generate a dtt fields edit row. |
|
1202 | + * The same row is used to generate a row with valid DTT objects |
|
1203 | + * and the default row that is used as the skeleton by the js. |
|
1204 | + * |
|
1205 | + * @param int $datetime_row The row number for the row being generated. |
|
1206 | + * @param EE_Datetime $datetime |
|
1207 | + * @param bool $default Whether a default row is being generated or not. |
|
1208 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1209 | + * @return string |
|
1210 | + * @throws DomainException |
|
1211 | + * @throws EE_Error |
|
1212 | + */ |
|
1213 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1214 | + { |
|
1215 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1216 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1217 | + $template_args = array( |
|
1218 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1219 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1220 | + 'edit_dtt_expanded' => '', |
|
1221 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1222 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1223 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1224 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1225 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1226 | + 'DTT_reg_limit' => $default |
|
1227 | + ? '' |
|
1228 | + : $datetime->get_pretty( |
|
1229 | + 'DTT_reg_limit', |
|
1230 | + 'input' |
|
1231 | + ), |
|
1232 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1233 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1234 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1235 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1236 | + ? '' |
|
1237 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1238 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1239 | + ? 'ee-lock-icon' |
|
1240 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1241 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1242 | + ? '' |
|
1243 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1244 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1245 | + REG_ADMIN_URL |
|
1246 | + ), |
|
1247 | + ); |
|
1248 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1249 | + ? ' style="display:none"' |
|
1250 | + : ''; |
|
1251 | + // allow filtering of template args at this point. |
|
1252 | + $template_args = apply_filters( |
|
1253 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1254 | + $template_args, |
|
1255 | + $datetime_row, |
|
1256 | + $datetime, |
|
1257 | + $default, |
|
1258 | + $all_datetimes, |
|
1259 | + $this->_is_creating_event |
|
1260 | + ); |
|
1261 | + return EEH_Template::display_template( |
|
1262 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1263 | + $template_args, |
|
1264 | + true |
|
1265 | + ); |
|
1266 | + } |
|
1267 | 1267 | |
1268 | 1268 | |
1269 | - /** |
|
1270 | - * @param int $datetime_row |
|
1271 | - * @param EE_Datetime $datetime |
|
1272 | - * @param array $datetime_tickets |
|
1273 | - * @param array $all_tickets |
|
1274 | - * @param bool $default |
|
1275 | - * @return mixed |
|
1276 | - * @throws DomainException |
|
1277 | - * @throws EE_Error |
|
1278 | - */ |
|
1279 | - protected function _get_dtt_attached_tickets_row( |
|
1280 | - $datetime_row, |
|
1281 | - $datetime, |
|
1282 | - $datetime_tickets = array(), |
|
1283 | - $all_tickets = array(), |
|
1284 | - $default |
|
1285 | - ) { |
|
1286 | - $template_args = array( |
|
1287 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1288 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1289 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1290 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1291 | - 'show_tickets_row' => ' style="display:none;"', |
|
1292 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1293 | - 'add_new_ticket_via_datetime', |
|
1294 | - $this->_adminpage_obj->page_slug, |
|
1295 | - $this->_adminpage_obj->get_req_action(), |
|
1296 | - false, |
|
1297 | - false |
|
1298 | - ), |
|
1299 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1300 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1301 | - ); |
|
1302 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1303 | - if (! $default) { |
|
1304 | - $ticket_row = 1; |
|
1305 | - foreach ($all_tickets as $ticket) { |
|
1306 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1307 | - $datetime_row, |
|
1308 | - $ticket_row, |
|
1309 | - $datetime, |
|
1310 | - $ticket, |
|
1311 | - $datetime_tickets, |
|
1312 | - $default |
|
1313 | - ); |
|
1314 | - $ticket_row++; |
|
1315 | - } |
|
1316 | - } |
|
1317 | - // filter template args at this point |
|
1318 | - $template_args = apply_filters( |
|
1319 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1320 | - $template_args, |
|
1321 | - $datetime_row, |
|
1322 | - $datetime, |
|
1323 | - $datetime_tickets, |
|
1324 | - $all_tickets, |
|
1325 | - $default, |
|
1326 | - $this->_is_creating_event |
|
1327 | - ); |
|
1328 | - return EEH_Template::display_template( |
|
1329 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1330 | - $template_args, |
|
1331 | - true |
|
1332 | - ); |
|
1333 | - } |
|
1269 | + /** |
|
1270 | + * @param int $datetime_row |
|
1271 | + * @param EE_Datetime $datetime |
|
1272 | + * @param array $datetime_tickets |
|
1273 | + * @param array $all_tickets |
|
1274 | + * @param bool $default |
|
1275 | + * @return mixed |
|
1276 | + * @throws DomainException |
|
1277 | + * @throws EE_Error |
|
1278 | + */ |
|
1279 | + protected function _get_dtt_attached_tickets_row( |
|
1280 | + $datetime_row, |
|
1281 | + $datetime, |
|
1282 | + $datetime_tickets = array(), |
|
1283 | + $all_tickets = array(), |
|
1284 | + $default |
|
1285 | + ) { |
|
1286 | + $template_args = array( |
|
1287 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1288 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1289 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1290 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1291 | + 'show_tickets_row' => ' style="display:none;"', |
|
1292 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1293 | + 'add_new_ticket_via_datetime', |
|
1294 | + $this->_adminpage_obj->page_slug, |
|
1295 | + $this->_adminpage_obj->get_req_action(), |
|
1296 | + false, |
|
1297 | + false |
|
1298 | + ), |
|
1299 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1300 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1301 | + ); |
|
1302 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1303 | + if (! $default) { |
|
1304 | + $ticket_row = 1; |
|
1305 | + foreach ($all_tickets as $ticket) { |
|
1306 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1307 | + $datetime_row, |
|
1308 | + $ticket_row, |
|
1309 | + $datetime, |
|
1310 | + $ticket, |
|
1311 | + $datetime_tickets, |
|
1312 | + $default |
|
1313 | + ); |
|
1314 | + $ticket_row++; |
|
1315 | + } |
|
1316 | + } |
|
1317 | + // filter template args at this point |
|
1318 | + $template_args = apply_filters( |
|
1319 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1320 | + $template_args, |
|
1321 | + $datetime_row, |
|
1322 | + $datetime, |
|
1323 | + $datetime_tickets, |
|
1324 | + $all_tickets, |
|
1325 | + $default, |
|
1326 | + $this->_is_creating_event |
|
1327 | + ); |
|
1328 | + return EEH_Template::display_template( |
|
1329 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1330 | + $template_args, |
|
1331 | + true |
|
1332 | + ); |
|
1333 | + } |
|
1334 | 1334 | |
1335 | 1335 | |
1336 | - /** |
|
1337 | - * @param int $datetime_row |
|
1338 | - * @param int $ticket_row |
|
1339 | - * @param EE_Datetime $datetime |
|
1340 | - * @param EE_Ticket $ticket |
|
1341 | - * @param array $datetime_tickets |
|
1342 | - * @param bool $default |
|
1343 | - * @return mixed |
|
1344 | - * @throws DomainException |
|
1345 | - * @throws EE_Error |
|
1346 | - */ |
|
1347 | - protected function _get_datetime_tickets_list_item( |
|
1348 | - $datetime_row, |
|
1349 | - $ticket_row, |
|
1350 | - $datetime, |
|
1351 | - $ticket, |
|
1352 | - $datetime_tickets = array(), |
|
1353 | - $default |
|
1354 | - ) { |
|
1355 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1356 | - ? $datetime_tickets[ $datetime->ID() ] |
|
1357 | - : array(); |
|
1358 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1359 | - $no_ticket = $default && empty($ticket); |
|
1360 | - $template_args = array( |
|
1361 | - 'dtt_row' => $default |
|
1362 | - ? 'DTTNUM' |
|
1363 | - : $datetime_row, |
|
1364 | - 'tkt_row' => $no_ticket |
|
1365 | - ? 'TICKETNUM' |
|
1366 | - : $ticket_row, |
|
1367 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1368 | - ? ' checked="checked"' |
|
1369 | - : '', |
|
1370 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1371 | - ? ' ticket-selected' |
|
1372 | - : '', |
|
1373 | - 'TKT_name' => $no_ticket |
|
1374 | - ? 'TKTNAME' |
|
1375 | - : $ticket->get('TKT_name'), |
|
1376 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1377 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1378 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1379 | - ); |
|
1380 | - // filter template args |
|
1381 | - $template_args = apply_filters( |
|
1382 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1383 | - $template_args, |
|
1384 | - $datetime_row, |
|
1385 | - $ticket_row, |
|
1386 | - $datetime, |
|
1387 | - $ticket, |
|
1388 | - $datetime_tickets, |
|
1389 | - $default, |
|
1390 | - $this->_is_creating_event |
|
1391 | - ); |
|
1392 | - return EEH_Template::display_template( |
|
1393 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1394 | - $template_args, |
|
1395 | - true |
|
1396 | - ); |
|
1397 | - } |
|
1336 | + /** |
|
1337 | + * @param int $datetime_row |
|
1338 | + * @param int $ticket_row |
|
1339 | + * @param EE_Datetime $datetime |
|
1340 | + * @param EE_Ticket $ticket |
|
1341 | + * @param array $datetime_tickets |
|
1342 | + * @param bool $default |
|
1343 | + * @return mixed |
|
1344 | + * @throws DomainException |
|
1345 | + * @throws EE_Error |
|
1346 | + */ |
|
1347 | + protected function _get_datetime_tickets_list_item( |
|
1348 | + $datetime_row, |
|
1349 | + $ticket_row, |
|
1350 | + $datetime, |
|
1351 | + $ticket, |
|
1352 | + $datetime_tickets = array(), |
|
1353 | + $default |
|
1354 | + ) { |
|
1355 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1356 | + ? $datetime_tickets[ $datetime->ID() ] |
|
1357 | + : array(); |
|
1358 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1359 | + $no_ticket = $default && empty($ticket); |
|
1360 | + $template_args = array( |
|
1361 | + 'dtt_row' => $default |
|
1362 | + ? 'DTTNUM' |
|
1363 | + : $datetime_row, |
|
1364 | + 'tkt_row' => $no_ticket |
|
1365 | + ? 'TICKETNUM' |
|
1366 | + : $ticket_row, |
|
1367 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1368 | + ? ' checked="checked"' |
|
1369 | + : '', |
|
1370 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1371 | + ? ' ticket-selected' |
|
1372 | + : '', |
|
1373 | + 'TKT_name' => $no_ticket |
|
1374 | + ? 'TKTNAME' |
|
1375 | + : $ticket->get('TKT_name'), |
|
1376 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1377 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1378 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1379 | + ); |
|
1380 | + // filter template args |
|
1381 | + $template_args = apply_filters( |
|
1382 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1383 | + $template_args, |
|
1384 | + $datetime_row, |
|
1385 | + $ticket_row, |
|
1386 | + $datetime, |
|
1387 | + $ticket, |
|
1388 | + $datetime_tickets, |
|
1389 | + $default, |
|
1390 | + $this->_is_creating_event |
|
1391 | + ); |
|
1392 | + return EEH_Template::display_template( |
|
1393 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1394 | + $template_args, |
|
1395 | + true |
|
1396 | + ); |
|
1397 | + } |
|
1398 | 1398 | |
1399 | 1399 | |
1400 | - /** |
|
1401 | - * This generates the ticket row for tickets. |
|
1402 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1403 | - * (when default === true) |
|
1404 | - * |
|
1405 | - * @param int $ticket_row Represents the row number being generated. |
|
1406 | - * @param $ticket |
|
1407 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1408 | - * or empty for default |
|
1409 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1410 | - * @param bool $default Whether default row being generated or not. |
|
1411 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1412 | - * (or empty in the case of defaults) |
|
1413 | - * @return mixed |
|
1414 | - * @throws InvalidArgumentException |
|
1415 | - * @throws InvalidInterfaceException |
|
1416 | - * @throws InvalidDataTypeException |
|
1417 | - * @throws DomainException |
|
1418 | - * @throws EE_Error |
|
1419 | - * @throws ReflectionException |
|
1420 | - */ |
|
1421 | - protected function _get_ticket_row( |
|
1422 | - $ticket_row, |
|
1423 | - $ticket, |
|
1424 | - $ticket_datetimes, |
|
1425 | - $all_datetimes, |
|
1426 | - $default = false, |
|
1427 | - $all_tickets = array() |
|
1428 | - ) { |
|
1429 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1430 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1431 | - $prices = ! empty($ticket) && ! $default |
|
1432 | - ? $ticket->get_many_related( |
|
1433 | - 'Price', |
|
1434 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1435 | - ) |
|
1436 | - : array(); |
|
1437 | - // if there is only one price (which would be the base price) |
|
1438 | - // or NO prices and this ticket is a default ticket, |
|
1439 | - // let's just make sure there are no cached default prices on the object. |
|
1440 | - // This is done by not including any query_params. |
|
1441 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1442 | - $prices = $ticket->prices(); |
|
1443 | - } |
|
1444 | - // check if we're dealing with a default ticket in which case |
|
1445 | - // we don't want any starting_ticket_datetime_row values set |
|
1446 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1447 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1448 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1449 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1450 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
1451 | - : array(); |
|
1452 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1453 | - $base_price = $default ? null : $ticket->base_price(); |
|
1454 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1455 | - // breaking out complicated condition for ticket_status |
|
1456 | - if ($default) { |
|
1457 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1458 | - } else { |
|
1459 | - $ticket_status_class = $ticket->is_default() |
|
1460 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1461 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1462 | - } |
|
1463 | - // breaking out complicated condition for TKT_taxable |
|
1464 | - if ($default) { |
|
1465 | - $TKT_taxable = ''; |
|
1466 | - } else { |
|
1467 | - $TKT_taxable = $ticket->taxable() |
|
1468 | - ? ' checked="checked"' |
|
1469 | - : ''; |
|
1470 | - } |
|
1471 | - if ($default) { |
|
1472 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1473 | - } elseif ($ticket->is_default()) { |
|
1474 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1475 | - } else { |
|
1476 | - $TKT_status = $ticket->ticket_status(true); |
|
1477 | - } |
|
1478 | - if ($default) { |
|
1479 | - $TKT_min = ''; |
|
1480 | - } else { |
|
1481 | - $TKT_min = $ticket->min(); |
|
1482 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1483 | - $TKT_min = ''; |
|
1484 | - } |
|
1485 | - } |
|
1486 | - $template_args = array( |
|
1487 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1488 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1489 | - // on initial page load this will always be the correct order. |
|
1490 | - 'tkt_status_class' => $ticket_status_class, |
|
1491 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1492 | - 'edit_tkt_expanded' => '', |
|
1493 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1494 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1495 | - 'TKT_start_date' => $default |
|
1496 | - ? '' |
|
1497 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1498 | - 'TKT_end_date' => $default |
|
1499 | - ? '' |
|
1500 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1501 | - 'TKT_status' => $TKT_status, |
|
1502 | - 'TKT_price' => $default |
|
1503 | - ? '' |
|
1504 | - : EEH_Template::format_currency( |
|
1505 | - $ticket->get_ticket_total_with_taxes(), |
|
1506 | - false, |
|
1507 | - false |
|
1508 | - ), |
|
1509 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1510 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1511 | - 'TKT_qty' => $default |
|
1512 | - ? '' |
|
1513 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1514 | - 'TKT_qty_for_input' => $default |
|
1515 | - ? '' |
|
1516 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1517 | - 'TKT_uses' => $default |
|
1518 | - ? '' |
|
1519 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1520 | - 'TKT_min' => $TKT_min, |
|
1521 | - 'TKT_max' => $default |
|
1522 | - ? '' |
|
1523 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1524 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1525 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1526 | - 'TKT_registrations' => $default |
|
1527 | - ? 0 |
|
1528 | - : $ticket->count_registrations( |
|
1529 | - array( |
|
1530 | - array( |
|
1531 | - 'STS_ID' => array( |
|
1532 | - '!=', |
|
1533 | - EEM_Registration::status_id_incomplete, |
|
1534 | - ), |
|
1535 | - ), |
|
1536 | - ) |
|
1537 | - ), |
|
1538 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1539 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1540 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1541 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1542 | - 'TKT_is_default_selector' => '', |
|
1543 | - 'ticket_price_rows' => '', |
|
1544 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1545 | - ? '' |
|
1546 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1547 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1548 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1549 | - ? '' |
|
1550 | - : ' style="display:none;"', |
|
1551 | - 'show_price_mod_button' => count($prices) > 1 |
|
1552 | - || ($default && $count_price_mods > 0) |
|
1553 | - || (! $default && $ticket->deleted()) |
|
1554 | - ? ' style="display:none;"' |
|
1555 | - : '', |
|
1556 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1557 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1558 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1559 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1560 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1561 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1562 | - 'TKT_taxable' => $TKT_taxable, |
|
1563 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1564 | - ? '' |
|
1565 | - : ' style="display:none"', |
|
1566 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1567 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1568 | - $ticket_subtotal, |
|
1569 | - false, |
|
1570 | - false |
|
1571 | - ), |
|
1572 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1573 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1574 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1575 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1576 | - ? ' ticket-archived' |
|
1577 | - : '', |
|
1578 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
1579 | - && $ticket->deleted() |
|
1580 | - && ! $ticket->is_permanently_deleteable() |
|
1581 | - ? 'ee-lock-icon ' |
|
1582 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1583 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1584 | - ? '' |
|
1585 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1586 | - ); |
|
1587 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1588 | - ? ' style="display:none"' |
|
1589 | - : ''; |
|
1590 | - // handle rows that should NOT be empty |
|
1591 | - if (empty($template_args['TKT_start_date'])) { |
|
1592 | - // if empty then the start date will be now. |
|
1593 | - $template_args['TKT_start_date'] = date( |
|
1594 | - $this->_date_time_format, |
|
1595 | - current_time('timestamp') |
|
1596 | - ); |
|
1597 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1598 | - } |
|
1599 | - if (empty($template_args['TKT_end_date'])) { |
|
1600 | - // get the earliest datetime (if present); |
|
1601 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1602 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1603 | - 'Datetime', |
|
1604 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1605 | - ) |
|
1606 | - : null; |
|
1607 | - if (! empty($earliest_dtt)) { |
|
1608 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1609 | - 'DTT_EVT_start', |
|
1610 | - $this->_date_time_format |
|
1611 | - ); |
|
1612 | - } else { |
|
1613 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1614 | - $template_args['TKT_end_date'] = date( |
|
1615 | - $this->_date_time_format, |
|
1616 | - mktime( |
|
1617 | - 24, |
|
1618 | - 0, |
|
1619 | - 0, |
|
1620 | - date('m'), |
|
1621 | - date('d') + 29, |
|
1622 | - date('Y') |
|
1623 | - ) |
|
1624 | - ); |
|
1625 | - } |
|
1626 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1627 | - } |
|
1628 | - // generate ticket_datetime items |
|
1629 | - if (! $default) { |
|
1630 | - $datetime_row = 1; |
|
1631 | - foreach ($all_datetimes as $datetime) { |
|
1632 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1633 | - $datetime_row, |
|
1634 | - $ticket_row, |
|
1635 | - $datetime, |
|
1636 | - $ticket, |
|
1637 | - $ticket_datetimes, |
|
1638 | - $default |
|
1639 | - ); |
|
1640 | - $datetime_row++; |
|
1641 | - } |
|
1642 | - } |
|
1643 | - $price_row = 1; |
|
1644 | - foreach ($prices as $price) { |
|
1645 | - if (! $price instanceof EE_Price) { |
|
1646 | - continue; |
|
1647 | - } |
|
1648 | - if ($price->is_base_price()) { |
|
1649 | - $price_row++; |
|
1650 | - continue; |
|
1651 | - } |
|
1652 | - $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1653 | - $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1654 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1655 | - $ticket_row, |
|
1656 | - $price_row, |
|
1657 | - $price, |
|
1658 | - $default, |
|
1659 | - $ticket, |
|
1660 | - $show_trash, |
|
1661 | - $show_create |
|
1662 | - ); |
|
1663 | - $price_row++; |
|
1664 | - } |
|
1665 | - // filter $template_args |
|
1666 | - $template_args = apply_filters( |
|
1667 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1668 | - $template_args, |
|
1669 | - $ticket_row, |
|
1670 | - $ticket, |
|
1671 | - $ticket_datetimes, |
|
1672 | - $all_datetimes, |
|
1673 | - $default, |
|
1674 | - $all_tickets, |
|
1675 | - $this->_is_creating_event |
|
1676 | - ); |
|
1677 | - return EEH_Template::display_template( |
|
1678 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1679 | - $template_args, |
|
1680 | - true |
|
1681 | - ); |
|
1682 | - } |
|
1400 | + /** |
|
1401 | + * This generates the ticket row for tickets. |
|
1402 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1403 | + * (when default === true) |
|
1404 | + * |
|
1405 | + * @param int $ticket_row Represents the row number being generated. |
|
1406 | + * @param $ticket |
|
1407 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1408 | + * or empty for default |
|
1409 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1410 | + * @param bool $default Whether default row being generated or not. |
|
1411 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1412 | + * (or empty in the case of defaults) |
|
1413 | + * @return mixed |
|
1414 | + * @throws InvalidArgumentException |
|
1415 | + * @throws InvalidInterfaceException |
|
1416 | + * @throws InvalidDataTypeException |
|
1417 | + * @throws DomainException |
|
1418 | + * @throws EE_Error |
|
1419 | + * @throws ReflectionException |
|
1420 | + */ |
|
1421 | + protected function _get_ticket_row( |
|
1422 | + $ticket_row, |
|
1423 | + $ticket, |
|
1424 | + $ticket_datetimes, |
|
1425 | + $all_datetimes, |
|
1426 | + $default = false, |
|
1427 | + $all_tickets = array() |
|
1428 | + ) { |
|
1429 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1430 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1431 | + $prices = ! empty($ticket) && ! $default |
|
1432 | + ? $ticket->get_many_related( |
|
1433 | + 'Price', |
|
1434 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1435 | + ) |
|
1436 | + : array(); |
|
1437 | + // if there is only one price (which would be the base price) |
|
1438 | + // or NO prices and this ticket is a default ticket, |
|
1439 | + // let's just make sure there are no cached default prices on the object. |
|
1440 | + // This is done by not including any query_params. |
|
1441 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1442 | + $prices = $ticket->prices(); |
|
1443 | + } |
|
1444 | + // check if we're dealing with a default ticket in which case |
|
1445 | + // we don't want any starting_ticket_datetime_row values set |
|
1446 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1447 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1448 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1449 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1450 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
1451 | + : array(); |
|
1452 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1453 | + $base_price = $default ? null : $ticket->base_price(); |
|
1454 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1455 | + // breaking out complicated condition for ticket_status |
|
1456 | + if ($default) { |
|
1457 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1458 | + } else { |
|
1459 | + $ticket_status_class = $ticket->is_default() |
|
1460 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1461 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1462 | + } |
|
1463 | + // breaking out complicated condition for TKT_taxable |
|
1464 | + if ($default) { |
|
1465 | + $TKT_taxable = ''; |
|
1466 | + } else { |
|
1467 | + $TKT_taxable = $ticket->taxable() |
|
1468 | + ? ' checked="checked"' |
|
1469 | + : ''; |
|
1470 | + } |
|
1471 | + if ($default) { |
|
1472 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1473 | + } elseif ($ticket->is_default()) { |
|
1474 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1475 | + } else { |
|
1476 | + $TKT_status = $ticket->ticket_status(true); |
|
1477 | + } |
|
1478 | + if ($default) { |
|
1479 | + $TKT_min = ''; |
|
1480 | + } else { |
|
1481 | + $TKT_min = $ticket->min(); |
|
1482 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1483 | + $TKT_min = ''; |
|
1484 | + } |
|
1485 | + } |
|
1486 | + $template_args = array( |
|
1487 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1488 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1489 | + // on initial page load this will always be the correct order. |
|
1490 | + 'tkt_status_class' => $ticket_status_class, |
|
1491 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1492 | + 'edit_tkt_expanded' => '', |
|
1493 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1494 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1495 | + 'TKT_start_date' => $default |
|
1496 | + ? '' |
|
1497 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1498 | + 'TKT_end_date' => $default |
|
1499 | + ? '' |
|
1500 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1501 | + 'TKT_status' => $TKT_status, |
|
1502 | + 'TKT_price' => $default |
|
1503 | + ? '' |
|
1504 | + : EEH_Template::format_currency( |
|
1505 | + $ticket->get_ticket_total_with_taxes(), |
|
1506 | + false, |
|
1507 | + false |
|
1508 | + ), |
|
1509 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1510 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1511 | + 'TKT_qty' => $default |
|
1512 | + ? '' |
|
1513 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1514 | + 'TKT_qty_for_input' => $default |
|
1515 | + ? '' |
|
1516 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1517 | + 'TKT_uses' => $default |
|
1518 | + ? '' |
|
1519 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1520 | + 'TKT_min' => $TKT_min, |
|
1521 | + 'TKT_max' => $default |
|
1522 | + ? '' |
|
1523 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1524 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1525 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1526 | + 'TKT_registrations' => $default |
|
1527 | + ? 0 |
|
1528 | + : $ticket->count_registrations( |
|
1529 | + array( |
|
1530 | + array( |
|
1531 | + 'STS_ID' => array( |
|
1532 | + '!=', |
|
1533 | + EEM_Registration::status_id_incomplete, |
|
1534 | + ), |
|
1535 | + ), |
|
1536 | + ) |
|
1537 | + ), |
|
1538 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1539 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1540 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1541 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1542 | + 'TKT_is_default_selector' => '', |
|
1543 | + 'ticket_price_rows' => '', |
|
1544 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1545 | + ? '' |
|
1546 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1547 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1548 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1549 | + ? '' |
|
1550 | + : ' style="display:none;"', |
|
1551 | + 'show_price_mod_button' => count($prices) > 1 |
|
1552 | + || ($default && $count_price_mods > 0) |
|
1553 | + || (! $default && $ticket->deleted()) |
|
1554 | + ? ' style="display:none;"' |
|
1555 | + : '', |
|
1556 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1557 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1558 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1559 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1560 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1561 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1562 | + 'TKT_taxable' => $TKT_taxable, |
|
1563 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1564 | + ? '' |
|
1565 | + : ' style="display:none"', |
|
1566 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1567 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1568 | + $ticket_subtotal, |
|
1569 | + false, |
|
1570 | + false |
|
1571 | + ), |
|
1572 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1573 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1574 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1575 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1576 | + ? ' ticket-archived' |
|
1577 | + : '', |
|
1578 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
1579 | + && $ticket->deleted() |
|
1580 | + && ! $ticket->is_permanently_deleteable() |
|
1581 | + ? 'ee-lock-icon ' |
|
1582 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1583 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1584 | + ? '' |
|
1585 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1586 | + ); |
|
1587 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1588 | + ? ' style="display:none"' |
|
1589 | + : ''; |
|
1590 | + // handle rows that should NOT be empty |
|
1591 | + if (empty($template_args['TKT_start_date'])) { |
|
1592 | + // if empty then the start date will be now. |
|
1593 | + $template_args['TKT_start_date'] = date( |
|
1594 | + $this->_date_time_format, |
|
1595 | + current_time('timestamp') |
|
1596 | + ); |
|
1597 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1598 | + } |
|
1599 | + if (empty($template_args['TKT_end_date'])) { |
|
1600 | + // get the earliest datetime (if present); |
|
1601 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1602 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1603 | + 'Datetime', |
|
1604 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1605 | + ) |
|
1606 | + : null; |
|
1607 | + if (! empty($earliest_dtt)) { |
|
1608 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1609 | + 'DTT_EVT_start', |
|
1610 | + $this->_date_time_format |
|
1611 | + ); |
|
1612 | + } else { |
|
1613 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1614 | + $template_args['TKT_end_date'] = date( |
|
1615 | + $this->_date_time_format, |
|
1616 | + mktime( |
|
1617 | + 24, |
|
1618 | + 0, |
|
1619 | + 0, |
|
1620 | + date('m'), |
|
1621 | + date('d') + 29, |
|
1622 | + date('Y') |
|
1623 | + ) |
|
1624 | + ); |
|
1625 | + } |
|
1626 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1627 | + } |
|
1628 | + // generate ticket_datetime items |
|
1629 | + if (! $default) { |
|
1630 | + $datetime_row = 1; |
|
1631 | + foreach ($all_datetimes as $datetime) { |
|
1632 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1633 | + $datetime_row, |
|
1634 | + $ticket_row, |
|
1635 | + $datetime, |
|
1636 | + $ticket, |
|
1637 | + $ticket_datetimes, |
|
1638 | + $default |
|
1639 | + ); |
|
1640 | + $datetime_row++; |
|
1641 | + } |
|
1642 | + } |
|
1643 | + $price_row = 1; |
|
1644 | + foreach ($prices as $price) { |
|
1645 | + if (! $price instanceof EE_Price) { |
|
1646 | + continue; |
|
1647 | + } |
|
1648 | + if ($price->is_base_price()) { |
|
1649 | + $price_row++; |
|
1650 | + continue; |
|
1651 | + } |
|
1652 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1653 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1654 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1655 | + $ticket_row, |
|
1656 | + $price_row, |
|
1657 | + $price, |
|
1658 | + $default, |
|
1659 | + $ticket, |
|
1660 | + $show_trash, |
|
1661 | + $show_create |
|
1662 | + ); |
|
1663 | + $price_row++; |
|
1664 | + } |
|
1665 | + // filter $template_args |
|
1666 | + $template_args = apply_filters( |
|
1667 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1668 | + $template_args, |
|
1669 | + $ticket_row, |
|
1670 | + $ticket, |
|
1671 | + $ticket_datetimes, |
|
1672 | + $all_datetimes, |
|
1673 | + $default, |
|
1674 | + $all_tickets, |
|
1675 | + $this->_is_creating_event |
|
1676 | + ); |
|
1677 | + return EEH_Template::display_template( |
|
1678 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1679 | + $template_args, |
|
1680 | + true |
|
1681 | + ); |
|
1682 | + } |
|
1683 | 1683 | |
1684 | 1684 | |
1685 | - /** |
|
1686 | - * @param int $ticket_row |
|
1687 | - * @param EE_Ticket|null $ticket |
|
1688 | - * @return string |
|
1689 | - * @throws DomainException |
|
1690 | - * @throws EE_Error |
|
1691 | - */ |
|
1692 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1693 | - { |
|
1694 | - $tax_rows = ''; |
|
1695 | - /** @var EE_Price[] $taxes */ |
|
1696 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1697 | - foreach ($taxes as $tax) { |
|
1698 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1699 | - $template_args = array( |
|
1700 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1701 | - ? '' |
|
1702 | - : ' style="display:none;"', |
|
1703 | - 'tax_id' => $tax->ID(), |
|
1704 | - 'tkt_row' => $ticket_row, |
|
1705 | - 'tax_label' => $tax->get('PRC_name'), |
|
1706 | - 'tax_added' => $tax_added, |
|
1707 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1708 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1709 | - ); |
|
1710 | - $template_args = apply_filters( |
|
1711 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1712 | - $template_args, |
|
1713 | - $ticket_row, |
|
1714 | - $ticket, |
|
1715 | - $this->_is_creating_event |
|
1716 | - ); |
|
1717 | - $tax_rows .= EEH_Template::display_template( |
|
1718 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1719 | - $template_args, |
|
1720 | - true |
|
1721 | - ); |
|
1722 | - } |
|
1723 | - return $tax_rows; |
|
1724 | - } |
|
1685 | + /** |
|
1686 | + * @param int $ticket_row |
|
1687 | + * @param EE_Ticket|null $ticket |
|
1688 | + * @return string |
|
1689 | + * @throws DomainException |
|
1690 | + * @throws EE_Error |
|
1691 | + */ |
|
1692 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1693 | + { |
|
1694 | + $tax_rows = ''; |
|
1695 | + /** @var EE_Price[] $taxes */ |
|
1696 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1697 | + foreach ($taxes as $tax) { |
|
1698 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1699 | + $template_args = array( |
|
1700 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1701 | + ? '' |
|
1702 | + : ' style="display:none;"', |
|
1703 | + 'tax_id' => $tax->ID(), |
|
1704 | + 'tkt_row' => $ticket_row, |
|
1705 | + 'tax_label' => $tax->get('PRC_name'), |
|
1706 | + 'tax_added' => $tax_added, |
|
1707 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1708 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1709 | + ); |
|
1710 | + $template_args = apply_filters( |
|
1711 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1712 | + $template_args, |
|
1713 | + $ticket_row, |
|
1714 | + $ticket, |
|
1715 | + $this->_is_creating_event |
|
1716 | + ); |
|
1717 | + $tax_rows .= EEH_Template::display_template( |
|
1718 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1719 | + $template_args, |
|
1720 | + true |
|
1721 | + ); |
|
1722 | + } |
|
1723 | + return $tax_rows; |
|
1724 | + } |
|
1725 | 1725 | |
1726 | 1726 | |
1727 | - /** |
|
1728 | - * @param EE_Price $tax |
|
1729 | - * @param EE_Ticket|null $ticket |
|
1730 | - * @return float|int |
|
1731 | - * @throws EE_Error |
|
1732 | - */ |
|
1733 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1734 | - { |
|
1735 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1736 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1737 | - } |
|
1727 | + /** |
|
1728 | + * @param EE_Price $tax |
|
1729 | + * @param EE_Ticket|null $ticket |
|
1730 | + * @return float|int |
|
1731 | + * @throws EE_Error |
|
1732 | + */ |
|
1733 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1734 | + { |
|
1735 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1736 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1737 | + } |
|
1738 | 1738 | |
1739 | 1739 | |
1740 | - /** |
|
1741 | - * @param int $ticket_row |
|
1742 | - * @param int $price_row |
|
1743 | - * @param EE_Price|null $price |
|
1744 | - * @param bool $default |
|
1745 | - * @param EE_Ticket|null $ticket |
|
1746 | - * @param bool $show_trash |
|
1747 | - * @param bool $show_create |
|
1748 | - * @return mixed |
|
1749 | - * @throws InvalidArgumentException |
|
1750 | - * @throws InvalidInterfaceException |
|
1751 | - * @throws InvalidDataTypeException |
|
1752 | - * @throws DomainException |
|
1753 | - * @throws EE_Error |
|
1754 | - * @throws ReflectionException |
|
1755 | - */ |
|
1756 | - protected function _get_ticket_price_row( |
|
1757 | - $ticket_row, |
|
1758 | - $price_row, |
|
1759 | - $price, |
|
1760 | - $default, |
|
1761 | - $ticket, |
|
1762 | - $show_trash = true, |
|
1763 | - $show_create = true |
|
1764 | - ) { |
|
1765 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1766 | - $template_args = array( |
|
1767 | - 'tkt_row' => $default && empty($ticket) |
|
1768 | - ? 'TICKETNUM' |
|
1769 | - : $ticket_row, |
|
1770 | - 'PRC_order' => $default && empty($price) |
|
1771 | - ? 'PRICENUM' |
|
1772 | - : $price_row, |
|
1773 | - 'edit_prices_name' => $default && empty($price) |
|
1774 | - ? 'PRICENAMEATTR' |
|
1775 | - : 'edit_prices', |
|
1776 | - 'price_type_selector' => $default && empty($price) |
|
1777 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1778 | - : $this->_get_price_type_selector( |
|
1779 | - $ticket_row, |
|
1780 | - $price_row, |
|
1781 | - $price, |
|
1782 | - $default, |
|
1783 | - $send_disabled |
|
1784 | - ), |
|
1785 | - 'PRC_ID' => $default && empty($price) |
|
1786 | - ? 0 |
|
1787 | - : $price->ID(), |
|
1788 | - 'PRC_is_default' => $default && empty($price) |
|
1789 | - ? 0 |
|
1790 | - : $price->get('PRC_is_default'), |
|
1791 | - 'PRC_name' => $default && empty($price) |
|
1792 | - ? '' |
|
1793 | - : $price->get('PRC_name'), |
|
1794 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1795 | - 'show_plus_or_minus' => $default && empty($price) |
|
1796 | - ? '' |
|
1797 | - : ' style="display:none;"', |
|
1798 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1799 | - ? ' style="display:none;"' |
|
1800 | - : '', |
|
1801 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1802 | - ? ' style="display:none;"' |
|
1803 | - : '', |
|
1804 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1805 | - ? ' style="display:none"' |
|
1806 | - : '', |
|
1807 | - 'PRC_amount' => $default && empty($price) |
|
1808 | - ? 0 |
|
1809 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1810 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1811 | - ? ' style="display:none;"' |
|
1812 | - : '', |
|
1813 | - 'show_trash_icon' => $show_trash |
|
1814 | - ? '' |
|
1815 | - : ' style="display:none;"', |
|
1816 | - 'show_create_button' => $show_create |
|
1817 | - ? '' |
|
1818 | - : ' style="display:none;"', |
|
1819 | - 'PRC_desc' => $default && empty($price) |
|
1820 | - ? '' |
|
1821 | - : $price->get('PRC_desc'), |
|
1822 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1823 | - ); |
|
1824 | - $template_args = apply_filters( |
|
1825 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1826 | - $template_args, |
|
1827 | - $ticket_row, |
|
1828 | - $price_row, |
|
1829 | - $price, |
|
1830 | - $default, |
|
1831 | - $ticket, |
|
1832 | - $show_trash, |
|
1833 | - $show_create, |
|
1834 | - $this->_is_creating_event |
|
1835 | - ); |
|
1836 | - return EEH_Template::display_template( |
|
1837 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1838 | - $template_args, |
|
1839 | - true |
|
1840 | - ); |
|
1841 | - } |
|
1740 | + /** |
|
1741 | + * @param int $ticket_row |
|
1742 | + * @param int $price_row |
|
1743 | + * @param EE_Price|null $price |
|
1744 | + * @param bool $default |
|
1745 | + * @param EE_Ticket|null $ticket |
|
1746 | + * @param bool $show_trash |
|
1747 | + * @param bool $show_create |
|
1748 | + * @return mixed |
|
1749 | + * @throws InvalidArgumentException |
|
1750 | + * @throws InvalidInterfaceException |
|
1751 | + * @throws InvalidDataTypeException |
|
1752 | + * @throws DomainException |
|
1753 | + * @throws EE_Error |
|
1754 | + * @throws ReflectionException |
|
1755 | + */ |
|
1756 | + protected function _get_ticket_price_row( |
|
1757 | + $ticket_row, |
|
1758 | + $price_row, |
|
1759 | + $price, |
|
1760 | + $default, |
|
1761 | + $ticket, |
|
1762 | + $show_trash = true, |
|
1763 | + $show_create = true |
|
1764 | + ) { |
|
1765 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1766 | + $template_args = array( |
|
1767 | + 'tkt_row' => $default && empty($ticket) |
|
1768 | + ? 'TICKETNUM' |
|
1769 | + : $ticket_row, |
|
1770 | + 'PRC_order' => $default && empty($price) |
|
1771 | + ? 'PRICENUM' |
|
1772 | + : $price_row, |
|
1773 | + 'edit_prices_name' => $default && empty($price) |
|
1774 | + ? 'PRICENAMEATTR' |
|
1775 | + : 'edit_prices', |
|
1776 | + 'price_type_selector' => $default && empty($price) |
|
1777 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1778 | + : $this->_get_price_type_selector( |
|
1779 | + $ticket_row, |
|
1780 | + $price_row, |
|
1781 | + $price, |
|
1782 | + $default, |
|
1783 | + $send_disabled |
|
1784 | + ), |
|
1785 | + 'PRC_ID' => $default && empty($price) |
|
1786 | + ? 0 |
|
1787 | + : $price->ID(), |
|
1788 | + 'PRC_is_default' => $default && empty($price) |
|
1789 | + ? 0 |
|
1790 | + : $price->get('PRC_is_default'), |
|
1791 | + 'PRC_name' => $default && empty($price) |
|
1792 | + ? '' |
|
1793 | + : $price->get('PRC_name'), |
|
1794 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1795 | + 'show_plus_or_minus' => $default && empty($price) |
|
1796 | + ? '' |
|
1797 | + : ' style="display:none;"', |
|
1798 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1799 | + ? ' style="display:none;"' |
|
1800 | + : '', |
|
1801 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1802 | + ? ' style="display:none;"' |
|
1803 | + : '', |
|
1804 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1805 | + ? ' style="display:none"' |
|
1806 | + : '', |
|
1807 | + 'PRC_amount' => $default && empty($price) |
|
1808 | + ? 0 |
|
1809 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1810 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1811 | + ? ' style="display:none;"' |
|
1812 | + : '', |
|
1813 | + 'show_trash_icon' => $show_trash |
|
1814 | + ? '' |
|
1815 | + : ' style="display:none;"', |
|
1816 | + 'show_create_button' => $show_create |
|
1817 | + ? '' |
|
1818 | + : ' style="display:none;"', |
|
1819 | + 'PRC_desc' => $default && empty($price) |
|
1820 | + ? '' |
|
1821 | + : $price->get('PRC_desc'), |
|
1822 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1823 | + ); |
|
1824 | + $template_args = apply_filters( |
|
1825 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1826 | + $template_args, |
|
1827 | + $ticket_row, |
|
1828 | + $price_row, |
|
1829 | + $price, |
|
1830 | + $default, |
|
1831 | + $ticket, |
|
1832 | + $show_trash, |
|
1833 | + $show_create, |
|
1834 | + $this->_is_creating_event |
|
1835 | + ); |
|
1836 | + return EEH_Template::display_template( |
|
1837 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1838 | + $template_args, |
|
1839 | + true |
|
1840 | + ); |
|
1841 | + } |
|
1842 | 1842 | |
1843 | 1843 | |
1844 | - /** |
|
1845 | - * @param int $ticket_row |
|
1846 | - * @param int $price_row |
|
1847 | - * @param EE_Price $price |
|
1848 | - * @param bool $default |
|
1849 | - * @param bool $disabled |
|
1850 | - * @return mixed |
|
1851 | - * @throws ReflectionException |
|
1852 | - * @throws InvalidArgumentException |
|
1853 | - * @throws InvalidInterfaceException |
|
1854 | - * @throws InvalidDataTypeException |
|
1855 | - * @throws DomainException |
|
1856 | - * @throws EE_Error |
|
1857 | - */ |
|
1858 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1859 | - { |
|
1860 | - if ($price->is_base_price()) { |
|
1861 | - return $this->_get_base_price_template( |
|
1862 | - $ticket_row, |
|
1863 | - $price_row, |
|
1864 | - $price, |
|
1865 | - $default |
|
1866 | - ); |
|
1867 | - } |
|
1868 | - return $this->_get_price_modifier_template( |
|
1869 | - $ticket_row, |
|
1870 | - $price_row, |
|
1871 | - $price, |
|
1872 | - $default, |
|
1873 | - $disabled |
|
1874 | - ); |
|
1875 | - } |
|
1844 | + /** |
|
1845 | + * @param int $ticket_row |
|
1846 | + * @param int $price_row |
|
1847 | + * @param EE_Price $price |
|
1848 | + * @param bool $default |
|
1849 | + * @param bool $disabled |
|
1850 | + * @return mixed |
|
1851 | + * @throws ReflectionException |
|
1852 | + * @throws InvalidArgumentException |
|
1853 | + * @throws InvalidInterfaceException |
|
1854 | + * @throws InvalidDataTypeException |
|
1855 | + * @throws DomainException |
|
1856 | + * @throws EE_Error |
|
1857 | + */ |
|
1858 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1859 | + { |
|
1860 | + if ($price->is_base_price()) { |
|
1861 | + return $this->_get_base_price_template( |
|
1862 | + $ticket_row, |
|
1863 | + $price_row, |
|
1864 | + $price, |
|
1865 | + $default |
|
1866 | + ); |
|
1867 | + } |
|
1868 | + return $this->_get_price_modifier_template( |
|
1869 | + $ticket_row, |
|
1870 | + $price_row, |
|
1871 | + $price, |
|
1872 | + $default, |
|
1873 | + $disabled |
|
1874 | + ); |
|
1875 | + } |
|
1876 | 1876 | |
1877 | 1877 | |
1878 | - /** |
|
1879 | - * @param int $ticket_row |
|
1880 | - * @param int $price_row |
|
1881 | - * @param EE_Price $price |
|
1882 | - * @param bool $default |
|
1883 | - * @return mixed |
|
1884 | - * @throws DomainException |
|
1885 | - * @throws EE_Error |
|
1886 | - */ |
|
1887 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1888 | - { |
|
1889 | - $template_args = array( |
|
1890 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1891 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1892 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1893 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1894 | - 'price_selected_operator' => '+', |
|
1895 | - 'price_selected_is_percent' => 0, |
|
1896 | - ); |
|
1897 | - $template_args = apply_filters( |
|
1898 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1899 | - $template_args, |
|
1900 | - $ticket_row, |
|
1901 | - $price_row, |
|
1902 | - $price, |
|
1903 | - $default, |
|
1904 | - $this->_is_creating_event |
|
1905 | - ); |
|
1906 | - return EEH_Template::display_template( |
|
1907 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1908 | - $template_args, |
|
1909 | - true |
|
1910 | - ); |
|
1911 | - } |
|
1878 | + /** |
|
1879 | + * @param int $ticket_row |
|
1880 | + * @param int $price_row |
|
1881 | + * @param EE_Price $price |
|
1882 | + * @param bool $default |
|
1883 | + * @return mixed |
|
1884 | + * @throws DomainException |
|
1885 | + * @throws EE_Error |
|
1886 | + */ |
|
1887 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1888 | + { |
|
1889 | + $template_args = array( |
|
1890 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1891 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1892 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1893 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1894 | + 'price_selected_operator' => '+', |
|
1895 | + 'price_selected_is_percent' => 0, |
|
1896 | + ); |
|
1897 | + $template_args = apply_filters( |
|
1898 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1899 | + $template_args, |
|
1900 | + $ticket_row, |
|
1901 | + $price_row, |
|
1902 | + $price, |
|
1903 | + $default, |
|
1904 | + $this->_is_creating_event |
|
1905 | + ); |
|
1906 | + return EEH_Template::display_template( |
|
1907 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1908 | + $template_args, |
|
1909 | + true |
|
1910 | + ); |
|
1911 | + } |
|
1912 | 1912 | |
1913 | 1913 | |
1914 | - /** |
|
1915 | - * @param int $ticket_row |
|
1916 | - * @param int $price_row |
|
1917 | - * @param EE_Price $price |
|
1918 | - * @param bool $default |
|
1919 | - * @param bool $disabled |
|
1920 | - * @return mixed |
|
1921 | - * @throws ReflectionException |
|
1922 | - * @throws InvalidArgumentException |
|
1923 | - * @throws InvalidInterfaceException |
|
1924 | - * @throws InvalidDataTypeException |
|
1925 | - * @throws DomainException |
|
1926 | - * @throws EE_Error |
|
1927 | - */ |
|
1928 | - protected function _get_price_modifier_template( |
|
1929 | - $ticket_row, |
|
1930 | - $price_row, |
|
1931 | - $price, |
|
1932 | - $default, |
|
1933 | - $disabled = false |
|
1934 | - ) { |
|
1935 | - $select_name = $default && ! $price instanceof EE_Price |
|
1936 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1937 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1938 | - /** @var EEM_Price_Type $price_type_model */ |
|
1939 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1940 | - $price_types = $price_type_model->get_all(array( |
|
1941 | - array( |
|
1942 | - 'OR' => array( |
|
1943 | - 'PBT_ID' => '2', |
|
1944 | - 'PBT_ID*' => '3', |
|
1945 | - ), |
|
1946 | - ), |
|
1947 | - )); |
|
1948 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1949 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1950 | - : array(); |
|
1951 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1952 | - $price_option_spans = ''; |
|
1953 | - // setup price types for selector |
|
1954 | - foreach ($price_types as $price_type) { |
|
1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
1956 | - continue; |
|
1957 | - } |
|
1958 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1959 | - // while we're in the loop let's setup the option spans used by js |
|
1960 | - $span_args = array( |
|
1961 | - 'PRT_ID' => $price_type->ID(), |
|
1962 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1963 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1964 | - ); |
|
1965 | - $price_option_spans .= EEH_Template::display_template( |
|
1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1967 | - $span_args, |
|
1968 | - true |
|
1969 | - ); |
|
1970 | - } |
|
1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1972 | - : $select_name; |
|
1973 | - $select_input = new EE_Select_Input( |
|
1974 | - $all_price_types, |
|
1975 | - array( |
|
1976 | - 'default' => $selected_price_type_id, |
|
1977 | - 'html_name' => $select_name, |
|
1978 | - 'html_class' => 'edit-price-PRT_ID', |
|
1979 | - 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1980 | - ) |
|
1981 | - ); |
|
1982 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1983 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1984 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1985 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1986 | - $template_args = array( |
|
1987 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1988 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1989 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1990 | - 'main_name' => $select_name, |
|
1991 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1992 | - 'price_option_spans' => $price_option_spans, |
|
1993 | - 'price_selected_operator' => $price_selected_operator, |
|
1994 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1995 | - 'disabled' => $disabled, |
|
1996 | - ); |
|
1997 | - $template_args = apply_filters( |
|
1998 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1999 | - $template_args, |
|
2000 | - $ticket_row, |
|
2001 | - $price_row, |
|
2002 | - $price, |
|
2003 | - $default, |
|
2004 | - $disabled, |
|
2005 | - $this->_is_creating_event |
|
2006 | - ); |
|
2007 | - return EEH_Template::display_template( |
|
2008 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2009 | - $template_args, |
|
2010 | - true |
|
2011 | - ); |
|
2012 | - } |
|
1914 | + /** |
|
1915 | + * @param int $ticket_row |
|
1916 | + * @param int $price_row |
|
1917 | + * @param EE_Price $price |
|
1918 | + * @param bool $default |
|
1919 | + * @param bool $disabled |
|
1920 | + * @return mixed |
|
1921 | + * @throws ReflectionException |
|
1922 | + * @throws InvalidArgumentException |
|
1923 | + * @throws InvalidInterfaceException |
|
1924 | + * @throws InvalidDataTypeException |
|
1925 | + * @throws DomainException |
|
1926 | + * @throws EE_Error |
|
1927 | + */ |
|
1928 | + protected function _get_price_modifier_template( |
|
1929 | + $ticket_row, |
|
1930 | + $price_row, |
|
1931 | + $price, |
|
1932 | + $default, |
|
1933 | + $disabled = false |
|
1934 | + ) { |
|
1935 | + $select_name = $default && ! $price instanceof EE_Price |
|
1936 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1937 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1938 | + /** @var EEM_Price_Type $price_type_model */ |
|
1939 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1940 | + $price_types = $price_type_model->get_all(array( |
|
1941 | + array( |
|
1942 | + 'OR' => array( |
|
1943 | + 'PBT_ID' => '2', |
|
1944 | + 'PBT_ID*' => '3', |
|
1945 | + ), |
|
1946 | + ), |
|
1947 | + )); |
|
1948 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1949 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1950 | + : array(); |
|
1951 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1952 | + $price_option_spans = ''; |
|
1953 | + // setup price types for selector |
|
1954 | + foreach ($price_types as $price_type) { |
|
1955 | + if (! $price_type instanceof EE_Price_Type) { |
|
1956 | + continue; |
|
1957 | + } |
|
1958 | + $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1959 | + // while we're in the loop let's setup the option spans used by js |
|
1960 | + $span_args = array( |
|
1961 | + 'PRT_ID' => $price_type->ID(), |
|
1962 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1963 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1964 | + ); |
|
1965 | + $price_option_spans .= EEH_Template::display_template( |
|
1966 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1967 | + $span_args, |
|
1968 | + true |
|
1969 | + ); |
|
1970 | + } |
|
1971 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1972 | + : $select_name; |
|
1973 | + $select_input = new EE_Select_Input( |
|
1974 | + $all_price_types, |
|
1975 | + array( |
|
1976 | + 'default' => $selected_price_type_id, |
|
1977 | + 'html_name' => $select_name, |
|
1978 | + 'html_class' => 'edit-price-PRT_ID', |
|
1979 | + 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1980 | + ) |
|
1981 | + ); |
|
1982 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1983 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1984 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1985 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1986 | + $template_args = array( |
|
1987 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1988 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1989 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1990 | + 'main_name' => $select_name, |
|
1991 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1992 | + 'price_option_spans' => $price_option_spans, |
|
1993 | + 'price_selected_operator' => $price_selected_operator, |
|
1994 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1995 | + 'disabled' => $disabled, |
|
1996 | + ); |
|
1997 | + $template_args = apply_filters( |
|
1998 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1999 | + $template_args, |
|
2000 | + $ticket_row, |
|
2001 | + $price_row, |
|
2002 | + $price, |
|
2003 | + $default, |
|
2004 | + $disabled, |
|
2005 | + $this->_is_creating_event |
|
2006 | + ); |
|
2007 | + return EEH_Template::display_template( |
|
2008 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2009 | + $template_args, |
|
2010 | + true |
|
2011 | + ); |
|
2012 | + } |
|
2013 | 2013 | |
2014 | 2014 | |
2015 | - /** |
|
2016 | - * @param int $datetime_row |
|
2017 | - * @param int $ticket_row |
|
2018 | - * @param EE_Datetime|null $datetime |
|
2019 | - * @param EE_Ticket|null $ticket |
|
2020 | - * @param array $ticket_datetimes |
|
2021 | - * @param bool $default |
|
2022 | - * @return mixed |
|
2023 | - * @throws DomainException |
|
2024 | - * @throws EE_Error |
|
2025 | - */ |
|
2026 | - protected function _get_ticket_datetime_list_item( |
|
2027 | - $datetime_row, |
|
2028 | - $ticket_row, |
|
2029 | - $datetime, |
|
2030 | - $ticket, |
|
2031 | - $ticket_datetimes = array(), |
|
2032 | - $default |
|
2033 | - ) { |
|
2034 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2035 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
2036 | - : array(); |
|
2037 | - $template_args = array( |
|
2038 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2039 | - ? 'DTTNUM' |
|
2040 | - : $datetime_row, |
|
2041 | - 'tkt_row' => $default |
|
2042 | - ? 'TICKETNUM' |
|
2043 | - : $ticket_row, |
|
2044 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2045 | - ? ' ticket-selected' |
|
2046 | - : '', |
|
2047 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2048 | - ? ' checked="checked"' |
|
2049 | - : '', |
|
2050 | - 'DTT_name' => $default && empty($datetime) |
|
2051 | - ? 'DTTNAME' |
|
2052 | - : $datetime->get_dtt_display_name(true), |
|
2053 | - 'tkt_status_class' => '', |
|
2054 | - ); |
|
2055 | - $template_args = apply_filters( |
|
2056 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2057 | - $template_args, |
|
2058 | - $datetime_row, |
|
2059 | - $ticket_row, |
|
2060 | - $datetime, |
|
2061 | - $ticket, |
|
2062 | - $ticket_datetimes, |
|
2063 | - $default, |
|
2064 | - $this->_is_creating_event |
|
2065 | - ); |
|
2066 | - return EEH_Template::display_template( |
|
2067 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2068 | - $template_args, |
|
2069 | - true |
|
2070 | - ); |
|
2071 | - } |
|
2015 | + /** |
|
2016 | + * @param int $datetime_row |
|
2017 | + * @param int $ticket_row |
|
2018 | + * @param EE_Datetime|null $datetime |
|
2019 | + * @param EE_Ticket|null $ticket |
|
2020 | + * @param array $ticket_datetimes |
|
2021 | + * @param bool $default |
|
2022 | + * @return mixed |
|
2023 | + * @throws DomainException |
|
2024 | + * @throws EE_Error |
|
2025 | + */ |
|
2026 | + protected function _get_ticket_datetime_list_item( |
|
2027 | + $datetime_row, |
|
2028 | + $ticket_row, |
|
2029 | + $datetime, |
|
2030 | + $ticket, |
|
2031 | + $ticket_datetimes = array(), |
|
2032 | + $default |
|
2033 | + ) { |
|
2034 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2035 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
2036 | + : array(); |
|
2037 | + $template_args = array( |
|
2038 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2039 | + ? 'DTTNUM' |
|
2040 | + : $datetime_row, |
|
2041 | + 'tkt_row' => $default |
|
2042 | + ? 'TICKETNUM' |
|
2043 | + : $ticket_row, |
|
2044 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2045 | + ? ' ticket-selected' |
|
2046 | + : '', |
|
2047 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2048 | + ? ' checked="checked"' |
|
2049 | + : '', |
|
2050 | + 'DTT_name' => $default && empty($datetime) |
|
2051 | + ? 'DTTNAME' |
|
2052 | + : $datetime->get_dtt_display_name(true), |
|
2053 | + 'tkt_status_class' => '', |
|
2054 | + ); |
|
2055 | + $template_args = apply_filters( |
|
2056 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2057 | + $template_args, |
|
2058 | + $datetime_row, |
|
2059 | + $ticket_row, |
|
2060 | + $datetime, |
|
2061 | + $ticket, |
|
2062 | + $ticket_datetimes, |
|
2063 | + $default, |
|
2064 | + $this->_is_creating_event |
|
2065 | + ); |
|
2066 | + return EEH_Template::display_template( |
|
2067 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2068 | + $template_args, |
|
2069 | + true |
|
2070 | + ); |
|
2071 | + } |
|
2072 | 2072 | |
2073 | 2073 | |
2074 | - /** |
|
2075 | - * @param array $all_datetimes |
|
2076 | - * @param array $all_tickets |
|
2077 | - * @return mixed |
|
2078 | - * @throws ReflectionException |
|
2079 | - * @throws InvalidArgumentException |
|
2080 | - * @throws InvalidInterfaceException |
|
2081 | - * @throws InvalidDataTypeException |
|
2082 | - * @throws DomainException |
|
2083 | - * @throws EE_Error |
|
2084 | - */ |
|
2085 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2086 | - { |
|
2087 | - $template_args = array( |
|
2088 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2089 | - 'DTTNUM', |
|
2090 | - null, |
|
2091 | - true, |
|
2092 | - $all_datetimes |
|
2093 | - ), |
|
2094 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2095 | - 'TICKETNUM', |
|
2096 | - null, |
|
2097 | - array(), |
|
2098 | - array(), |
|
2099 | - true |
|
2100 | - ), |
|
2101 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2102 | - 'TICKETNUM', |
|
2103 | - 'PRICENUM', |
|
2104 | - null, |
|
2105 | - true, |
|
2106 | - null |
|
2107 | - ), |
|
2108 | - 'default_price_rows' => '', |
|
2109 | - 'default_base_price_amount' => 0, |
|
2110 | - 'default_base_price_name' => '', |
|
2111 | - 'default_base_price_description' => '', |
|
2112 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2113 | - 'TICKETNUM', |
|
2114 | - 'PRICENUM', |
|
2115 | - null, |
|
2116 | - true |
|
2117 | - ), |
|
2118 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2119 | - 'DTTNUM', |
|
2120 | - null, |
|
2121 | - array(), |
|
2122 | - array(), |
|
2123 | - true |
|
2124 | - ), |
|
2125 | - 'existing_available_datetime_tickets_list' => '', |
|
2126 | - 'existing_available_ticket_datetimes_list' => '', |
|
2127 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2128 | - 'DTTNUM', |
|
2129 | - 'TICKETNUM', |
|
2130 | - null, |
|
2131 | - null, |
|
2132 | - array(), |
|
2133 | - true |
|
2134 | - ), |
|
2135 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2136 | - 'DTTNUM', |
|
2137 | - 'TICKETNUM', |
|
2138 | - null, |
|
2139 | - null, |
|
2140 | - array(), |
|
2141 | - true |
|
2142 | - ), |
|
2143 | - ); |
|
2144 | - $ticket_row = 1; |
|
2145 | - foreach ($all_tickets as $ticket) { |
|
2146 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2147 | - 'DTTNUM', |
|
2148 | - $ticket_row, |
|
2149 | - null, |
|
2150 | - $ticket, |
|
2151 | - array(), |
|
2152 | - true |
|
2153 | - ); |
|
2154 | - $ticket_row++; |
|
2155 | - } |
|
2156 | - $datetime_row = 1; |
|
2157 | - foreach ($all_datetimes as $datetime) { |
|
2158 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2159 | - $datetime_row, |
|
2160 | - 'TICKETNUM', |
|
2161 | - $datetime, |
|
2162 | - null, |
|
2163 | - array(), |
|
2164 | - true |
|
2165 | - ); |
|
2166 | - $datetime_row++; |
|
2167 | - } |
|
2168 | - /** @var EEM_Price $price_model */ |
|
2169 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2170 | - $default_prices = $price_model->get_all_default_prices(); |
|
2171 | - $price_row = 1; |
|
2172 | - foreach ($default_prices as $price) { |
|
2173 | - if (! $price instanceof EE_Price) { |
|
2174 | - continue; |
|
2175 | - } |
|
2176 | - if ($price->is_base_price()) { |
|
2177 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2178 | - 'PRC_amount', |
|
2179 | - 'localized_float' |
|
2180 | - ); |
|
2181 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2182 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2183 | - $price_row++; |
|
2184 | - continue; |
|
2185 | - } |
|
2186 | - $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2187 | - || count($default_prices) === 1); |
|
2188 | - $show_create = ! (count($default_prices) > 1 |
|
2189 | - && count($default_prices) |
|
2190 | - !== $price_row); |
|
2191 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2192 | - 'TICKETNUM', |
|
2193 | - $price_row, |
|
2194 | - $price, |
|
2195 | - true, |
|
2196 | - null, |
|
2197 | - $show_trash, |
|
2198 | - $show_create |
|
2199 | - ); |
|
2200 | - $price_row++; |
|
2201 | - } |
|
2202 | - $template_args = apply_filters( |
|
2203 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2204 | - $template_args, |
|
2205 | - $all_datetimes, |
|
2206 | - $all_tickets, |
|
2207 | - $this->_is_creating_event |
|
2208 | - ); |
|
2209 | - return EEH_Template::display_template( |
|
2210 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2211 | - $template_args, |
|
2212 | - true |
|
2213 | - ); |
|
2214 | - } |
|
2074 | + /** |
|
2075 | + * @param array $all_datetimes |
|
2076 | + * @param array $all_tickets |
|
2077 | + * @return mixed |
|
2078 | + * @throws ReflectionException |
|
2079 | + * @throws InvalidArgumentException |
|
2080 | + * @throws InvalidInterfaceException |
|
2081 | + * @throws InvalidDataTypeException |
|
2082 | + * @throws DomainException |
|
2083 | + * @throws EE_Error |
|
2084 | + */ |
|
2085 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2086 | + { |
|
2087 | + $template_args = array( |
|
2088 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2089 | + 'DTTNUM', |
|
2090 | + null, |
|
2091 | + true, |
|
2092 | + $all_datetimes |
|
2093 | + ), |
|
2094 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2095 | + 'TICKETNUM', |
|
2096 | + null, |
|
2097 | + array(), |
|
2098 | + array(), |
|
2099 | + true |
|
2100 | + ), |
|
2101 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2102 | + 'TICKETNUM', |
|
2103 | + 'PRICENUM', |
|
2104 | + null, |
|
2105 | + true, |
|
2106 | + null |
|
2107 | + ), |
|
2108 | + 'default_price_rows' => '', |
|
2109 | + 'default_base_price_amount' => 0, |
|
2110 | + 'default_base_price_name' => '', |
|
2111 | + 'default_base_price_description' => '', |
|
2112 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2113 | + 'TICKETNUM', |
|
2114 | + 'PRICENUM', |
|
2115 | + null, |
|
2116 | + true |
|
2117 | + ), |
|
2118 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2119 | + 'DTTNUM', |
|
2120 | + null, |
|
2121 | + array(), |
|
2122 | + array(), |
|
2123 | + true |
|
2124 | + ), |
|
2125 | + 'existing_available_datetime_tickets_list' => '', |
|
2126 | + 'existing_available_ticket_datetimes_list' => '', |
|
2127 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2128 | + 'DTTNUM', |
|
2129 | + 'TICKETNUM', |
|
2130 | + null, |
|
2131 | + null, |
|
2132 | + array(), |
|
2133 | + true |
|
2134 | + ), |
|
2135 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2136 | + 'DTTNUM', |
|
2137 | + 'TICKETNUM', |
|
2138 | + null, |
|
2139 | + null, |
|
2140 | + array(), |
|
2141 | + true |
|
2142 | + ), |
|
2143 | + ); |
|
2144 | + $ticket_row = 1; |
|
2145 | + foreach ($all_tickets as $ticket) { |
|
2146 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2147 | + 'DTTNUM', |
|
2148 | + $ticket_row, |
|
2149 | + null, |
|
2150 | + $ticket, |
|
2151 | + array(), |
|
2152 | + true |
|
2153 | + ); |
|
2154 | + $ticket_row++; |
|
2155 | + } |
|
2156 | + $datetime_row = 1; |
|
2157 | + foreach ($all_datetimes as $datetime) { |
|
2158 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2159 | + $datetime_row, |
|
2160 | + 'TICKETNUM', |
|
2161 | + $datetime, |
|
2162 | + null, |
|
2163 | + array(), |
|
2164 | + true |
|
2165 | + ); |
|
2166 | + $datetime_row++; |
|
2167 | + } |
|
2168 | + /** @var EEM_Price $price_model */ |
|
2169 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2170 | + $default_prices = $price_model->get_all_default_prices(); |
|
2171 | + $price_row = 1; |
|
2172 | + foreach ($default_prices as $price) { |
|
2173 | + if (! $price instanceof EE_Price) { |
|
2174 | + continue; |
|
2175 | + } |
|
2176 | + if ($price->is_base_price()) { |
|
2177 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2178 | + 'PRC_amount', |
|
2179 | + 'localized_float' |
|
2180 | + ); |
|
2181 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2182 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2183 | + $price_row++; |
|
2184 | + continue; |
|
2185 | + } |
|
2186 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2187 | + || count($default_prices) === 1); |
|
2188 | + $show_create = ! (count($default_prices) > 1 |
|
2189 | + && count($default_prices) |
|
2190 | + !== $price_row); |
|
2191 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2192 | + 'TICKETNUM', |
|
2193 | + $price_row, |
|
2194 | + $price, |
|
2195 | + true, |
|
2196 | + null, |
|
2197 | + $show_trash, |
|
2198 | + $show_create |
|
2199 | + ); |
|
2200 | + $price_row++; |
|
2201 | + } |
|
2202 | + $template_args = apply_filters( |
|
2203 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2204 | + $template_args, |
|
2205 | + $all_datetimes, |
|
2206 | + $all_tickets, |
|
2207 | + $this->_is_creating_event |
|
2208 | + ); |
|
2209 | + return EEH_Template::display_template( |
|
2210 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2211 | + $template_args, |
|
2212 | + true |
|
2213 | + ); |
|
2214 | + } |
|
2215 | 2215 | } |