@@ -12,15 +12,15 @@ |
||
12 | 12 | class Extend_Events_Admin_List_Table extends Events_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - protected function _column_name_action_setup(EE_Event $item) |
|
16 | - { |
|
17 | - $export_query_args = array( |
|
18 | - 'action' => 'export_events', |
|
19 | - 'EVT_ID' => $item->ID(), |
|
20 | - ); |
|
21 | - $export_event_link = EE_Admin_Page::add_query_args_and_nonce($export_query_args, EVENTS_ADMIN_URL); |
|
15 | + protected function _column_name_action_setup(EE_Event $item) |
|
16 | + { |
|
17 | + $export_query_args = array( |
|
18 | + 'action' => 'export_events', |
|
19 | + 'EVT_ID' => $item->ID(), |
|
20 | + ); |
|
21 | + $export_event_link = EE_Admin_Page::add_query_args_and_nonce($export_query_args, EVENTS_ADMIN_URL); |
|
22 | 22 | |
23 | - $actions = parent::_column_name_action_setup($item); |
|
24 | - return $actions; |
|
25 | - } |
|
23 | + $actions = parent::_column_name_action_setup($item); |
|
24 | + return $actions; |
|
25 | + } |
|
26 | 26 | } |
@@ -15,17 +15,17 @@ |
||
15 | 15 | class Extend_EE_Attendee_Contact_List_Table extends EE_Attendee_Contact_List_Table |
16 | 16 | { |
17 | 17 | |
18 | - protected function _set_properties() |
|
19 | - { |
|
20 | - parent::_set_properties(); |
|
21 | - $this->_bottom_buttons = array( |
|
22 | - 'contact_list_report' => array( |
|
23 | - 'route' => 'contact_list_report', |
|
24 | - 'extra_request' => |
|
25 | - array( |
|
26 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
27 | - ), |
|
28 | - ), |
|
29 | - ); |
|
30 | - } |
|
18 | + protected function _set_properties() |
|
19 | + { |
|
20 | + parent::_set_properties(); |
|
21 | + $this->_bottom_buttons = array( |
|
22 | + 'contact_list_report' => array( |
|
23 | + 'route' => 'contact_list_report', |
|
24 | + 'extra_request' => |
|
25 | + array( |
|
26 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
27 | + ), |
|
28 | + ), |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | } |
@@ -13,115 +13,115 @@ |
||
13 | 13 | class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param EE_Registration $item |
|
18 | - * @return string |
|
19 | - * @throws EE_Error |
|
20 | - * @throws InvalidArgumentException |
|
21 | - * @throws ReflectionException |
|
22 | - * @throws InvalidDataTypeException |
|
23 | - * @throws InvalidInterfaceException |
|
24 | - */ |
|
25 | - public function column__REG_date(EE_Registration $item) |
|
26 | - { |
|
27 | - $date_linked = parent::column__REG_date($item); |
|
28 | - $actions = array(); |
|
29 | - // Build row actions |
|
30 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
31 | - 'action' => 'event_registrations', |
|
32 | - 'event_id' => $item->event_ID(), |
|
33 | - ), REG_ADMIN_URL); |
|
34 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
35 | - 'ee_read_registration', |
|
36 | - 'espresso_registrations_registration_checkins', |
|
37 | - $item->ID() |
|
38 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
39 | - 'ee_read_checkins', |
|
40 | - 'espresso_registrations_registration_checkins' |
|
41 | - ) |
|
42 | - ? '<a href="' . $check_in_url . '"' |
|
43 | - . ' title="' . esc_attr__( |
|
44 | - 'The Check-In List allows you to easily toggle check-in status for this event', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
48 | - : esc_html__('View Check-ins', 'event_espresso'); |
|
16 | + /** |
|
17 | + * @param EE_Registration $item |
|
18 | + * @return string |
|
19 | + * @throws EE_Error |
|
20 | + * @throws InvalidArgumentException |
|
21 | + * @throws ReflectionException |
|
22 | + * @throws InvalidDataTypeException |
|
23 | + * @throws InvalidInterfaceException |
|
24 | + */ |
|
25 | + public function column__REG_date(EE_Registration $item) |
|
26 | + { |
|
27 | + $date_linked = parent::column__REG_date($item); |
|
28 | + $actions = array(); |
|
29 | + // Build row actions |
|
30 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
31 | + 'action' => 'event_registrations', |
|
32 | + 'event_id' => $item->event_ID(), |
|
33 | + ), REG_ADMIN_URL); |
|
34 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
35 | + 'ee_read_registration', |
|
36 | + 'espresso_registrations_registration_checkins', |
|
37 | + $item->ID() |
|
38 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
39 | + 'ee_read_checkins', |
|
40 | + 'espresso_registrations_registration_checkins' |
|
41 | + ) |
|
42 | + ? '<a href="' . $check_in_url . '"' |
|
43 | + . ' title="' . esc_attr__( |
|
44 | + 'The Check-In List allows you to easily toggle check-in status for this event', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
48 | + : esc_html__('View Check-ins', 'event_espresso'); |
|
49 | 49 | |
50 | - return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
51 | - } |
|
50 | + return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * column_default |
|
56 | - * |
|
57 | - * @param \EE_Registration $item |
|
58 | - * @return string |
|
59 | - * @throws EE_Error |
|
60 | - * @throws InvalidArgumentException |
|
61 | - * @throws InvalidDataTypeException |
|
62 | - * @throws InvalidInterfaceException |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | - { |
|
67 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | - $ticket = $item->ticket(); |
|
69 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | - $EVT_ID = $item->event_ID(); |
|
71 | - $datetimes_for_display = array(); |
|
72 | - foreach ($datetimes as $datetime) { |
|
73 | - $datetime_string = ''; |
|
74 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
75 | - 'ee_read_checkin', |
|
76 | - 'espresso_registrations_registration_checkins', |
|
77 | - $item->ID() |
|
78 | - )) { |
|
79 | - // open "a" tag and "href" |
|
80 | - $datetime_string .= '<a href="'; |
|
81 | - // checkin URL |
|
82 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
83 | - array( |
|
84 | - 'action' => 'event_registrations', |
|
85 | - 'event_id' => $EVT_ID, |
|
86 | - 'DTT_ID' => $datetime->ID(), |
|
87 | - ), |
|
88 | - REG_ADMIN_URL |
|
89 | - ); |
|
90 | - // close "href" |
|
91 | - $datetime_string .= '"'; |
|
92 | - // open "title" tag |
|
93 | - $datetime_string .= ' title="'; |
|
94 | - // link title text |
|
95 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
96 | - // close "title" tag and end of "a" tag opening |
|
97 | - $datetime_string .= '">'; |
|
98 | - // link text |
|
99 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
100 | - // close "a" tag |
|
101 | - $datetime_string .= '</a>'; |
|
102 | - } else { |
|
103 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
104 | - } |
|
105 | - // add a "View Registrations" link that filters list by event AND datetime |
|
106 | - $datetime_string .= $this->row_actions( |
|
107 | - array( |
|
108 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
109 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
110 | - REG_ADMIN_URL |
|
111 | - ) |
|
112 | - . '" title="' . sprintf( |
|
113 | - esc_attr__( |
|
114 | - 'Filter this list to only show registrations for this datetime %s', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $datetime->name() |
|
118 | - ) . '">' |
|
119 | - . esc_html__('View Registrations', 'event_espresso') |
|
120 | - . '</a>', |
|
121 | - ) |
|
122 | - ); |
|
123 | - $datetimes_for_display[] = $datetime_string; |
|
124 | - } |
|
125 | - return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
126 | - } |
|
54 | + /** |
|
55 | + * column_default |
|
56 | + * |
|
57 | + * @param \EE_Registration $item |
|
58 | + * @return string |
|
59 | + * @throws EE_Error |
|
60 | + * @throws InvalidArgumentException |
|
61 | + * @throws InvalidDataTypeException |
|
62 | + * @throws InvalidInterfaceException |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | + { |
|
67 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | + $ticket = $item->ticket(); |
|
69 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | + $EVT_ID = $item->event_ID(); |
|
71 | + $datetimes_for_display = array(); |
|
72 | + foreach ($datetimes as $datetime) { |
|
73 | + $datetime_string = ''; |
|
74 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
75 | + 'ee_read_checkin', |
|
76 | + 'espresso_registrations_registration_checkins', |
|
77 | + $item->ID() |
|
78 | + )) { |
|
79 | + // open "a" tag and "href" |
|
80 | + $datetime_string .= '<a href="'; |
|
81 | + // checkin URL |
|
82 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
83 | + array( |
|
84 | + 'action' => 'event_registrations', |
|
85 | + 'event_id' => $EVT_ID, |
|
86 | + 'DTT_ID' => $datetime->ID(), |
|
87 | + ), |
|
88 | + REG_ADMIN_URL |
|
89 | + ); |
|
90 | + // close "href" |
|
91 | + $datetime_string .= '"'; |
|
92 | + // open "title" tag |
|
93 | + $datetime_string .= ' title="'; |
|
94 | + // link title text |
|
95 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
96 | + // close "title" tag and end of "a" tag opening |
|
97 | + $datetime_string .= '">'; |
|
98 | + // link text |
|
99 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
100 | + // close "a" tag |
|
101 | + $datetime_string .= '</a>'; |
|
102 | + } else { |
|
103 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
104 | + } |
|
105 | + // add a "View Registrations" link that filters list by event AND datetime |
|
106 | + $datetime_string .= $this->row_actions( |
|
107 | + array( |
|
108 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
109 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
110 | + REG_ADMIN_URL |
|
111 | + ) |
|
112 | + . '" title="' . sprintf( |
|
113 | + esc_attr__( |
|
114 | + 'Filter this list to only show registrations for this datetime %s', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $datetime->name() |
|
118 | + ) . '">' |
|
119 | + . esc_html__('View Registrations', 'event_espresso') |
|
120 | + . '</a>', |
|
121 | + ) |
|
122 | + ); |
|
123 | + $datetimes_for_display[] = $datetime_string; |
|
124 | + } |
|
125 | + return $this->generateDisplayForDateTimes($datetimes_for_display); |
|
126 | + } |
|
127 | 127 | } |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | 'ee_read_checkins', |
40 | 40 | 'espresso_registrations_registration_checkins' |
41 | 41 | ) |
42 | - ? '<a href="' . $check_in_url . '"' |
|
43 | - . ' title="' . esc_attr__( |
|
42 | + ? '<a href="'.$check_in_url.'"' |
|
43 | + . ' title="'.esc_attr__( |
|
44 | 44 | 'The Check-In List allows you to easily toggle check-in status for this event', |
45 | 45 | 'event_espresso' |
46 | 46 | ) |
47 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
47 | + . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>' |
|
48 | 48 | : esc_html__('View Check-ins', 'event_espresso'); |
49 | 49 | |
50 | 50 | return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
@@ -105,17 +105,17 @@ discard block |
||
105 | 105 | // add a "View Registrations" link that filters list by event AND datetime |
106 | 106 | $datetime_string .= $this->row_actions( |
107 | 107 | array( |
108 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
108 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
109 | 109 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
110 | 110 | REG_ADMIN_URL |
111 | 111 | ) |
112 | - . '" title="' . sprintf( |
|
112 | + . '" title="'.sprintf( |
|
113 | 113 | esc_attr__( |
114 | 114 | 'Filter this list to only show registrations for this datetime %s', |
115 | 115 | 'event_espresso' |
116 | 116 | ), |
117 | 117 | $datetime->name() |
118 | - ) . '">' |
|
118 | + ).'">' |
|
119 | 119 | . esc_html__('View Registrations', 'event_espresso') |
120 | 120 | . '</a>', |
121 | 121 | ) |
@@ -12,562 +12,562 @@ |
||
12 | 12 | class EE_Event_Registrations_List_Table extends EE_Admin_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
17 | - * |
|
18 | - * @var EE_Datetime[] |
|
19 | - */ |
|
20 | - protected $_dtts_for_event = array(); |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * The event if one is specified in the request |
|
25 | - * |
|
26 | - * @var EE_Event |
|
27 | - */ |
|
28 | - protected $_evt = null; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * The DTT_ID if the current view has a specified datetime. |
|
33 | - * |
|
34 | - * @var int $_cur_dtt_id |
|
35 | - */ |
|
36 | - protected $_cur_dtt_id = 0; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EE_Event_Registrations_List_Table constructor. |
|
41 | - * |
|
42 | - * @param \Registrations_Admin_Page $admin_page |
|
43 | - */ |
|
44 | - public function __construct($admin_page) |
|
45 | - { |
|
46 | - parent::__construct($admin_page); |
|
47 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - protected function _setup_data() |
|
52 | - { |
|
53 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
54 | - : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
55 | - $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
56 | - $this->_per_page, |
|
57 | - true |
|
58 | - ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - protected function _set_properties() |
|
63 | - { |
|
64 | - $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
65 | - $this->_wp_list_args = array( |
|
66 | - 'singular' => __('registrant', 'event_espresso'), |
|
67 | - 'plural' => __('registrants', 'event_espresso'), |
|
68 | - 'ajax' => true, |
|
69 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
70 | - ); |
|
71 | - $columns = array(); |
|
72 | - // $columns['_Reg_Status'] = ''; |
|
73 | - if (! empty($evt_id)) { |
|
74 | - $columns['cb'] = '<input type="checkbox" />'; // Render a checkbox instead of text |
|
75 | - $this->_has_checkbox_column = true; |
|
76 | - } |
|
77 | - $this->_columns = array( |
|
78 | - '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
|
79 | - 'ATT_name' => __('Registrant', 'event_espresso'), |
|
80 | - 'ATT_email' => __('Email Address', 'event_espresso'), |
|
81 | - 'Event' => __('Event', 'event_espresso'), |
|
82 | - 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
83 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
84 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
85 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
86 | - ); |
|
87 | - $this->_columns = array_merge($columns, $this->_columns); |
|
88 | - $this->_primary_column = '_REG_att_checked_in'; |
|
89 | - if (! empty($evt_id) |
|
90 | - && EE_Registry::instance()->CAP->current_user_can( |
|
91 | - 'ee_read_registrations', |
|
92 | - 'espresso_registrations_registrations_reports', |
|
93 | - $evt_id |
|
94 | - ) |
|
95 | - ) { |
|
96 | - $this->_bottom_buttons = array( |
|
97 | - 'report' => array( |
|
98 | - 'route' => 'registrations_report', |
|
99 | - 'extra_request' => |
|
100 | - array( |
|
101 | - 'EVT_ID' => $evt_id, |
|
102 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
103 | - ), |
|
104 | - ), |
|
105 | - ); |
|
106 | - } |
|
107 | - $this->_bottom_buttons['report_filtered'] = array( |
|
108 | - 'route' => 'registrations_checkin_report', |
|
109 | - 'extra_request' => array( |
|
110 | - 'use_filters' => true, |
|
111 | - 'filters' => array_merge( |
|
112 | - array( |
|
113 | - 'EVT_ID' => $evt_id, |
|
114 | - ), |
|
115 | - array_diff_key( |
|
116 | - $this->_req_data, |
|
117 | - array_flip( |
|
118 | - array( |
|
119 | - 'page', |
|
120 | - 'action', |
|
121 | - 'default_nonce', |
|
122 | - ) |
|
123 | - ) |
|
124 | - ) |
|
125 | - ), |
|
126 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
127 | - ), |
|
128 | - ); |
|
129 | - $this->_sortable_columns = array( |
|
130 | - /** |
|
131 | - * Allows users to change the default sort if they wish. |
|
132 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
133 | - * |
|
134 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
135 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
136 | - * for a specific list table you can use the provided reference to this object instance. |
|
137 | - */ |
|
138 | - 'ATT_name' => array( |
|
139 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
140 | - true, |
|
141 | - $this, |
|
142 | - ) |
|
143 | - ? array('ATT_lname' => true) |
|
144 | - : array('ATT_fname' => true), |
|
145 | - 'Event' => array('Event.EVT.Name' => false), |
|
146 | - ); |
|
147 | - $this->_hidden_columns = array(); |
|
148 | - $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
149 | - $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param \EE_Registration $item |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - protected function _get_row_class($item) |
|
158 | - { |
|
159 | - $class = parent::_get_row_class($item); |
|
160 | - // add status class |
|
161 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
162 | - if ($this->_has_checkbox_column) { |
|
163 | - $class .= ' has-checkbox-column'; |
|
164 | - } |
|
165 | - return $class; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return array |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - protected function _get_table_filters() |
|
174 | - { |
|
175 | - $filters = $where = array(); |
|
176 | - $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
177 | - if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
178 | - // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
179 | - // note possible capability restrictions |
|
180 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
181 | - $where['status**'] = array('!=', 'private'); |
|
182 | - } |
|
183 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
184 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
185 | - } |
|
186 | - $events = EEM_Event::instance()->get_all( |
|
187 | - array( |
|
188 | - $where, |
|
189 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
190 | - ) |
|
191 | - ); |
|
192 | - $evts[] = array( |
|
193 | - 'id' => 0, |
|
194 | - 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
195 | - ); |
|
196 | - $checked = 'checked'; |
|
197 | - /** @var EE_Event $evt */ |
|
198 | - foreach ($events as $evt) { |
|
199 | - // any registrations for this event? |
|
200 | - if (! $evt->get_count_of_all_registrations()) { |
|
201 | - continue; |
|
202 | - } |
|
203 | - $evts[] = array( |
|
204 | - 'id' => $evt->ID(), |
|
205 | - 'text' => apply_filters( |
|
206 | - 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
207 | - $evt->get('EVT_name'), |
|
208 | - $evt |
|
209 | - ), |
|
210 | - 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
211 | - ); |
|
212 | - if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
213 | - $checked = ''; |
|
214 | - } |
|
215 | - } |
|
216 | - $event_filter = '<div class="ee-event-filter">'; |
|
217 | - $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
218 | - $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
219 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
220 | - $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
221 | - $event_filter .= '</span>'; |
|
222 | - $event_filter .= '</div>'; |
|
223 | - $filters[] = $event_filter; |
|
224 | - } |
|
225 | - if (! empty($this->_dtts_for_event)) { |
|
226 | - // DTT datetimes filter |
|
227 | - $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
228 | - if (count($this->_dtts_for_event) > 1) { |
|
229 | - $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
230 | - foreach ($this->_dtts_for_event as $dtt) { |
|
231 | - $datetime_string = $dtt->name(); |
|
232 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
233 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
234 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
235 | - } |
|
236 | - $input = new EE_Select_Input( |
|
237 | - $dtts, |
|
238 | - array( |
|
239 | - 'html_name' => 'DTT_ID', |
|
240 | - 'html_id' => 'DTT_ID', |
|
241 | - 'default' => $this->_cur_dtt_id, |
|
242 | - ) |
|
243 | - ); |
|
244 | - $filters[] = $input->get_html_for_input(); |
|
245 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
246 | - } |
|
247 | - } |
|
248 | - return $filters; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - protected function _add_view_counts() |
|
253 | - { |
|
254 | - $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * @return int |
|
260 | - * @throws \EE_Error |
|
261 | - */ |
|
262 | - protected function _get_total_event_attendees() |
|
263 | - { |
|
264 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
265 | - $DTT_ID = $this->_cur_dtt_id; |
|
266 | - $query_params = array(); |
|
267 | - if ($EVT_ID) { |
|
268 | - $query_params[0]['EVT_ID'] = $EVT_ID; |
|
269 | - } |
|
270 | - // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
271 | - if ($DTT_ID) { |
|
272 | - $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
273 | - } |
|
274 | - $status_ids_array = apply_filters( |
|
275 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
276 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
277 | - ); |
|
278 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
279 | - return EEM_Registration::instance()->count($query_params); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param \EE_Registration $item |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function column__Reg_Status(EE_Registration $item) |
|
288 | - { |
|
289 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param \EE_Registration $item |
|
295 | - * @return string |
|
296 | - * @throws \EE_Error |
|
297 | - */ |
|
298 | - public function column_cb($item) |
|
299 | - { |
|
300 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * column_REG_att_checked_in |
|
306 | - * |
|
307 | - * @param EE_Registration $item |
|
308 | - * @return string |
|
309 | - * @throws EE_Error |
|
310 | - * @throws InvalidArgumentException |
|
311 | - * @throws InvalidDataTypeException |
|
312 | - * @throws InvalidInterfaceException |
|
313 | - */ |
|
314 | - public function column__REG_att_checked_in(EE_Registration $item) |
|
315 | - { |
|
316 | - $attendee = $item->attendee(); |
|
317 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
318 | - |
|
319 | - if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
320 | - $latest_related_datetime = $item->get_latest_related_datetime(); |
|
321 | - if ($latest_related_datetime instanceof EE_Datetime) { |
|
322 | - $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
323 | - } |
|
324 | - } |
|
325 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
326 | - $item, |
|
327 | - $this->_cur_dtt_id |
|
328 | - ); |
|
329 | - $nonce = wp_create_nonce('checkin_nonce'); |
|
330 | - $toggle_active = ! empty($this->_cur_dtt_id) |
|
331 | - && EE_Registry::instance()->CAP->current_user_can( |
|
332 | - 'ee_edit_checkin', |
|
333 | - 'espresso_registrations_toggle_checkin_status', |
|
334 | - $item->ID() |
|
335 | - ) |
|
336 | - ? ' clickable trigger-checkin' |
|
337 | - : ''; |
|
338 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
339 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
340 | - . ' data-_regid="' . $item->ID() . '"' |
|
341 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
342 | - . ' data-nonce="' . $nonce . '">' |
|
343 | - . '</span>' |
|
344 | - . $mobile_view_content; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @param \EE_Registration $item |
|
350 | - * @return mixed|string|void |
|
351 | - * @throws \EE_Error |
|
352 | - */ |
|
353 | - public function column_ATT_name(EE_Registration $item) |
|
354 | - { |
|
355 | - $attendee = $item->attendee(); |
|
356 | - if (! $attendee instanceof EE_Attendee) { |
|
357 | - return __('No contact record for this registration.', 'event_espresso'); |
|
358 | - } |
|
359 | - // edit attendee link |
|
360 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
361 | - array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
362 | - REG_ADMIN_URL |
|
363 | - ); |
|
364 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
365 | - 'ee_edit_contacts', |
|
366 | - 'espresso_registrations_edit_attendee' |
|
367 | - ) |
|
368 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
369 | - . $item->attendee()->full_name() |
|
370 | - . '</a>' |
|
371 | - : $item->attendee()->full_name(); |
|
372 | - $name_link .= $item->count() === 1 |
|
373 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
|
374 | - : ''; |
|
375 | - // add group details |
|
376 | - $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
377 | - // add regcode |
|
378 | - $link = EE_Admin_Page::add_query_args_and_nonce( |
|
379 | - array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
380 | - REG_ADMIN_URL |
|
381 | - ); |
|
382 | - $name_link .= '<br>'; |
|
383 | - $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
384 | - 'ee_read_registration', |
|
385 | - 'view_registration', |
|
386 | - $item->ID() |
|
387 | - ) |
|
388 | - ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
389 | - . $item->reg_code() |
|
390 | - . '</a>' |
|
391 | - : $item->reg_code(); |
|
392 | - // status |
|
393 | - $name_link .= '<br><span class="ee-status-text-small">'; |
|
394 | - $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
395 | - $name_link .= '</span>'; |
|
396 | - $actions = array(); |
|
397 | - $DTT_ID = $this->_cur_dtt_id; |
|
398 | - $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
399 | - ? $item->get_latest_related_datetime() |
|
400 | - : null; |
|
401 | - $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
402 | - ? $latest_related_datetime->ID() |
|
403 | - : $DTT_ID; |
|
404 | - if (! empty($DTT_ID) |
|
405 | - && EE_Registry::instance()->CAP->current_user_can( |
|
406 | - 'ee_read_checkins', |
|
407 | - 'espresso_registrations_registration_checkins' |
|
408 | - ) |
|
409 | - ) { |
|
410 | - $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
411 | - array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID), |
|
412 | - REG_ADMIN_URL |
|
413 | - ); |
|
414 | - // get the timestamps for this registration's checkins, related to the selected datetime |
|
415 | - $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
416 | - if (! empty($timestamps)) { |
|
417 | - // get the last timestamp |
|
418 | - $last_timestamp = end($timestamps); |
|
419 | - // checked in or checked out? |
|
420 | - $checkin_status = $last_timestamp->get('CHK_in') |
|
421 | - ? esc_html__('Checked In', 'event_espresso') |
|
422 | - : esc_html__('Checked Out', 'event_espresso'); |
|
423 | - // get timestamp string |
|
424 | - $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
425 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
426 | - . esc_attr__( |
|
427 | - 'View this registrant\'s check-ins/checkouts for the datetime', |
|
428 | - 'event_espresso' |
|
429 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
430 | - } |
|
431 | - } |
|
432 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
433 | - ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
434 | - : $name_link; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @param \EE_Registration $item |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function column_ATT_email(EE_Registration $item) |
|
443 | - { |
|
444 | - $attendee = $item->attendee(); |
|
445 | - return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * @param \EE_Registration $item |
|
451 | - * @return bool|string |
|
452 | - * @throws \EE_Error |
|
453 | - */ |
|
454 | - public function column_Event(EE_Registration $item) |
|
455 | - { |
|
456 | - try { |
|
457 | - $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
|
458 | - $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
459 | - array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
460 | - REG_ADMIN_URL |
|
461 | - ); |
|
462 | - $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
463 | - 'ee_read_checkins', |
|
464 | - 'espresso_registrations_registration_checkins' |
|
465 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
466 | - . esc_attr__( |
|
467 | - 'View Checkins for this Event', |
|
468 | - 'event_espresso' |
|
469 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
470 | - } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
471 | - $event_label = esc_html__('Unknown', 'event_espresso'); |
|
472 | - } |
|
473 | - return $event_label; |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * @param \EE_Registration $item |
|
479 | - * @return mixed|string|void |
|
480 | - */ |
|
481 | - public function column_PRC_name(EE_Registration $item) |
|
482 | - { |
|
483 | - return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * column_REG_final_price |
|
489 | - * |
|
490 | - * @param \EE_Registration $item |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function column__REG_final_price(EE_Registration $item) |
|
494 | - { |
|
495 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * column_TXN_paid |
|
501 | - * |
|
502 | - * @param \EE_Registration $item |
|
503 | - * @return string |
|
504 | - * @throws \EE_Error |
|
505 | - */ |
|
506 | - public function column_TXN_paid(EE_Registration $item) |
|
507 | - { |
|
508 | - if ($item->count() === 1) { |
|
509 | - if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
510 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
511 | - } else { |
|
512 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
513 | - array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
514 | - TXN_ADMIN_URL |
|
515 | - ); |
|
516 | - return EE_Registry::instance()->CAP->current_user_can( |
|
517 | - 'ee_read_transaction', |
|
518 | - 'espresso_transactions_view_transaction' |
|
519 | - ) ? ' |
|
15 | + /** |
|
16 | + * This property will hold the related Datetimes on an event IF the event id is included in the request. |
|
17 | + * |
|
18 | + * @var EE_Datetime[] |
|
19 | + */ |
|
20 | + protected $_dtts_for_event = array(); |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * The event if one is specified in the request |
|
25 | + * |
|
26 | + * @var EE_Event |
|
27 | + */ |
|
28 | + protected $_evt = null; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * The DTT_ID if the current view has a specified datetime. |
|
33 | + * |
|
34 | + * @var int $_cur_dtt_id |
|
35 | + */ |
|
36 | + protected $_cur_dtt_id = 0; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EE_Event_Registrations_List_Table constructor. |
|
41 | + * |
|
42 | + * @param \Registrations_Admin_Page $admin_page |
|
43 | + */ |
|
44 | + public function __construct($admin_page) |
|
45 | + { |
|
46 | + parent::__construct($admin_page); |
|
47 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + protected function _setup_data() |
|
52 | + { |
|
53 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
54 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
55 | + $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
|
56 | + $this->_per_page, |
|
57 | + true |
|
58 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + protected function _set_properties() |
|
63 | + { |
|
64 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
65 | + $this->_wp_list_args = array( |
|
66 | + 'singular' => __('registrant', 'event_espresso'), |
|
67 | + 'plural' => __('registrants', 'event_espresso'), |
|
68 | + 'ajax' => true, |
|
69 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
70 | + ); |
|
71 | + $columns = array(); |
|
72 | + // $columns['_Reg_Status'] = ''; |
|
73 | + if (! empty($evt_id)) { |
|
74 | + $columns['cb'] = '<input type="checkbox" />'; // Render a checkbox instead of text |
|
75 | + $this->_has_checkbox_column = true; |
|
76 | + } |
|
77 | + $this->_columns = array( |
|
78 | + '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
|
79 | + 'ATT_name' => __('Registrant', 'event_espresso'), |
|
80 | + 'ATT_email' => __('Email Address', 'event_espresso'), |
|
81 | + 'Event' => __('Event', 'event_espresso'), |
|
82 | + 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
83 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
84 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
85 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
86 | + ); |
|
87 | + $this->_columns = array_merge($columns, $this->_columns); |
|
88 | + $this->_primary_column = '_REG_att_checked_in'; |
|
89 | + if (! empty($evt_id) |
|
90 | + && EE_Registry::instance()->CAP->current_user_can( |
|
91 | + 'ee_read_registrations', |
|
92 | + 'espresso_registrations_registrations_reports', |
|
93 | + $evt_id |
|
94 | + ) |
|
95 | + ) { |
|
96 | + $this->_bottom_buttons = array( |
|
97 | + 'report' => array( |
|
98 | + 'route' => 'registrations_report', |
|
99 | + 'extra_request' => |
|
100 | + array( |
|
101 | + 'EVT_ID' => $evt_id, |
|
102 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
103 | + ), |
|
104 | + ), |
|
105 | + ); |
|
106 | + } |
|
107 | + $this->_bottom_buttons['report_filtered'] = array( |
|
108 | + 'route' => 'registrations_checkin_report', |
|
109 | + 'extra_request' => array( |
|
110 | + 'use_filters' => true, |
|
111 | + 'filters' => array_merge( |
|
112 | + array( |
|
113 | + 'EVT_ID' => $evt_id, |
|
114 | + ), |
|
115 | + array_diff_key( |
|
116 | + $this->_req_data, |
|
117 | + array_flip( |
|
118 | + array( |
|
119 | + 'page', |
|
120 | + 'action', |
|
121 | + 'default_nonce', |
|
122 | + ) |
|
123 | + ) |
|
124 | + ) |
|
125 | + ), |
|
126 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
127 | + ), |
|
128 | + ); |
|
129 | + $this->_sortable_columns = array( |
|
130 | + /** |
|
131 | + * Allows users to change the default sort if they wish. |
|
132 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
133 | + * |
|
134 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
135 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
136 | + * for a specific list table you can use the provided reference to this object instance. |
|
137 | + */ |
|
138 | + 'ATT_name' => array( |
|
139 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
140 | + true, |
|
141 | + $this, |
|
142 | + ) |
|
143 | + ? array('ATT_lname' => true) |
|
144 | + : array('ATT_fname' => true), |
|
145 | + 'Event' => array('Event.EVT.Name' => false), |
|
146 | + ); |
|
147 | + $this->_hidden_columns = array(); |
|
148 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
149 | + $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param \EE_Registration $item |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + protected function _get_row_class($item) |
|
158 | + { |
|
159 | + $class = parent::_get_row_class($item); |
|
160 | + // add status class |
|
161 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
162 | + if ($this->_has_checkbox_column) { |
|
163 | + $class .= ' has-checkbox-column'; |
|
164 | + } |
|
165 | + return $class; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return array |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + protected function _get_table_filters() |
|
174 | + { |
|
175 | + $filters = $where = array(); |
|
176 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
177 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
178 | + // this means we don't have an event so let's setup a filter dropdown for all the events to select |
|
179 | + // note possible capability restrictions |
|
180 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
181 | + $where['status**'] = array('!=', 'private'); |
|
182 | + } |
|
183 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
184 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
185 | + } |
|
186 | + $events = EEM_Event::instance()->get_all( |
|
187 | + array( |
|
188 | + $where, |
|
189 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
190 | + ) |
|
191 | + ); |
|
192 | + $evts[] = array( |
|
193 | + 'id' => 0, |
|
194 | + 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
195 | + ); |
|
196 | + $checked = 'checked'; |
|
197 | + /** @var EE_Event $evt */ |
|
198 | + foreach ($events as $evt) { |
|
199 | + // any registrations for this event? |
|
200 | + if (! $evt->get_count_of_all_registrations()) { |
|
201 | + continue; |
|
202 | + } |
|
203 | + $evts[] = array( |
|
204 | + 'id' => $evt->ID(), |
|
205 | + 'text' => apply_filters( |
|
206 | + 'FHEE__EE_Event_Registrations___get_table_filters__event_name', |
|
207 | + $evt->get('EVT_name'), |
|
208 | + $evt |
|
209 | + ), |
|
210 | + 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
|
211 | + ); |
|
212 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
213 | + $checked = ''; |
|
214 | + } |
|
215 | + } |
|
216 | + $event_filter = '<div class="ee-event-filter">'; |
|
217 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
218 | + $event_filter .= '<span class="ee-event-filter-toggle">'; |
|
219 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
220 | + $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
221 | + $event_filter .= '</span>'; |
|
222 | + $event_filter .= '</div>'; |
|
223 | + $filters[] = $event_filter; |
|
224 | + } |
|
225 | + if (! empty($this->_dtts_for_event)) { |
|
226 | + // DTT datetimes filter |
|
227 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
228 | + if (count($this->_dtts_for_event) > 1) { |
|
229 | + $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
230 | + foreach ($this->_dtts_for_event as $dtt) { |
|
231 | + $datetime_string = $dtt->name(); |
|
232 | + $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
233 | + $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
234 | + $dtts[ $dtt->ID() ] = $datetime_string; |
|
235 | + } |
|
236 | + $input = new EE_Select_Input( |
|
237 | + $dtts, |
|
238 | + array( |
|
239 | + 'html_name' => 'DTT_ID', |
|
240 | + 'html_id' => 'DTT_ID', |
|
241 | + 'default' => $this->_cur_dtt_id, |
|
242 | + ) |
|
243 | + ); |
|
244 | + $filters[] = $input->get_html_for_input(); |
|
245 | + $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
246 | + } |
|
247 | + } |
|
248 | + return $filters; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + protected function _add_view_counts() |
|
253 | + { |
|
254 | + $this->_views['all']['count'] = $this->_get_total_event_attendees(); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * @return int |
|
260 | + * @throws \EE_Error |
|
261 | + */ |
|
262 | + protected function _get_total_event_attendees() |
|
263 | + { |
|
264 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
265 | + $DTT_ID = $this->_cur_dtt_id; |
|
266 | + $query_params = array(); |
|
267 | + if ($EVT_ID) { |
|
268 | + $query_params[0]['EVT_ID'] = $EVT_ID; |
|
269 | + } |
|
270 | + // if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
|
271 | + if ($DTT_ID) { |
|
272 | + $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
|
273 | + } |
|
274 | + $status_ids_array = apply_filters( |
|
275 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
276 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
277 | + ); |
|
278 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
279 | + return EEM_Registration::instance()->count($query_params); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param \EE_Registration $item |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function column__Reg_Status(EE_Registration $item) |
|
288 | + { |
|
289 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param \EE_Registration $item |
|
295 | + * @return string |
|
296 | + * @throws \EE_Error |
|
297 | + */ |
|
298 | + public function column_cb($item) |
|
299 | + { |
|
300 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * column_REG_att_checked_in |
|
306 | + * |
|
307 | + * @param EE_Registration $item |
|
308 | + * @return string |
|
309 | + * @throws EE_Error |
|
310 | + * @throws InvalidArgumentException |
|
311 | + * @throws InvalidDataTypeException |
|
312 | + * @throws InvalidInterfaceException |
|
313 | + */ |
|
314 | + public function column__REG_att_checked_in(EE_Registration $item) |
|
315 | + { |
|
316 | + $attendee = $item->attendee(); |
|
317 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
318 | + |
|
319 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
320 | + $latest_related_datetime = $item->get_latest_related_datetime(); |
|
321 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
322 | + $this->_cur_dtt_id = $latest_related_datetime->ID(); |
|
323 | + } |
|
324 | + } |
|
325 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
326 | + $item, |
|
327 | + $this->_cur_dtt_id |
|
328 | + ); |
|
329 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
330 | + $toggle_active = ! empty($this->_cur_dtt_id) |
|
331 | + && EE_Registry::instance()->CAP->current_user_can( |
|
332 | + 'ee_edit_checkin', |
|
333 | + 'espresso_registrations_toggle_checkin_status', |
|
334 | + $item->ID() |
|
335 | + ) |
|
336 | + ? ' clickable trigger-checkin' |
|
337 | + : ''; |
|
338 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
339 | + return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
340 | + . ' data-_regid="' . $item->ID() . '"' |
|
341 | + . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
342 | + . ' data-nonce="' . $nonce . '">' |
|
343 | + . '</span>' |
|
344 | + . $mobile_view_content; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @param \EE_Registration $item |
|
350 | + * @return mixed|string|void |
|
351 | + * @throws \EE_Error |
|
352 | + */ |
|
353 | + public function column_ATT_name(EE_Registration $item) |
|
354 | + { |
|
355 | + $attendee = $item->attendee(); |
|
356 | + if (! $attendee instanceof EE_Attendee) { |
|
357 | + return __('No contact record for this registration.', 'event_espresso'); |
|
358 | + } |
|
359 | + // edit attendee link |
|
360 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
361 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
362 | + REG_ADMIN_URL |
|
363 | + ); |
|
364 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
365 | + 'ee_edit_contacts', |
|
366 | + 'espresso_registrations_edit_attendee' |
|
367 | + ) |
|
368 | + ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
369 | + . $item->attendee()->full_name() |
|
370 | + . '</a>' |
|
371 | + : $item->attendee()->full_name(); |
|
372 | + $name_link .= $item->count() === 1 |
|
373 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
|
374 | + : ''; |
|
375 | + // add group details |
|
376 | + $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
377 | + // add regcode |
|
378 | + $link = EE_Admin_Page::add_query_args_and_nonce( |
|
379 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
380 | + REG_ADMIN_URL |
|
381 | + ); |
|
382 | + $name_link .= '<br>'; |
|
383 | + $name_link .= EE_Registry::instance()->instance()->CAP->current_user_can( |
|
384 | + 'ee_read_registration', |
|
385 | + 'view_registration', |
|
386 | + $item->ID() |
|
387 | + ) |
|
388 | + ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
389 | + . $item->reg_code() |
|
390 | + . '</a>' |
|
391 | + : $item->reg_code(); |
|
392 | + // status |
|
393 | + $name_link .= '<br><span class="ee-status-text-small">'; |
|
394 | + $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
395 | + $name_link .= '</span>'; |
|
396 | + $actions = array(); |
|
397 | + $DTT_ID = $this->_cur_dtt_id; |
|
398 | + $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
399 | + ? $item->get_latest_related_datetime() |
|
400 | + : null; |
|
401 | + $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
|
402 | + ? $latest_related_datetime->ID() |
|
403 | + : $DTT_ID; |
|
404 | + if (! empty($DTT_ID) |
|
405 | + && EE_Registry::instance()->CAP->current_user_can( |
|
406 | + 'ee_read_checkins', |
|
407 | + 'espresso_registrations_registration_checkins' |
|
408 | + ) |
|
409 | + ) { |
|
410 | + $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
|
411 | + array('action' => 'registration_checkins', '_REG_ID' => $item->ID(), 'DTT_ID' => $DTT_ID), |
|
412 | + REG_ADMIN_URL |
|
413 | + ); |
|
414 | + // get the timestamps for this registration's checkins, related to the selected datetime |
|
415 | + $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
416 | + if (! empty($timestamps)) { |
|
417 | + // get the last timestamp |
|
418 | + $last_timestamp = end($timestamps); |
|
419 | + // checked in or checked out? |
|
420 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
421 | + ? esc_html__('Checked In', 'event_espresso') |
|
422 | + : esc_html__('Checked Out', 'event_espresso'); |
|
423 | + // get timestamp string |
|
424 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
425 | + $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
426 | + . esc_attr__( |
|
427 | + 'View this registrant\'s check-ins/checkouts for the datetime', |
|
428 | + 'event_espresso' |
|
429 | + ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
430 | + } |
|
431 | + } |
|
432 | + return (! empty($DTT_ID) && ! empty($timestamps)) |
|
433 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
434 | + : $name_link; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @param \EE_Registration $item |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function column_ATT_email(EE_Registration $item) |
|
443 | + { |
|
444 | + $attendee = $item->attendee(); |
|
445 | + return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * @param \EE_Registration $item |
|
451 | + * @return bool|string |
|
452 | + * @throws \EE_Error |
|
453 | + */ |
|
454 | + public function column_Event(EE_Registration $item) |
|
455 | + { |
|
456 | + try { |
|
457 | + $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
|
458 | + $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
459 | + array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
460 | + REG_ADMIN_URL |
|
461 | + ); |
|
462 | + $event_label = EE_Registry::instance()->CAP->current_user_can( |
|
463 | + 'ee_read_checkins', |
|
464 | + 'espresso_registrations_registration_checkins' |
|
465 | + ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
466 | + . esc_attr__( |
|
467 | + 'View Checkins for this Event', |
|
468 | + 'event_espresso' |
|
469 | + ) . '">' . $event->name() . '</a>' : $event->name(); |
|
470 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
471 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
472 | + } |
|
473 | + return $event_label; |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * @param \EE_Registration $item |
|
479 | + * @return mixed|string|void |
|
480 | + */ |
|
481 | + public function column_PRC_name(EE_Registration $item) |
|
482 | + { |
|
483 | + return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * column_REG_final_price |
|
489 | + * |
|
490 | + * @param \EE_Registration $item |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function column__REG_final_price(EE_Registration $item) |
|
494 | + { |
|
495 | + return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * column_TXN_paid |
|
501 | + * |
|
502 | + * @param \EE_Registration $item |
|
503 | + * @return string |
|
504 | + * @throws \EE_Error |
|
505 | + */ |
|
506 | + public function column_TXN_paid(EE_Registration $item) |
|
507 | + { |
|
508 | + if ($item->count() === 1) { |
|
509 | + if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
510 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
511 | + } else { |
|
512 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
513 | + array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
514 | + TXN_ADMIN_URL |
|
515 | + ); |
|
516 | + return EE_Registry::instance()->CAP->current_user_can( |
|
517 | + 'ee_read_transaction', |
|
518 | + 'espresso_transactions_view_transaction' |
|
519 | + ) ? ' |
|
520 | 520 | <span class="reg-pad-rght"> |
521 | 521 | <a class="status-' |
522 | - . $item->transaction()->status_ID() |
|
523 | - . '" href="' |
|
524 | - . $view_txn_lnk_url |
|
525 | - . '" title="' |
|
526 | - . esc_attr__('View Transaction', 'event_espresso') |
|
527 | - . '"> |
|
522 | + . $item->transaction()->status_ID() |
|
523 | + . '" href="' |
|
524 | + . $view_txn_lnk_url |
|
525 | + . '" title="' |
|
526 | + . esc_attr__('View Transaction', 'event_espresso') |
|
527 | + . '"> |
|
528 | 528 | ' |
529 | - . $item->transaction()->pretty_paid() |
|
530 | - . ' |
|
529 | + . $item->transaction()->pretty_paid() |
|
530 | + . ' |
|
531 | 531 | </a> |
532 | 532 | <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
533 | - } |
|
534 | - } else { |
|
535 | - return '<span class="reg-pad-rght"></span>'; |
|
536 | - } |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * column_TXN_total |
|
542 | - * |
|
543 | - * @param \EE_Registration $item |
|
544 | - * @return string |
|
545 | - * @throws \EE_Error |
|
546 | - */ |
|
547 | - public function column_TXN_total(EE_Registration $item) |
|
548 | - { |
|
549 | - $txn = $item->transaction(); |
|
550 | - $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
551 | - if ($item->get('REG_count') === 1) { |
|
552 | - $line_total_obj = $txn->total_line_item(); |
|
553 | - $txn_total = $line_total_obj instanceof EE_Line_Item |
|
554 | - ? $line_total_obj->get_pretty('LIN_total') |
|
555 | - : __( |
|
556 | - 'View Transaction', |
|
557 | - 'event_espresso' |
|
558 | - ); |
|
559 | - return EE_Registry::instance()->CAP->current_user_can( |
|
560 | - 'ee_read_transaction', |
|
561 | - 'espresso_transactions_view_transaction' |
|
562 | - ) ? '<a href="' |
|
563 | - . $view_txn_url |
|
564 | - . '" title="' |
|
565 | - . esc_attr__('View Transaction', 'event_espresso') |
|
566 | - . '"><span class="reg-pad-rght">' |
|
567 | - . $txn_total |
|
568 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
569 | - } else { |
|
570 | - return '<span class="reg-pad-rght"></span>'; |
|
571 | - } |
|
572 | - } |
|
533 | + } |
|
534 | + } else { |
|
535 | + return '<span class="reg-pad-rght"></span>'; |
|
536 | + } |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * column_TXN_total |
|
542 | + * |
|
543 | + * @param \EE_Registration $item |
|
544 | + * @return string |
|
545 | + * @throws \EE_Error |
|
546 | + */ |
|
547 | + public function column_TXN_total(EE_Registration $item) |
|
548 | + { |
|
549 | + $txn = $item->transaction(); |
|
550 | + $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
551 | + if ($item->get('REG_count') === 1) { |
|
552 | + $line_total_obj = $txn->total_line_item(); |
|
553 | + $txn_total = $line_total_obj instanceof EE_Line_Item |
|
554 | + ? $line_total_obj->get_pretty('LIN_total') |
|
555 | + : __( |
|
556 | + 'View Transaction', |
|
557 | + 'event_espresso' |
|
558 | + ); |
|
559 | + return EE_Registry::instance()->CAP->current_user_can( |
|
560 | + 'ee_read_transaction', |
|
561 | + 'espresso_transactions_view_transaction' |
|
562 | + ) ? '<a href="' |
|
563 | + . $view_txn_url |
|
564 | + . '" title="' |
|
565 | + . esc_attr__('View Transaction', 'event_espresso') |
|
566 | + . '"><span class="reg-pad-rght">' |
|
567 | + . $txn_total |
|
568 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
569 | + } else { |
|
570 | + return '<span class="reg-pad-rght"></span>'; |
|
571 | + } |
|
572 | + } |
|
573 | 573 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ); |
71 | 71 | $columns = array(); |
72 | 72 | // $columns['_Reg_Status'] = ''; |
73 | - if (! empty($evt_id)) { |
|
73 | + if ( ! empty($evt_id)) { |
|
74 | 74 | $columns['cb'] = '<input type="checkbox" />'; // Render a checkbox instead of text |
75 | 75 | $this->_has_checkbox_column = true; |
76 | 76 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | ); |
87 | 87 | $this->_columns = array_merge($columns, $this->_columns); |
88 | 88 | $this->_primary_column = '_REG_att_checked_in'; |
89 | - if (! empty($evt_id) |
|
89 | + if ( ! empty($evt_id) |
|
90 | 90 | && EE_Registry::instance()->CAP->current_user_can( |
91 | 91 | 'ee_read_registrations', |
92 | 92 | 'espresso_registrations_registrations_reports', |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | { |
159 | 159 | $class = parent::_get_row_class($item); |
160 | 160 | // add status class |
161 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
161 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
162 | 162 | if ($this->_has_checkbox_column) { |
163 | 163 | $class .= ' has-checkbox-column'; |
164 | 164 | } |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
178 | 178 | // this means we don't have an event so let's setup a filter dropdown for all the events to select |
179 | 179 | // note possible capability restrictions |
180 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
180 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
181 | 181 | $where['status**'] = array('!=', 'private'); |
182 | 182 | } |
183 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
183 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
184 | 184 | $where['EVT_wp_user'] = get_current_user_id(); |
185 | 185 | } |
186 | 186 | $events = EEM_Event::instance()->get_all( |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | /** @var EE_Event $evt */ |
198 | 198 | foreach ($events as $evt) { |
199 | 199 | // any registrations for this event? |
200 | - if (! $evt->get_count_of_all_registrations()) { |
|
200 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | $evts[] = array( |
@@ -216,22 +216,22 @@ discard block |
||
216 | 216 | $event_filter = '<div class="ee-event-filter">'; |
217 | 217 | $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
218 | 218 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
219 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
219 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
220 | 220 | $event_filter .= __('Hide Expired Events', 'event_espresso'); |
221 | 221 | $event_filter .= '</span>'; |
222 | 222 | $event_filter .= '</div>'; |
223 | 223 | $filters[] = $event_filter; |
224 | 224 | } |
225 | - if (! empty($this->_dtts_for_event)) { |
|
225 | + if ( ! empty($this->_dtts_for_event)) { |
|
226 | 226 | // DTT datetimes filter |
227 | 227 | $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
228 | 228 | if (count($this->_dtts_for_event) > 1) { |
229 | 229 | $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
230 | 230 | foreach ($this->_dtts_for_event as $dtt) { |
231 | 231 | $datetime_string = $dtt->name(); |
232 | - $datetime_string = ! empty($datetime_string) ? ' (' . $datetime_string . ')' : ''; |
|
233 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
234 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
232 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
233 | + $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
234 | + $dtts[$dtt->ID()] = $datetime_string; |
|
235 | 235 | } |
236 | 236 | $input = new EE_Select_Input( |
237 | 237 | $dtts, |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | ) |
243 | 243 | ); |
244 | 244 | $filters[] = $input->get_html_for_input(); |
245 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
245 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | return $filters; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function column__Reg_Status(EE_Registration $item) |
288 | 288 | { |
289 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
289 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>'; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -335,11 +335,11 @@ discard block |
||
335 | 335 | ) |
336 | 336 | ? ' clickable trigger-checkin' |
337 | 337 | : ''; |
338 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
339 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
340 | - . ' data-_regid="' . $item->ID() . '"' |
|
341 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
342 | - . ' data-nonce="' . $nonce . '">' |
|
338 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
339 | + return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"' |
|
340 | + . ' data-_regid="'.$item->ID().'"' |
|
341 | + . ' data-dttid="'.$this->_cur_dtt_id.'"' |
|
342 | + . ' data-nonce="'.$nonce.'">' |
|
343 | 343 | . '</span>' |
344 | 344 | . $mobile_view_content; |
345 | 345 | } |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | public function column_ATT_name(EE_Registration $item) |
354 | 354 | { |
355 | 355 | $attendee = $item->attendee(); |
356 | - if (! $attendee instanceof EE_Attendee) { |
|
356 | + if ( ! $attendee instanceof EE_Attendee) { |
|
357 | 357 | return __('No contact record for this registration.', 'event_espresso'); |
358 | 358 | } |
359 | 359 | // edit attendee link |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'ee_edit_contacts', |
366 | 366 | 'espresso_registrations_edit_attendee' |
367 | 367 | ) |
368 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
368 | + ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
369 | 369 | . $item->attendee()->full_name() |
370 | 370 | . '</a>' |
371 | 371 | : $item->attendee()->full_name(); |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
374 | 374 | : ''; |
375 | 375 | // add group details |
376 | - $name_link .= ' ' . sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
376 | + $name_link .= ' '.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
377 | 377 | // add regcode |
378 | 378 | $link = EE_Admin_Page::add_query_args_and_nonce( |
379 | 379 | array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | 'view_registration', |
386 | 386 | $item->ID() |
387 | 387 | ) |
388 | - ? '<a href="' . $link . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
388 | + ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
389 | 389 | . $item->reg_code() |
390 | 390 | . '</a>' |
391 | 391 | : $item->reg_code(); |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
402 | 402 | ? $latest_related_datetime->ID() |
403 | 403 | : $DTT_ID; |
404 | - if (! empty($DTT_ID) |
|
404 | + if ( ! empty($DTT_ID) |
|
405 | 405 | && EE_Registry::instance()->CAP->current_user_can( |
406 | 406 | 'ee_read_checkins', |
407 | 407 | 'espresso_registrations_registration_checkins' |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | ); |
414 | 414 | // get the timestamps for this registration's checkins, related to the selected datetime |
415 | 415 | $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
416 | - if (! empty($timestamps)) { |
|
416 | + if ( ! empty($timestamps)) { |
|
417 | 417 | // get the last timestamp |
418 | 418 | $last_timestamp = end($timestamps); |
419 | 419 | // checked in or checked out? |
@@ -422,14 +422,14 @@ discard block |
||
422 | 422 | : esc_html__('Checked Out', 'event_espresso'); |
423 | 423 | // get timestamp string |
424 | 424 | $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
425 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' |
|
425 | + $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="' |
|
426 | 426 | . esc_attr__( |
427 | 427 | 'View this registrant\'s check-ins/checkouts for the datetime', |
428 | 428 | 'event_espresso' |
429 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
429 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
430 | 430 | } |
431 | 431 | } |
432 | - return (! empty($DTT_ID) && ! empty($timestamps)) |
|
432 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
433 | 433 | ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
434 | 434 | : $name_link; |
435 | 435 | } |
@@ -462,11 +462,11 @@ discard block |
||
462 | 462 | $event_label = EE_Registry::instance()->CAP->current_user_can( |
463 | 463 | 'ee_read_checkins', |
464 | 464 | 'espresso_registrations_registration_checkins' |
465 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' |
|
465 | + ) ? '<a href="'.$chkin_lnk_url.'" title="' |
|
466 | 466 | . esc_attr__( |
467 | 467 | 'View Checkins for this Event', |
468 | 468 | 'event_espresso' |
469 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
469 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
470 | 470 | } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
471 | 471 | $event_label = esc_html__('Unknown', 'event_espresso'); |
472 | 472 | } |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | */ |
493 | 493 | public function column__REG_final_price(EE_Registration $item) |
494 | 494 | { |
495 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
495 | + return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>'; |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | . $item->transaction()->pretty_paid() |
530 | 530 | . ' |
531 | 531 | </a> |
532 | - <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
532 | + <span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
533 | 533 | } |
534 | 534 | } else { |
535 | 535 | return '<span class="reg-pad-rght"></span>'; |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | . esc_attr__('View Transaction', 'event_espresso') |
566 | 566 | . '"><span class="reg-pad-rght">' |
567 | 567 | . $txn_total |
568 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
568 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
569 | 569 | } else { |
570 | 570 | return '<span class="reg-pad-rght"></span>'; |
571 | 571 | } |
@@ -17,156 +17,156 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - public function __construct($admin_page) |
|
21 | - { |
|
22 | - parent::__construct($admin_page); |
|
23 | - } |
|
24 | - |
|
25 | - |
|
26 | - protected function _setup_data() |
|
27 | - { |
|
28 | - $this->_data = $this->_get_checkins($this->_per_page); |
|
29 | - $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - protected function _set_properties() |
|
34 | - { |
|
35 | - $this->_wp_list_args = array( |
|
36 | - 'singular' => __('check-in', 'event_espresso'), |
|
37 | - 'plural' => __('check-ins', 'event_espresso'), |
|
38 | - 'ajax' => true, |
|
39 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
40 | - ); |
|
41 | - |
|
42 | - $this->_columns = array( |
|
43 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
44 | - 'CHK_in' => __('Check-In', 'event_espresso'), |
|
45 | - 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
46 | - ); |
|
47 | - |
|
48 | - $this->_sortable_columns = array( |
|
49 | - 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
50 | - ); |
|
51 | - |
|
52 | - $this->_primary_column = 'CHK_in'; |
|
53 | - |
|
54 | - $this->_hidden_columns = array(); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - protected function _get_table_filters() |
|
59 | - { |
|
60 | - return array(); |
|
61 | - } |
|
62 | - |
|
63 | - // remove the search box |
|
64 | - public function search_box($text, $input_id) |
|
65 | - { |
|
66 | - return ''; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - protected function _add_view_counts() |
|
71 | - { |
|
72 | - $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - public function column_cb($item) |
|
77 | - { |
|
78 | - return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - public function column_CHK_in(EE_Checkin $item) |
|
83 | - { |
|
84 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
85 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - public function column_CHK_timestamp(EE_Checkin $item) |
|
90 | - { |
|
91 | - $actions = array(); |
|
92 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', |
|
93 | - 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
94 | - '_REG_ID' => $this->_req_data['_REG_ID'], |
|
95 | - 'CHK_ID' => $item->ID(), |
|
96 | - )); |
|
97 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
98 | - 'ee_delete_checkins', |
|
99 | - 'espresso_registrations_delete_checkin_row' |
|
100 | - ) |
|
101 | - ? '<a href="' . $delete_url . '" title="' |
|
102 | - . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
103 | - . __('Delete', 'event_espresso') . '</a>' |
|
104 | - : ''; |
|
105 | - |
|
106 | - return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions)); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * This retrieves all the Check-ins for the given parameters. |
|
112 | - * experimenting with having the query for the table values within the list table. |
|
113 | - * |
|
114 | - * @access protected |
|
115 | - * @param int $per_page How many to retrieve per page |
|
116 | - * @param bool $count Whether to return a count or not |
|
117 | - * @return EE_Checkin[]|int |
|
118 | - */ |
|
119 | - protected function _get_checkins($per_page = 10, $count = false) |
|
120 | - { |
|
121 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
122 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
123 | - |
|
124 | - // if user does not have the capability for the checkins for this registration then get out! |
|
125 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
126 | - 'ee_read_checkin', |
|
127 | - 'espresso_registrations_registration_checkins', |
|
128 | - $REG_ID |
|
129 | - )) { |
|
130 | - return $count ? 0 : array(); |
|
131 | - } |
|
132 | - |
|
133 | - // if no reg id then get out cause need a reg id |
|
134 | - if (empty($REG_ID) || empty($DTT_ID)) { |
|
135 | - throw new EE_Error( |
|
136 | - __( |
|
137 | - 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
138 | - 'event_espresso' |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - // set orderby |
|
144 | - $orderby = 'CHK_timestamp'; // note that with this table we're only providing the option to orderby the timestamp value. |
|
145 | - |
|
146 | - $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
147 | - |
|
148 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
149 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
150 | - $limit = null; |
|
151 | - if (! $count) { |
|
152 | - $offset = ($current_page - 1) * $per_page; |
|
153 | - $limit = array($offset, $per_page); |
|
154 | - } |
|
155 | - |
|
156 | - $_where = array( |
|
157 | - 'REG_ID' => $REG_ID, |
|
158 | - 'DTT_ID' => $DTT_ID, |
|
159 | - ); |
|
160 | - |
|
161 | - $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
162 | - |
|
163 | - // if no per_page value then we just want to return a count of all Check-ins |
|
164 | - if ($count) { |
|
165 | - return EEM_Checkin::instance()->count(array($_where)); |
|
166 | - } |
|
167 | - |
|
168 | - return $count |
|
169 | - ? EEM_Checkin::instance()->count(array($_where)) |
|
170 | - : EEM_Checkin::instance()->get_all($query_params); |
|
171 | - } |
|
20 | + public function __construct($admin_page) |
|
21 | + { |
|
22 | + parent::__construct($admin_page); |
|
23 | + } |
|
24 | + |
|
25 | + |
|
26 | + protected function _setup_data() |
|
27 | + { |
|
28 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
29 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, true); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + protected function _set_properties() |
|
34 | + { |
|
35 | + $this->_wp_list_args = array( |
|
36 | + 'singular' => __('check-in', 'event_espresso'), |
|
37 | + 'plural' => __('check-ins', 'event_espresso'), |
|
38 | + 'ajax' => true, |
|
39 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
40 | + ); |
|
41 | + |
|
42 | + $this->_columns = array( |
|
43 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
44 | + 'CHK_in' => __('Check-In', 'event_espresso'), |
|
45 | + 'CHK_timestamp' => __('Timestamp', 'event_espresso'), |
|
46 | + ); |
|
47 | + |
|
48 | + $this->_sortable_columns = array( |
|
49 | + 'CHK_timestamp' => array('CHK_timestamp' => true), |
|
50 | + ); |
|
51 | + |
|
52 | + $this->_primary_column = 'CHK_in'; |
|
53 | + |
|
54 | + $this->_hidden_columns = array(); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + protected function _get_table_filters() |
|
59 | + { |
|
60 | + return array(); |
|
61 | + } |
|
62 | + |
|
63 | + // remove the search box |
|
64 | + public function search_box($text, $input_id) |
|
65 | + { |
|
66 | + return ''; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + protected function _add_view_counts() |
|
71 | + { |
|
72 | + $this->_views['all']['count'] = $this->_get_checkins(null, true); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + public function column_cb($item) |
|
77 | + { |
|
78 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + public function column_CHK_in(EE_Checkin $item) |
|
83 | + { |
|
84 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
85 | + return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + public function column_CHK_timestamp(EE_Checkin $item) |
|
90 | + { |
|
91 | + $actions = array(); |
|
92 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', |
|
93 | + 'DTT_ID' => $this->_req_data['DTT_ID'], |
|
94 | + '_REG_ID' => $this->_req_data['_REG_ID'], |
|
95 | + 'CHK_ID' => $item->ID(), |
|
96 | + )); |
|
97 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( |
|
98 | + 'ee_delete_checkins', |
|
99 | + 'espresso_registrations_delete_checkin_row' |
|
100 | + ) |
|
101 | + ? '<a href="' . $delete_url . '" title="' |
|
102 | + . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
103 | + . __('Delete', 'event_espresso') . '</a>' |
|
104 | + : ''; |
|
105 | + |
|
106 | + return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions)); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * This retrieves all the Check-ins for the given parameters. |
|
112 | + * experimenting with having the query for the table values within the list table. |
|
113 | + * |
|
114 | + * @access protected |
|
115 | + * @param int $per_page How many to retrieve per page |
|
116 | + * @param bool $count Whether to return a count or not |
|
117 | + * @return EE_Checkin[]|int |
|
118 | + */ |
|
119 | + protected function _get_checkins($per_page = 10, $count = false) |
|
120 | + { |
|
121 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : false; |
|
122 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
|
123 | + |
|
124 | + // if user does not have the capability for the checkins for this registration then get out! |
|
125 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
126 | + 'ee_read_checkin', |
|
127 | + 'espresso_registrations_registration_checkins', |
|
128 | + $REG_ID |
|
129 | + )) { |
|
130 | + return $count ? 0 : array(); |
|
131 | + } |
|
132 | + |
|
133 | + // if no reg id then get out cause need a reg id |
|
134 | + if (empty($REG_ID) || empty($DTT_ID)) { |
|
135 | + throw new EE_Error( |
|
136 | + __( |
|
137 | + 'This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', |
|
138 | + 'event_espresso' |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + // set orderby |
|
144 | + $orderby = 'CHK_timestamp'; // note that with this table we're only providing the option to orderby the timestamp value. |
|
145 | + |
|
146 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
147 | + |
|
148 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
149 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
150 | + $limit = null; |
|
151 | + if (! $count) { |
|
152 | + $offset = ($current_page - 1) * $per_page; |
|
153 | + $limit = array($offset, $per_page); |
|
154 | + } |
|
155 | + |
|
156 | + $_where = array( |
|
157 | + 'REG_ID' => $REG_ID, |
|
158 | + 'DTT_ID' => $DTT_ID, |
|
159 | + ); |
|
160 | + |
|
161 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
162 | + |
|
163 | + // if no per_page value then we just want to return a count of all Check-ins |
|
164 | + if ($count) { |
|
165 | + return EEM_Checkin::instance()->count(array($_where)); |
|
166 | + } |
|
167 | + |
|
168 | + return $count |
|
169 | + ? EEM_Checkin::instance()->count(array($_where)) |
|
170 | + : EEM_Checkin::instance()->get_all($query_params); |
|
171 | + } |
|
172 | 172 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function column_CHK_in(EE_Checkin $item) |
83 | 83 | { |
84 | 84 | $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
85 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
85 | + return '<span class="'.$checkin_status_dashicon->cssClasses().'"></span><span class="show-on-mobile-view-only">'.$item->get_datetime('CHK_timestamp').'</span>'; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | 'ee_delete_checkins', |
99 | 99 | 'espresso_registrations_delete_checkin_row' |
100 | 100 | ) |
101 | - ? '<a href="' . $delete_url . '" title="' |
|
102 | - . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' |
|
103 | - . __('Delete', 'event_espresso') . '</a>' |
|
101 | + ? '<a href="'.$delete_url.'" title="' |
|
102 | + . esc_attr__('Click here to delete this check-in record', 'event_espresso').'">' |
|
103 | + . __('Delete', 'event_espresso').'</a>' |
|
104 | 104 | : ''; |
105 | 105 | |
106 | 106 | return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions)); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : false; |
123 | 123 | |
124 | 124 | // if user does not have the capability for the checkins for this registration then get out! |
125 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
125 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
126 | 126 | 'ee_read_checkin', |
127 | 127 | 'espresso_registrations_registration_checkins', |
128 | 128 | $REG_ID |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
149 | 149 | $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
150 | 150 | $limit = null; |
151 | - if (! $count) { |
|
151 | + if ( ! $count) { |
|
152 | 152 | $offset = ($current_page - 1) * $per_page; |
153 | 153 | $limit = array($offset, $per_page); |
154 | 154 | } |
@@ -12,252 +12,252 @@ |
||
12 | 12 | class Custom_Messages_Template_List_Table extends Messages_Template_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Setup initial data. |
|
17 | - */ |
|
18 | - protected function _setup_data() |
|
19 | - { |
|
20 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
21 | - $this->_per_page, |
|
22 | - $this->_view, |
|
23 | - false, |
|
24 | - false, |
|
25 | - false |
|
26 | - ); |
|
27 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
28 | - $this->_per_page, |
|
29 | - $this->_view, |
|
30 | - true, |
|
31 | - true, |
|
32 | - false |
|
33 | - ); |
|
34 | - } |
|
15 | + /** |
|
16 | + * Setup initial data. |
|
17 | + */ |
|
18 | + protected function _setup_data() |
|
19 | + { |
|
20 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
21 | + $this->_per_page, |
|
22 | + $this->_view, |
|
23 | + false, |
|
24 | + false, |
|
25 | + false |
|
26 | + ); |
|
27 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
28 | + $this->_per_page, |
|
29 | + $this->_view, |
|
30 | + true, |
|
31 | + true, |
|
32 | + false |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Set initial properties |
|
39 | - */ |
|
40 | - protected function _set_properties() |
|
41 | - { |
|
42 | - parent::_set_properties(); |
|
43 | - $this->_wp_list_args = array( |
|
44 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
45 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
46 | - 'ajax' => true, // for now, |
|
47 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
48 | - ); |
|
37 | + /** |
|
38 | + * Set initial properties |
|
39 | + */ |
|
40 | + protected function _set_properties() |
|
41 | + { |
|
42 | + parent::_set_properties(); |
|
43 | + $this->_wp_list_args = array( |
|
44 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
45 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
46 | + 'ajax' => true, // for now, |
|
47 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
48 | + ); |
|
49 | 49 | |
50 | - $this->_columns = array_merge( |
|
51 | - array( |
|
52 | - 'cb' => '<input type="checkbox" />', |
|
53 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
54 | - ), |
|
55 | - $this->_columns, |
|
56 | - array( |
|
57 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
58 | - 'actions' => '', |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
50 | + $this->_columns = array_merge( |
|
51 | + array( |
|
52 | + 'cb' => '<input type="checkbox" />', |
|
53 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
54 | + ), |
|
55 | + $this->_columns, |
|
56 | + array( |
|
57 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
58 | + 'actions' => '', |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Custom message for when there are no items found. |
|
66 | - * |
|
67 | - * @since 4.3.0 |
|
68 | - */ |
|
69 | - public function no_items() |
|
70 | - { |
|
71 | - if ($this->_view !== 'trashed') { |
|
72 | - printf( |
|
73 | - esc_html__( |
|
74 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - '<strong>', |
|
78 | - '</strong>' |
|
79 | - ); |
|
80 | - } else { |
|
81 | - parent::no_items(); |
|
82 | - } |
|
83 | - } |
|
64 | + /** |
|
65 | + * Custom message for when there are no items found. |
|
66 | + * |
|
67 | + * @since 4.3.0 |
|
68 | + */ |
|
69 | + public function no_items() |
|
70 | + { |
|
71 | + if ($this->_view !== 'trashed') { |
|
72 | + printf( |
|
73 | + esc_html__( |
|
74 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + '<strong>', |
|
78 | + '</strong>' |
|
79 | + ); |
|
80 | + } else { |
|
81 | + parent::no_items(); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * @param EE_Message_Template_Group $item |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function column_cb($item) |
|
91 | - { |
|
92 | - return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
93 | - } |
|
86 | + /** |
|
87 | + * @param EE_Message_Template_Group $item |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function column_cb($item) |
|
91 | + { |
|
92 | + return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * @param EE_Message_Template_Group $item |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function column_name($item) |
|
101 | - { |
|
102 | - return '<p>' . $item->name() . '</p>'; |
|
103 | - } |
|
96 | + /** |
|
97 | + * @param EE_Message_Template_Group $item |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function column_name($item) |
|
101 | + { |
|
102 | + return '<p>' . $item->name() . '</p>'; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @param EE_Message_Template_Group $item |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function column_actions($item) |
|
111 | - { |
|
112 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
113 | - 'ee_edit_messages', |
|
114 | - 'espresso_messages_add_new_message_template' |
|
115 | - )) { |
|
116 | - $create_args = array( |
|
117 | - 'GRP_ID' => $item->ID(), |
|
118 | - 'messenger' => $item->messenger(), |
|
119 | - 'message_type' => $item->message_type(), |
|
120 | - 'action' => 'add_new_message_template', |
|
121 | - ); |
|
122 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
123 | - return sprintf( |
|
124 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
125 | - $create_link, |
|
126 | - esc_html__('Create Custom', 'event_espresso') |
|
127 | - ); |
|
128 | - } |
|
129 | - return ''; |
|
130 | - } |
|
106 | + /** |
|
107 | + * @param EE_Message_Template_Group $item |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function column_actions($item) |
|
111 | + { |
|
112 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
113 | + 'ee_edit_messages', |
|
114 | + 'espresso_messages_add_new_message_template' |
|
115 | + )) { |
|
116 | + $create_args = array( |
|
117 | + 'GRP_ID' => $item->ID(), |
|
118 | + 'messenger' => $item->messenger(), |
|
119 | + 'message_type' => $item->message_type(), |
|
120 | + 'action' => 'add_new_message_template', |
|
121 | + ); |
|
122 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
123 | + return sprintf( |
|
124 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
125 | + $create_link, |
|
126 | + esc_html__('Create Custom', 'event_espresso') |
|
127 | + ); |
|
128 | + } |
|
129 | + return ''; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Set the view counts on the _views property |
|
134 | - */ |
|
135 | - protected function _add_view_counts() |
|
136 | - { |
|
137 | - foreach ($this->_views as $view => $args) { |
|
138 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
139 | - $this->_per_page, |
|
140 | - $view, |
|
141 | - true, |
|
142 | - true, |
|
143 | - false |
|
144 | - ); |
|
145 | - } |
|
146 | - } |
|
132 | + /** |
|
133 | + * Set the view counts on the _views property |
|
134 | + */ |
|
135 | + protected function _add_view_counts() |
|
136 | + { |
|
137 | + foreach ($this->_views as $view => $args) { |
|
138 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
139 | + $this->_per_page, |
|
140 | + $view, |
|
141 | + true, |
|
142 | + true, |
|
143 | + false |
|
144 | + ); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | - /** |
|
150 | - * column_events |
|
151 | - * This provides a count of events using this custom template |
|
152 | - * |
|
153 | - * @param EE_Message_Template_Group $item message_template group data |
|
154 | - * @return string column output |
|
155 | - */ |
|
156 | - public function column_events($item) |
|
157 | - { |
|
158 | - return $item->count_events(); |
|
159 | - } |
|
149 | + /** |
|
150 | + * column_events |
|
151 | + * This provides a count of events using this custom template |
|
152 | + * |
|
153 | + * @param EE_Message_Template_Group $item message_template group data |
|
154 | + * @return string column output |
|
155 | + */ |
|
156 | + public function column_events($item) |
|
157 | + { |
|
158 | + return $item->count_events(); |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * Add additional actions for custom message template list view. |
|
164 | - * |
|
165 | - * @param EE_Message_Template_Group $item |
|
166 | - * @return array |
|
167 | - * @throws EE_Error |
|
168 | - */ |
|
169 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
170 | - { |
|
171 | - $actions = parent::_get_actions_for_messenger_column($item); |
|
162 | + /** |
|
163 | + * Add additional actions for custom message template list view. |
|
164 | + * |
|
165 | + * @param EE_Message_Template_Group $item |
|
166 | + * @return array |
|
167 | + * @throws EE_Error |
|
168 | + */ |
|
169 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
170 | + { |
|
171 | + $actions = parent::_get_actions_for_messenger_column($item); |
|
172 | 172 | |
173 | - // add additional actions for trash/restore etc. |
|
174 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
175 | - 'action' => 'trash_message_template', |
|
176 | - 'id' => $item->GRP_ID(), |
|
177 | - 'noheader' => true, |
|
178 | - ), EE_MSG_ADMIN_URL); |
|
179 | - // restore link |
|
180 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
181 | - 'action' => 'restore_message_template', |
|
182 | - 'id' => $item->GRP_ID(), |
|
183 | - 'noheader' => true, |
|
184 | - ), EE_MSG_ADMIN_URL); |
|
185 | - // delete price link |
|
186 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
187 | - 'action' => 'delete_message_template', |
|
188 | - 'id' => $item->GRP_ID(), |
|
189 | - 'noheader' => true, |
|
190 | - ), EE_MSG_ADMIN_URL); |
|
173 | + // add additional actions for trash/restore etc. |
|
174 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
175 | + 'action' => 'trash_message_template', |
|
176 | + 'id' => $item->GRP_ID(), |
|
177 | + 'noheader' => true, |
|
178 | + ), EE_MSG_ADMIN_URL); |
|
179 | + // restore link |
|
180 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
181 | + 'action' => 'restore_message_template', |
|
182 | + 'id' => $item->GRP_ID(), |
|
183 | + 'noheader' => true, |
|
184 | + ), EE_MSG_ADMIN_URL); |
|
185 | + // delete price link |
|
186 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
187 | + 'action' => 'delete_message_template', |
|
188 | + 'id' => $item->GRP_ID(), |
|
189 | + 'noheader' => true, |
|
190 | + ), EE_MSG_ADMIN_URL); |
|
191 | 191 | |
192 | - if (! $item->get('MTP_deleted') |
|
193 | - && EE_Registry::instance()->CAP->current_user_can( |
|
194 | - 'ee_delete_message', |
|
195 | - 'espresso_messages_trash_message_template', |
|
196 | - $item->ID() |
|
197 | - ) |
|
198 | - ) { |
|
199 | - $actions['trash'] = '<a href="' |
|
200 | - . $trash_lnk_url |
|
201 | - . '" title="' |
|
202 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
203 | - . '">' |
|
204 | - . esc_html__('Move to Trash', 'event_espresso') |
|
205 | - . '</a>'; |
|
206 | - } else { |
|
207 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
208 | - 'ee_delete_message', |
|
209 | - 'espresso_messages_restore_message_template', |
|
210 | - $item->ID() |
|
211 | - )) { |
|
212 | - $actions['restore'] = '<a href="' |
|
213 | - . $restore_lnk_url |
|
214 | - . '" title="' |
|
215 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
216 | - . '">' |
|
217 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
218 | - } |
|
192 | + if (! $item->get('MTP_deleted') |
|
193 | + && EE_Registry::instance()->CAP->current_user_can( |
|
194 | + 'ee_delete_message', |
|
195 | + 'espresso_messages_trash_message_template', |
|
196 | + $item->ID() |
|
197 | + ) |
|
198 | + ) { |
|
199 | + $actions['trash'] = '<a href="' |
|
200 | + . $trash_lnk_url |
|
201 | + . '" title="' |
|
202 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
203 | + . '">' |
|
204 | + . esc_html__('Move to Trash', 'event_espresso') |
|
205 | + . '</a>'; |
|
206 | + } else { |
|
207 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
208 | + 'ee_delete_message', |
|
209 | + 'espresso_messages_restore_message_template', |
|
210 | + $item->ID() |
|
211 | + )) { |
|
212 | + $actions['restore'] = '<a href="' |
|
213 | + . $restore_lnk_url |
|
214 | + . '" title="' |
|
215 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
216 | + . '">' |
|
217 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
218 | + } |
|
219 | 219 | |
220 | - if ($this->_view === 'trashed' |
|
221 | - && EE_Registry::instance()->CAP->current_user_can( |
|
222 | - 'ee_delete_message', |
|
223 | - 'espresso_messages_delete_message_template', |
|
224 | - $item->ID() |
|
225 | - )) { |
|
226 | - $actions['delete'] = '<a href="' |
|
227 | - . $delete_lnk_url |
|
228 | - . '" title="' |
|
229 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
230 | - . '">' |
|
231 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
232 | - . '</a>'; |
|
233 | - } |
|
234 | - } |
|
235 | - return $actions; |
|
236 | - } |
|
220 | + if ($this->_view === 'trashed' |
|
221 | + && EE_Registry::instance()->CAP->current_user_can( |
|
222 | + 'ee_delete_message', |
|
223 | + 'espresso_messages_delete_message_template', |
|
224 | + $item->ID() |
|
225 | + )) { |
|
226 | + $actions['delete'] = '<a href="' |
|
227 | + . $delete_lnk_url |
|
228 | + . '" title="' |
|
229 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
230 | + . '">' |
|
231 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
232 | + . '</a>'; |
|
233 | + } |
|
234 | + } |
|
235 | + return $actions; |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * Generate dropdown filter select input for messengers |
|
241 | - * |
|
242 | - * @param bool $global |
|
243 | - * @return string |
|
244 | - * @throws EE_Error |
|
245 | - */ |
|
246 | - protected function _get_messengers_dropdown_filter($global = true) |
|
247 | - { |
|
248 | - return parent::_get_messengers_dropdown_filter(false); |
|
249 | - } |
|
239 | + /** |
|
240 | + * Generate dropdown filter select input for messengers |
|
241 | + * |
|
242 | + * @param bool $global |
|
243 | + * @return string |
|
244 | + * @throws EE_Error |
|
245 | + */ |
|
246 | + protected function _get_messengers_dropdown_filter($global = true) |
|
247 | + { |
|
248 | + return parent::_get_messengers_dropdown_filter(false); |
|
249 | + } |
|
250 | 250 | |
251 | 251 | |
252 | - /** |
|
253 | - * Generate dropdown filter select input for message types |
|
254 | - * |
|
255 | - * @param bool $global |
|
256 | - * @return string |
|
257 | - * @throws EE_Error |
|
258 | - */ |
|
259 | - protected function _get_message_types_dropdown_filter($global = true) |
|
260 | - { |
|
261 | - return parent::_get_message_types_dropdown_filter(false); |
|
262 | - } |
|
252 | + /** |
|
253 | + * Generate dropdown filter select input for message types |
|
254 | + * |
|
255 | + * @param bool $global |
|
256 | + * @return string |
|
257 | + * @throws EE_Error |
|
258 | + */ |
|
259 | + protected function _get_message_types_dropdown_filter($global = true) |
|
260 | + { |
|
261 | + return parent::_get_message_types_dropdown_filter(false); |
|
262 | + } |
|
263 | 263 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function column_name($item) |
101 | 101 | { |
102 | - return '<p>' . $item->name() . '</p>'; |
|
102 | + return '<p>'.$item->name().'</p>'; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | protected function _add_view_counts() |
136 | 136 | { |
137 | 137 | foreach ($this->_views as $view => $args) { |
138 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
138 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
139 | 139 | $this->_per_page, |
140 | 140 | $view, |
141 | 141 | true, |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'noheader' => true, |
190 | 190 | ), EE_MSG_ADMIN_URL); |
191 | 191 | |
192 | - if (! $item->get('MTP_deleted') |
|
192 | + if ( ! $item->get('MTP_deleted') |
|
193 | 193 | && EE_Registry::instance()->CAP->current_user_can( |
194 | 194 | 'ee_delete_message', |
195 | 195 | 'espresso_messages_trash_message_template', |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | . '" title="' |
215 | 215 | . esc_attr__('Restore Message Template', 'event_espresso') |
216 | 216 | . '">' |
217 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
217 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | if ($this->_view === 'trashed' |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks |
14 | 14 | { |
15 | - /** |
|
16 | - * espresso_events_Messages_Hooks_Extend constructor. |
|
17 | - * |
|
18 | - * @param \EE_Admin_Page $admin_page |
|
19 | - */ |
|
20 | - public function __construct(EE_Admin_Page $admin_page) |
|
21 | - { |
|
22 | - /** |
|
23 | - * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
24 | - */ |
|
25 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
26 | - 'ee_edit_messages', |
|
27 | - 'messages_events_editor_metabox' |
|
28 | - )) { |
|
29 | - return; |
|
30 | - } |
|
31 | - add_filter( |
|
32 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
33 | - array($this, 'caf_updates'), |
|
34 | - 10 |
|
35 | - ); |
|
36 | - add_action( |
|
37 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
38 | - array($this, 'duplicate_custom_message_settings'), |
|
39 | - 10, |
|
40 | - 2 |
|
41 | - ); |
|
42 | - parent::__construct($admin_page); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * extending the properties set in espresso_events_Messages_Hooks |
|
48 | - * |
|
49 | - * @access protected |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - protected function _extend_properties() |
|
53 | - { |
|
54 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
55 | - $this->_ajax_func = array( |
|
56 | - 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
57 | - ); |
|
58 | - $this->_metaboxes = array( |
|
59 | - 0 => array( |
|
60 | - 'page_route' => array('edit', 'create_new'), |
|
61 | - 'func' => 'messages_metabox', |
|
62 | - 'label' => esc_html__('Notifications', 'event_espresso'), |
|
63 | - 'priority' => 'high', |
|
64 | - ), |
|
65 | - ); |
|
66 | - |
|
67 | - // see explanation for layout in EE_Admin_Hooks |
|
68 | - $this->_scripts_styles = array( |
|
69 | - 'registers' => array( |
|
70 | - 'events_msg_admin' => array( |
|
71 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
72 | - 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
73 | - ), |
|
74 | - 'events_msg_admin_css' => array( |
|
75 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
76 | - 'type' => 'css', |
|
77 | - ), |
|
78 | - ), |
|
79 | - 'enqueues' => array( |
|
80 | - 'events_msg_admin' => array('edit', 'create_new'), |
|
81 | - 'events_msg_admin_css' => array('edit', 'create_new'), |
|
82 | - ), |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - public function caf_updates($update_callbacks) |
|
88 | - { |
|
89 | - $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
90 | - return $update_callbacks; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Handles attaching Message Templates to the Event on save. |
|
96 | - * |
|
97 | - * @param EE_Event $event EE event object |
|
98 | - * @param array $data The request data from the form |
|
99 | - * @return bool success or fail |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public function attach_evt_message_templates($event, $data) |
|
103 | - { |
|
104 | - // first we remove all existing relations on the Event for message types. |
|
105 | - $event->_remove_relations('Message_Template_Group'); |
|
106 | - // now let's just loop through the selected templates and add relations! |
|
107 | - if (isset($data['event_message_templates_relation'])) { |
|
108 | - foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
109 | - $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
110 | - } |
|
111 | - } |
|
112 | - // now save |
|
113 | - return $event->save(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param $event |
|
119 | - * @param $callback_args |
|
120 | - * @return string |
|
121 | - * @throws \EE_Error |
|
122 | - */ |
|
123 | - public function messages_metabox($event, $callback_args) |
|
124 | - { |
|
125 | - // let's get the active messengers (b/c messenger objects have the active message templates) |
|
126 | - // convert 'evt_id' to 'EVT_ID' |
|
127 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
128 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
129 | - ? $this->_req_data['post'] |
|
130 | - : $this->_req_data['EVT_ID']; |
|
131 | - |
|
132 | - $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
133 | - ? $this->_req_data['evt_id'] |
|
134 | - : $this->_req_data['EVT_ID']; |
|
135 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
136 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
137 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
138 | - $tabs = array(); |
|
139 | - |
|
140 | - // empty messengers? |
|
141 | - // Note message types will always have at least one available because every messenger has a default message type |
|
142 | - // associated with it (payment) if no other message types are selected. |
|
143 | - if (empty($active_messengers)) { |
|
144 | - $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
145 | - array('action' => 'settings'), |
|
146 | - EE_MSG_ADMIN_URL |
|
147 | - ); |
|
148 | - $error_msg = sprintf( |
|
149 | - esc_html__( |
|
150 | - 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
151 | - 'event_espresso' |
|
152 | - ), |
|
153 | - '<strong>', |
|
154 | - '</strong>', |
|
155 | - '<a href="' . $msg_activate_url . '">', |
|
156 | - '</a>' |
|
157 | - ); |
|
158 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
160 | - |
|
161 | - echo $error_content; |
|
162 | - echo $internal_content; |
|
163 | - return ''; |
|
164 | - } |
|
165 | - |
|
166 | - $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
167 | - // get content for active messengers |
|
168 | - foreach ($active_messengers as $name => $messenger) { |
|
169 | - // first check if there are any active message types for this messenger. |
|
170 | - $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
171 | - if (empty($active_mts)) { |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - $tab_content = $messenger->get_messenger_admin_page_content( |
|
176 | - 'events', |
|
177 | - 'edit', |
|
178 | - array('event' => $event_id) |
|
179 | - ); |
|
180 | - |
|
181 | - if (! empty($tab_content)) { |
|
182 | - $tabs[ $name ] = $tab_content; |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
188 | - $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
189 | - if ($tabbed_content instanceof WP_Error) { |
|
190 | - $tabbed_content = $tabbed_content->get_error_message(); |
|
191 | - } |
|
192 | - |
|
193 | - $notices = ' |
|
15 | + /** |
|
16 | + * espresso_events_Messages_Hooks_Extend constructor. |
|
17 | + * |
|
18 | + * @param \EE_Admin_Page $admin_page |
|
19 | + */ |
|
20 | + public function __construct(EE_Admin_Page $admin_page) |
|
21 | + { |
|
22 | + /** |
|
23 | + * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
24 | + */ |
|
25 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
26 | + 'ee_edit_messages', |
|
27 | + 'messages_events_editor_metabox' |
|
28 | + )) { |
|
29 | + return; |
|
30 | + } |
|
31 | + add_filter( |
|
32 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
33 | + array($this, 'caf_updates'), |
|
34 | + 10 |
|
35 | + ); |
|
36 | + add_action( |
|
37 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
38 | + array($this, 'duplicate_custom_message_settings'), |
|
39 | + 10, |
|
40 | + 2 |
|
41 | + ); |
|
42 | + parent::__construct($admin_page); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * extending the properties set in espresso_events_Messages_Hooks |
|
48 | + * |
|
49 | + * @access protected |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + protected function _extend_properties() |
|
53 | + { |
|
54 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
55 | + $this->_ajax_func = array( |
|
56 | + 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
57 | + ); |
|
58 | + $this->_metaboxes = array( |
|
59 | + 0 => array( |
|
60 | + 'page_route' => array('edit', 'create_new'), |
|
61 | + 'func' => 'messages_metabox', |
|
62 | + 'label' => esc_html__('Notifications', 'event_espresso'), |
|
63 | + 'priority' => 'high', |
|
64 | + ), |
|
65 | + ); |
|
66 | + |
|
67 | + // see explanation for layout in EE_Admin_Hooks |
|
68 | + $this->_scripts_styles = array( |
|
69 | + 'registers' => array( |
|
70 | + 'events_msg_admin' => array( |
|
71 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
72 | + 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
73 | + ), |
|
74 | + 'events_msg_admin_css' => array( |
|
75 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
76 | + 'type' => 'css', |
|
77 | + ), |
|
78 | + ), |
|
79 | + 'enqueues' => array( |
|
80 | + 'events_msg_admin' => array('edit', 'create_new'), |
|
81 | + 'events_msg_admin_css' => array('edit', 'create_new'), |
|
82 | + ), |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + public function caf_updates($update_callbacks) |
|
88 | + { |
|
89 | + $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
90 | + return $update_callbacks; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Handles attaching Message Templates to the Event on save. |
|
96 | + * |
|
97 | + * @param EE_Event $event EE event object |
|
98 | + * @param array $data The request data from the form |
|
99 | + * @return bool success or fail |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public function attach_evt_message_templates($event, $data) |
|
103 | + { |
|
104 | + // first we remove all existing relations on the Event for message types. |
|
105 | + $event->_remove_relations('Message_Template_Group'); |
|
106 | + // now let's just loop through the selected templates and add relations! |
|
107 | + if (isset($data['event_message_templates_relation'])) { |
|
108 | + foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
109 | + $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
110 | + } |
|
111 | + } |
|
112 | + // now save |
|
113 | + return $event->save(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param $event |
|
119 | + * @param $callback_args |
|
120 | + * @return string |
|
121 | + * @throws \EE_Error |
|
122 | + */ |
|
123 | + public function messages_metabox($event, $callback_args) |
|
124 | + { |
|
125 | + // let's get the active messengers (b/c messenger objects have the active message templates) |
|
126 | + // convert 'evt_id' to 'EVT_ID' |
|
127 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
128 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
129 | + ? $this->_req_data['post'] |
|
130 | + : $this->_req_data['EVT_ID']; |
|
131 | + |
|
132 | + $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
133 | + ? $this->_req_data['evt_id'] |
|
134 | + : $this->_req_data['EVT_ID']; |
|
135 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
136 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
137 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
138 | + $tabs = array(); |
|
139 | + |
|
140 | + // empty messengers? |
|
141 | + // Note message types will always have at least one available because every messenger has a default message type |
|
142 | + // associated with it (payment) if no other message types are selected. |
|
143 | + if (empty($active_messengers)) { |
|
144 | + $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
145 | + array('action' => 'settings'), |
|
146 | + EE_MSG_ADMIN_URL |
|
147 | + ); |
|
148 | + $error_msg = sprintf( |
|
149 | + esc_html__( |
|
150 | + 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
151 | + 'event_espresso' |
|
152 | + ), |
|
153 | + '<strong>', |
|
154 | + '</strong>', |
|
155 | + '<a href="' . $msg_activate_url . '">', |
|
156 | + '</a>' |
|
157 | + ); |
|
158 | + $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | + $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
160 | + |
|
161 | + echo $error_content; |
|
162 | + echo $internal_content; |
|
163 | + return ''; |
|
164 | + } |
|
165 | + |
|
166 | + $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
167 | + // get content for active messengers |
|
168 | + foreach ($active_messengers as $name => $messenger) { |
|
169 | + // first check if there are any active message types for this messenger. |
|
170 | + $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
171 | + if (empty($active_mts)) { |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + $tab_content = $messenger->get_messenger_admin_page_content( |
|
176 | + 'events', |
|
177 | + 'edit', |
|
178 | + array('event' => $event_id) |
|
179 | + ); |
|
180 | + |
|
181 | + if (! empty($tab_content)) { |
|
182 | + $tabs[ $name ] = $tab_content; |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
188 | + $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
189 | + if ($tabbed_content instanceof WP_Error) { |
|
190 | + $tabbed_content = $tabbed_content->get_error_message(); |
|
191 | + } |
|
192 | + |
|
193 | + $notices = ' |
|
194 | 194 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
195 | 195 | <span class="ee-spinner ee-spin"></span><span class="hidden">' |
196 | - . esc_html__('loading...', 'event_espresso') |
|
197 | - . '</span> |
|
196 | + . esc_html__('loading...', 'event_espresso') |
|
197 | + . '</span> |
|
198 | 198 | </div> |
199 | 199 | <div class="ee-notices"></div>'; |
200 | 200 | |
201 | - if (defined('DOING_AJAX')) { |
|
202 | - return $tabbed_content; |
|
203 | - } |
|
204 | - |
|
205 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
206 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
207 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
213 | - * Takes incoming GRP_ID and name and description values from ajax request |
|
214 | - * to create a new custom template based off of the incoming GRP_ID. |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @return string either an html string will be returned or a success message |
|
218 | - * @throws EE_Error |
|
219 | - */ |
|
220 | - public function create_new_custom() |
|
221 | - { |
|
222 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | - wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
224 | - } |
|
225 | - |
|
226 | - // let's clean up the _POST global a bit for downstream usage of name and description. |
|
227 | - $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
228 | - ? $this->_req_data['custom_template_args']['MTP_name'] |
|
229 | - : ''; |
|
230 | - $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
231 | - ? $this->_req_data['custom_template_args']['MTP_description'] |
|
232 | - : ''; |
|
233 | - |
|
234 | - |
|
235 | - // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
236 | - $this->_set_page_object(); |
|
237 | - |
|
238 | - // is this a template switch if so EE_Admin_Page child needs this object |
|
239 | - $this->_page_object->set_hook_object($this); |
|
240 | - |
|
241 | - $this->_page_object->add_message_template( |
|
242 | - $this->_req_data['messageType'], |
|
243 | - $this->_req_data['messenger'], |
|
244 | - $this->_req_data['group_ID'] |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - public function create_new_admin_footer() |
|
250 | - { |
|
251 | - $this->edit_admin_footer(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * This is the dynamic method for this class |
|
257 | - * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
258 | - * |
|
259 | - * @return string |
|
260 | - * @throws DomainException |
|
261 | - */ |
|
262 | - public function edit_admin_footer() |
|
263 | - { |
|
264 | - EEH_Template::display_template( |
|
265 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
266 | - ); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
272 | - * the assigned custom message templates. |
|
273 | - * |
|
274 | - * @param EE_Event $new_event |
|
275 | - * @param EE_Event $original_event |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
279 | - { |
|
280 | - $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
281 | - foreach ($message_template_groups as $message_template_group) { |
|
282 | - $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
283 | - } |
|
284 | - // save new event |
|
285 | - $new_event->save(); |
|
286 | - } |
|
201 | + if (defined('DOING_AJAX')) { |
|
202 | + return $tabbed_content; |
|
203 | + } |
|
204 | + |
|
205 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
206 | + echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
207 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
213 | + * Takes incoming GRP_ID and name and description values from ajax request |
|
214 | + * to create a new custom template based off of the incoming GRP_ID. |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @return string either an html string will be returned or a success message |
|
218 | + * @throws EE_Error |
|
219 | + */ |
|
220 | + public function create_new_custom() |
|
221 | + { |
|
222 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | + wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
224 | + } |
|
225 | + |
|
226 | + // let's clean up the _POST global a bit for downstream usage of name and description. |
|
227 | + $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
228 | + ? $this->_req_data['custom_template_args']['MTP_name'] |
|
229 | + : ''; |
|
230 | + $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
231 | + ? $this->_req_data['custom_template_args']['MTP_description'] |
|
232 | + : ''; |
|
233 | + |
|
234 | + |
|
235 | + // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
236 | + $this->_set_page_object(); |
|
237 | + |
|
238 | + // is this a template switch if so EE_Admin_Page child needs this object |
|
239 | + $this->_page_object->set_hook_object($this); |
|
240 | + |
|
241 | + $this->_page_object->add_message_template( |
|
242 | + $this->_req_data['messageType'], |
|
243 | + $this->_req_data['messenger'], |
|
244 | + $this->_req_data['group_ID'] |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + public function create_new_admin_footer() |
|
250 | + { |
|
251 | + $this->edit_admin_footer(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * This is the dynamic method for this class |
|
257 | + * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
258 | + * |
|
259 | + * @return string |
|
260 | + * @throws DomainException |
|
261 | + */ |
|
262 | + public function edit_admin_footer() |
|
263 | + { |
|
264 | + EEH_Template::display_template( |
|
265 | + EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
266 | + ); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
272 | + * the assigned custom message templates. |
|
273 | + * |
|
274 | + * @param EE_Event $new_event |
|
275 | + * @param EE_Event $original_event |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
279 | + { |
|
280 | + $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
281 | + foreach ($message_template_groups as $message_template_group) { |
|
282 | + $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
283 | + } |
|
284 | + // save new event |
|
285 | + $new_event->save(); |
|
286 | + } |
|
287 | 287 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
24 | 24 | */ |
25 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
25 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
26 | 26 | 'ee_edit_messages', |
27 | 27 | 'messages_events_editor_metabox' |
28 | 28 | )) { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | protected function _extend_properties() |
53 | 53 | { |
54 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
54 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/'); |
|
55 | 55 | $this->_ajax_func = array( |
56 | 56 | 'ee_msgs_create_new_custom' => 'create_new_custom', |
57 | 57 | ); |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $this->_scripts_styles = array( |
69 | 69 | 'registers' => array( |
70 | 70 | 'events_msg_admin' => array( |
71 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
71 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js', |
|
72 | 72 | 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
73 | 73 | ), |
74 | 74 | 'events_msg_admin_css' => array( |
75 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
75 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css', |
|
76 | 76 | 'type' => 'css', |
77 | 77 | ), |
78 | 78 | ), |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | ), |
153 | 153 | '<strong>', |
154 | 154 | '</strong>', |
155 | - '<a href="' . $msg_activate_url . '">', |
|
155 | + '<a href="'.$msg_activate_url.'">', |
|
156 | 156 | '</a>' |
157 | 157 | ); |
158 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
159 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
158 | + $error_content = '<div class="error"><p>'.$error_msg.'</p></div>'; |
|
159 | + $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>'; |
|
160 | 160 | |
161 | 161 | echo $error_content; |
162 | 162 | echo $internal_content; |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | array('event' => $event_id) |
179 | 179 | ); |
180 | 180 | |
181 | - if (! empty($tab_content)) { |
|
182 | - $tabs[ $name ] = $tab_content; |
|
181 | + if ( ! empty($tab_content)) { |
|
182 | + $tabs[$name] = $tab_content; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | } |
204 | 204 | |
205 | 205 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
206 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
206 | + echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>'; |
|
207 | 207 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
208 | 208 | } |
209 | 209 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function create_new_custom() |
221 | 221 | { |
222 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
222 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
223 | 223 | wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
224 | 224 | } |
225 | 225 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | public function edit_admin_footer() |
263 | 263 | { |
264 | 264 | EEH_Template::display_template( |
265 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
265 | + EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php' |
|
266 | 266 | ); |
267 | 267 | } |
268 | 268 |
@@ -18,153 +18,153 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - protected function _setup_data() |
|
22 | - { |
|
23 | - $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
24 | - $this->_data = $this->_admin_page->get_default_tickets($this->_per_page, false, $trashed); |
|
25 | - $this->_all_data_count = $this->_admin_page->get_default_tickets($this->_per_page, true, false); |
|
26 | - $this->_trashed_count = $this->_admin_page->get_default_tickets($this->_per_page, true, true); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - protected function _set_properties() |
|
31 | - { |
|
32 | - $this->_wp_list_args = array( |
|
33 | - 'singular' => __('ticket', 'event_espresso'), |
|
34 | - 'plural' => __('tickets', 'event_espresso'), |
|
35 | - 'ajax' => true, |
|
36 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
37 | - ); |
|
38 | - |
|
39 | - $this->_columns = array( |
|
40 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
41 | - 'TKT_name' => __('Name', 'event_espresso'), |
|
42 | - 'TKT_description' => __('Description', 'event_espresso'), |
|
43 | - 'TKT_qty' => __('Quantity', 'event_espresso'), |
|
44 | - 'TKT_uses' => __('Uses', 'event_espresso'), |
|
45 | - 'TKT_min' => __('Minimum', 'event_espresso'), |
|
46 | - 'TKT_max' => __('Maximum', 'event_espresso'), |
|
47 | - 'TKT_price' => __('Price', 'event_espresso'), |
|
48 | - 'TKT_taxable' => __('Taxable', 'event_espresso'), |
|
49 | - ); |
|
50 | - |
|
51 | - $this->_sortable_columns = array( |
|
52 | - // TRUE means its already sorted |
|
53 | - 'TKT_name' => array('TKT_name', true), |
|
54 | - 'TKT_description' => array('TKT_description', false), |
|
55 | - 'TKT_qty' => array('TKT_qty', false), |
|
56 | - 'TKT_uses' => array('TKT_uses', false), |
|
57 | - 'TKT_min' => array('TKT_min', false), |
|
58 | - 'TKT_max' => array('TKT_max', false), |
|
59 | - 'TKT_price' => array('TKT_price', false), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_hidden_columns = array(); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - protected function _get_table_filters() |
|
67 | - { |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - protected function _add_view_counts() |
|
72 | - { |
|
73 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
74 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_tickets', 'trash_ticket')) { |
|
75 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - public function column_cb($item) |
|
81 | - { |
|
82 | - return $item->ID() === 1 |
|
83 | - ? '<span class="ee-lock-icon"></span>' |
|
84 | - : sprintf( |
|
85 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
86 | - $item->ID() |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - public function column_TKT_name($item) |
|
92 | - { |
|
93 | - // build row actions |
|
94 | - $actions = array(); |
|
95 | - |
|
96 | - // trash links |
|
97 | - if ($item->ID() !== 1) { |
|
98 | - if ($this->_view == 'all') { |
|
99 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
100 | - 'action' => 'trash_ticket', |
|
101 | - 'TKT_ID' => $item->ID(), |
|
102 | - ), TICKETS_ADMIN_URL); |
|
103 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
104 | - . esc_attr__('Move Ticket to trash', 'event_espresso') . '">' |
|
105 | - . __('Trash', 'event_espresso') . '</a>'; |
|
106 | - } else { |
|
107 | - // restore price link |
|
108 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
109 | - 'action' => 'restore_ticket', |
|
110 | - 'TKT_ID' => $item->ID(), |
|
111 | - ), TICKETS_ADMIN_URL); |
|
112 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
113 | - . esc_attr__('Restore Ticket', 'event_espresso') . '">' |
|
114 | - . __('Restore', 'event_espresso') . '</a>'; |
|
115 | - // delete price link |
|
116 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
117 | - 'action' => 'delete_ticket', |
|
118 | - 'TKT_ID' => $item->ID(), |
|
119 | - ), TICKETS_ADMIN_URL); |
|
120 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
121 | - . esc_attr__('Delete Ticket Permanently', 'event_espresso') . '">' |
|
122 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - return $item->get('TKT_name') . $this->row_actions($actions); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - public function column_TKT_description($item) |
|
131 | - { |
|
132 | - return $item->get('TKT_description'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - public function column_TKT_qty($item) |
|
137 | - { |
|
138 | - return $item->get_pretty('TKT_qty', 'text'); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - public function column_TKT_uses($item) |
|
143 | - { |
|
144 | - return $item->get_pretty('TKT_uses', 'text'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - public function column_TKT_min($item) |
|
149 | - { |
|
150 | - return $item->get('TKT_min'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function column_TKT_max($item) |
|
155 | - { |
|
156 | - return $item->get_pretty('TKT_max', 'text'); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function column_TKT_price($item) |
|
161 | - { |
|
162 | - return EEH_Template::format_currency($item->get('TKT_price')); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - public function column_TKT_taxable($item) |
|
167 | - { |
|
168 | - return $item->get('TKT_taxable') ? __('Yes', 'event_espresso') : __('No', 'event_espresso'); |
|
169 | - } |
|
21 | + protected function _setup_data() |
|
22 | + { |
|
23 | + $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
24 | + $this->_data = $this->_admin_page->get_default_tickets($this->_per_page, false, $trashed); |
|
25 | + $this->_all_data_count = $this->_admin_page->get_default_tickets($this->_per_page, true, false); |
|
26 | + $this->_trashed_count = $this->_admin_page->get_default_tickets($this->_per_page, true, true); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + protected function _set_properties() |
|
31 | + { |
|
32 | + $this->_wp_list_args = array( |
|
33 | + 'singular' => __('ticket', 'event_espresso'), |
|
34 | + 'plural' => __('tickets', 'event_espresso'), |
|
35 | + 'ajax' => true, |
|
36 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
37 | + ); |
|
38 | + |
|
39 | + $this->_columns = array( |
|
40 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
41 | + 'TKT_name' => __('Name', 'event_espresso'), |
|
42 | + 'TKT_description' => __('Description', 'event_espresso'), |
|
43 | + 'TKT_qty' => __('Quantity', 'event_espresso'), |
|
44 | + 'TKT_uses' => __('Uses', 'event_espresso'), |
|
45 | + 'TKT_min' => __('Minimum', 'event_espresso'), |
|
46 | + 'TKT_max' => __('Maximum', 'event_espresso'), |
|
47 | + 'TKT_price' => __('Price', 'event_espresso'), |
|
48 | + 'TKT_taxable' => __('Taxable', 'event_espresso'), |
|
49 | + ); |
|
50 | + |
|
51 | + $this->_sortable_columns = array( |
|
52 | + // TRUE means its already sorted |
|
53 | + 'TKT_name' => array('TKT_name', true), |
|
54 | + 'TKT_description' => array('TKT_description', false), |
|
55 | + 'TKT_qty' => array('TKT_qty', false), |
|
56 | + 'TKT_uses' => array('TKT_uses', false), |
|
57 | + 'TKT_min' => array('TKT_min', false), |
|
58 | + 'TKT_max' => array('TKT_max', false), |
|
59 | + 'TKT_price' => array('TKT_price', false), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_hidden_columns = array(); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + protected function _get_table_filters() |
|
67 | + { |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + protected function _add_view_counts() |
|
72 | + { |
|
73 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
74 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_tickets', 'trash_ticket')) { |
|
75 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + public function column_cb($item) |
|
81 | + { |
|
82 | + return $item->ID() === 1 |
|
83 | + ? '<span class="ee-lock-icon"></span>' |
|
84 | + : sprintf( |
|
85 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
86 | + $item->ID() |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + public function column_TKT_name($item) |
|
92 | + { |
|
93 | + // build row actions |
|
94 | + $actions = array(); |
|
95 | + |
|
96 | + // trash links |
|
97 | + if ($item->ID() !== 1) { |
|
98 | + if ($this->_view == 'all') { |
|
99 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
100 | + 'action' => 'trash_ticket', |
|
101 | + 'TKT_ID' => $item->ID(), |
|
102 | + ), TICKETS_ADMIN_URL); |
|
103 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
104 | + . esc_attr__('Move Ticket to trash', 'event_espresso') . '">' |
|
105 | + . __('Trash', 'event_espresso') . '</a>'; |
|
106 | + } else { |
|
107 | + // restore price link |
|
108 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
109 | + 'action' => 'restore_ticket', |
|
110 | + 'TKT_ID' => $item->ID(), |
|
111 | + ), TICKETS_ADMIN_URL); |
|
112 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
113 | + . esc_attr__('Restore Ticket', 'event_espresso') . '">' |
|
114 | + . __('Restore', 'event_espresso') . '</a>'; |
|
115 | + // delete price link |
|
116 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
117 | + 'action' => 'delete_ticket', |
|
118 | + 'TKT_ID' => $item->ID(), |
|
119 | + ), TICKETS_ADMIN_URL); |
|
120 | + $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
121 | + . esc_attr__('Delete Ticket Permanently', 'event_espresso') . '">' |
|
122 | + . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + return $item->get('TKT_name') . $this->row_actions($actions); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + public function column_TKT_description($item) |
|
131 | + { |
|
132 | + return $item->get('TKT_description'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + public function column_TKT_qty($item) |
|
137 | + { |
|
138 | + return $item->get_pretty('TKT_qty', 'text'); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + public function column_TKT_uses($item) |
|
143 | + { |
|
144 | + return $item->get_pretty('TKT_uses', 'text'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + public function column_TKT_min($item) |
|
149 | + { |
|
150 | + return $item->get('TKT_min'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function column_TKT_max($item) |
|
155 | + { |
|
156 | + return $item->get_pretty('TKT_max', 'text'); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function column_TKT_price($item) |
|
161 | + { |
|
162 | + return EEH_Template::format_currency($item->get('TKT_price')); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + public function column_TKT_taxable($item) |
|
167 | + { |
|
168 | + return $item->get('TKT_taxable') ? __('Yes', 'event_espresso') : __('No', 'event_espresso'); |
|
169 | + } |
|
170 | 170 | } |
@@ -100,30 +100,30 @@ |
||
100 | 100 | 'action' => 'trash_ticket', |
101 | 101 | 'TKT_ID' => $item->ID(), |
102 | 102 | ), TICKETS_ADMIN_URL); |
103 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
104 | - . esc_attr__('Move Ticket to trash', 'event_espresso') . '">' |
|
105 | - . __('Trash', 'event_espresso') . '</a>'; |
|
103 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
104 | + . esc_attr__('Move Ticket to trash', 'event_espresso').'">' |
|
105 | + . __('Trash', 'event_espresso').'</a>'; |
|
106 | 106 | } else { |
107 | 107 | // restore price link |
108 | 108 | $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
109 | 109 | 'action' => 'restore_ticket', |
110 | 110 | 'TKT_ID' => $item->ID(), |
111 | 111 | ), TICKETS_ADMIN_URL); |
112 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
113 | - . esc_attr__('Restore Ticket', 'event_espresso') . '">' |
|
114 | - . __('Restore', 'event_espresso') . '</a>'; |
|
112 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
113 | + . esc_attr__('Restore Ticket', 'event_espresso').'">' |
|
114 | + . __('Restore', 'event_espresso').'</a>'; |
|
115 | 115 | // delete price link |
116 | 116 | $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
117 | 117 | 'action' => 'delete_ticket', |
118 | 118 | 'TKT_ID' => $item->ID(), |
119 | 119 | ), TICKETS_ADMIN_URL); |
120 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
121 | - . esc_attr__('Delete Ticket Permanently', 'event_espresso') . '">' |
|
122 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
120 | + $actions['delete'] = '<a href="'.$delete_lnk_url.'" title="' |
|
121 | + . esc_attr__('Delete Ticket Permanently', 'event_espresso').'">' |
|
122 | + . __('Delete Permanently', 'event_espresso').'</a>'; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - return $item->get('TKT_name') . $this->row_actions($actions); |
|
126 | + return $item->get('TKT_name').$this->row_actions($actions); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 |
@@ -15,2196 +15,2196 @@ |
||
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 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
378 | - // before going any further make sure our dates are setup correctly |
|
379 | - // so that the end date is always equal or greater than the start date. |
|
380 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
381 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
382 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
383 | - $datetime->save(); |
|
384 | - } |
|
385 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
386 | - // because it is possible there was a new one created for the autosave. |
|
387 | - // (save the ID for both key and value to avoid duplications) |
|
388 | - $DTT_ID = $datetime->ID(); |
|
389 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
390 | - $saved_dtt_objs[ $row ] = $datetime; |
|
391 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
392 | - } |
|
393 | - $event->save(); |
|
394 | - // now we need to REMOVE any datetimes that got deleted. |
|
395 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
396 | - // So its safe to permanently delete at this point. |
|
397 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
398 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
399 | - if (is_array($old_datetimes)) { |
|
400 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
401 | - foreach ($datetimes_to_delete as $id) { |
|
402 | - $id = absint($id); |
|
403 | - if (empty($id)) { |
|
404 | - continue; |
|
405 | - } |
|
406 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
407 | - // remove tkt relationships. |
|
408 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
409 | - foreach ($related_tickets as $tkt) { |
|
410 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
411 | - } |
|
412 | - $event->_remove_relation_to($id, 'Datetime'); |
|
413 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
414 | - } |
|
415 | - } |
|
416 | - return $saved_dtt_objs; |
|
417 | - } |
|
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 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
378 | + // before going any further make sure our dates are setup correctly |
|
379 | + // so that the end date is always equal or greater than the start date. |
|
380 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
381 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
382 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
383 | + $datetime->save(); |
|
384 | + } |
|
385 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
386 | + // because it is possible there was a new one created for the autosave. |
|
387 | + // (save the ID for both key and value to avoid duplications) |
|
388 | + $DTT_ID = $datetime->ID(); |
|
389 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
390 | + $saved_dtt_objs[ $row ] = $datetime; |
|
391 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
392 | + } |
|
393 | + $event->save(); |
|
394 | + // now we need to REMOVE any datetimes that got deleted. |
|
395 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
396 | + // So its safe to permanently delete at this point. |
|
397 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
398 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
399 | + if (is_array($old_datetimes)) { |
|
400 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
401 | + foreach ($datetimes_to_delete as $id) { |
|
402 | + $id = absint($id); |
|
403 | + if (empty($id)) { |
|
404 | + continue; |
|
405 | + } |
|
406 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
407 | + // remove tkt relationships. |
|
408 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
409 | + foreach ($related_tickets as $tkt) { |
|
410 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
411 | + } |
|
412 | + $event->_remove_relation_to($id, 'Datetime'); |
|
413 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
414 | + } |
|
415 | + } |
|
416 | + return $saved_dtt_objs; |
|
417 | + } |
|
418 | 418 | |
419 | 419 | |
420 | - /** |
|
421 | - * update tickets |
|
422 | - * |
|
423 | - * @param EE_Event $event Event object being updated |
|
424 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
425 | - * @param array $data incoming request data |
|
426 | - * @return EE_Ticket[] |
|
427 | - * @throws Exception |
|
428 | - * @throws ReflectionException |
|
429 | - * @throws InvalidInterfaceException |
|
430 | - * @throws InvalidDataTypeException |
|
431 | - * @throws InvalidArgumentException |
|
432 | - * @throws EE_Error |
|
433 | - */ |
|
434 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
435 | - { |
|
436 | - $new_tkt = null; |
|
437 | - $new_default = null; |
|
438 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
439 | - $data = stripslashes_deep($data); |
|
440 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
441 | - $saved_tickets = $datetimes_on_existing = array(); |
|
442 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
443 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
444 | - throw new InvalidArgumentException( |
|
445 | - esc_html__( |
|
446 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
447 | - 'event_espresso' |
|
448 | - ) |
|
449 | - ); |
|
450 | - } |
|
451 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
452 | - $update_prices = $create_new_TKT = false; |
|
453 | - // figure out what datetimes were added to the ticket |
|
454 | - // and what datetimes were removed from the ticket in the session. |
|
455 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
456 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
457 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
458 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
459 | - // trim inputs to ensure any excess whitespace is removed. |
|
460 | - $tkt = array_map( |
|
461 | - function ($ticket_data) { |
|
462 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
463 | - }, |
|
464 | - $tkt |
|
465 | - ); |
|
466 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
467 | - // because we're doing calculations prior to using the models. |
|
468 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
469 | - $ticket_price = isset($tkt['TKT_price']) |
|
470 | - ? round((float) $tkt['TKT_price'], 3) |
|
471 | - : 0; |
|
472 | - // note incoming base price needs converted from localized value. |
|
473 | - $base_price = isset($tkt['TKT_base_price']) |
|
474 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
475 | - : 0; |
|
476 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
477 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
478 | - ? $base_price |
|
479 | - : $ticket_price; |
|
480 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
481 | - ? $tkt['TKT_base_price_ID'] |
|
482 | - : 0; |
|
483 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
484 | - ? $data['edit_prices'][ $row ] |
|
485 | - : array(); |
|
486 | - $now = null; |
|
487 | - if (empty($tkt['TKT_start_date'])) { |
|
488 | - // lets' use now in the set timezone. |
|
489 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
490 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
491 | - } |
|
492 | - if (empty($tkt['TKT_end_date'])) { |
|
493 | - /** |
|
494 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
495 | - */ |
|
496 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
497 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
498 | - } |
|
499 | - $TKT_values = array( |
|
500 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
501 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
502 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
503 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
504 | - && $tkt['TKT_description'] !== esc_html__( |
|
505 | - 'You can modify this description', |
|
506 | - 'event_espresso' |
|
507 | - ) |
|
508 | - ? $tkt['TKT_description'] |
|
509 | - : '', |
|
510 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
511 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
512 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
513 | - ? EE_INF |
|
514 | - : $tkt['TKT_qty'], |
|
515 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
516 | - ? EE_INF |
|
517 | - : $tkt['TKT_uses'], |
|
518 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
519 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
520 | - 'TKT_row' => $row, |
|
521 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
522 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
523 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
524 | - 'TKT_price' => $ticket_price, |
|
525 | - ); |
|
526 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
527 | - // which means in turn that the prices will become new prices as well. |
|
528 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
529 | - $TKT_values['TKT_ID'] = 0; |
|
530 | - $TKT_values['TKT_is_default'] = 0; |
|
531 | - $update_prices = true; |
|
532 | - } |
|
533 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
534 | - // we actually do our saves ahead of doing any add_relations to |
|
535 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
536 | - // but DID have it's items modified. |
|
537 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
538 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
539 | - if (absint($TKT_values['TKT_ID'])) { |
|
540 | - $ticket = EE_Registry::instance() |
|
541 | - ->load_model('Ticket', array($timezone)) |
|
542 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
543 | - if ($ticket instanceof EE_Ticket) { |
|
544 | - $ticket = $this->_update_ticket_datetimes( |
|
545 | - $ticket, |
|
546 | - $saved_datetimes, |
|
547 | - $datetimes_added, |
|
548 | - $datetimes_removed |
|
549 | - ); |
|
550 | - // are there any registrations using this ticket ? |
|
551 | - $tickets_sold = $ticket->count_related( |
|
552 | - 'Registration', |
|
553 | - array( |
|
554 | - array( |
|
555 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
556 | - ), |
|
557 | - ) |
|
558 | - ); |
|
559 | - // set ticket formats |
|
560 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
561 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
562 | - // let's just check the total price for the existing ticket |
|
563 | - // and determine if it matches the new total price. |
|
564 | - // if they are different then we create a new ticket (if tickets sold) |
|
565 | - // if they aren't different then we go ahead and modify existing ticket. |
|
566 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
567 | - // set new values |
|
568 | - foreach ($TKT_values as $field => $value) { |
|
569 | - if ($field === 'TKT_qty') { |
|
570 | - $ticket->set_qty($value); |
|
571 | - } else { |
|
572 | - $ticket->set($field, $value); |
|
573 | - } |
|
574 | - } |
|
575 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
576 | - // Otherwise we have to create a new ticket. |
|
577 | - if ($create_new_TKT) { |
|
578 | - $new_tkt = $this->_duplicate_ticket( |
|
579 | - $ticket, |
|
580 | - $price_rows, |
|
581 | - $ticket_price, |
|
582 | - $base_price, |
|
583 | - $base_price_id |
|
584 | - ); |
|
585 | - } |
|
586 | - } |
|
587 | - } else { |
|
588 | - // no TKT_id so a new TKT |
|
589 | - $ticket = EE_Ticket::new_instance( |
|
590 | - $TKT_values, |
|
591 | - $timezone, |
|
592 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
593 | - ); |
|
594 | - if ($ticket instanceof EE_Ticket) { |
|
595 | - // make sure ticket has an ID of setting relations won't work |
|
596 | - $ticket->save(); |
|
597 | - $ticket = $this->_update_ticket_datetimes( |
|
598 | - $ticket, |
|
599 | - $saved_datetimes, |
|
600 | - $datetimes_added, |
|
601 | - $datetimes_removed |
|
602 | - ); |
|
603 | - $update_prices = true; |
|
604 | - } |
|
605 | - } |
|
606 | - // make sure any current values have been saved. |
|
607 | - // $ticket->save(); |
|
608 | - // before going any further make sure our dates are setup correctly |
|
609 | - // so that the end date is always equal or greater than the start date. |
|
610 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
611 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
612 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
613 | - } |
|
614 | - // let's make sure the base price is handled |
|
615 | - $ticket = ! $create_new_TKT |
|
616 | - ? $this->_add_prices_to_ticket( |
|
617 | - array(), |
|
618 | - $ticket, |
|
619 | - $update_prices, |
|
620 | - $base_price, |
|
621 | - $base_price_id |
|
622 | - ) |
|
623 | - : $ticket; |
|
624 | - // add/update price_modifiers |
|
625 | - $ticket = ! $create_new_TKT |
|
626 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
627 | - : $ticket; |
|
628 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
629 | - $ticket->ensure_TKT_Price_correct(); |
|
630 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
631 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
632 | - $update_prices = true; |
|
633 | - $new_default = clone $ticket; |
|
634 | - $new_default->set('TKT_ID', 0); |
|
635 | - $new_default->set('TKT_is_default', 1); |
|
636 | - $new_default->set('TKT_row', 1); |
|
637 | - $new_default->set('TKT_price', $ticket_price); |
|
638 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
639 | - // (note this is just removing the cached relations in the object) |
|
640 | - $new_default->_remove_relations('Datetime'); |
|
641 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
642 | - $new_default = $this->_add_prices_to_ticket( |
|
643 | - $price_rows, |
|
644 | - $new_default, |
|
645 | - $update_prices |
|
646 | - ); |
|
647 | - // don't forget the base price! |
|
648 | - $new_default = $this->_add_prices_to_ticket( |
|
649 | - array(), |
|
650 | - $new_default, |
|
651 | - $update_prices, |
|
652 | - $base_price, |
|
653 | - $base_price_id |
|
654 | - ); |
|
655 | - $new_default->save(); |
|
656 | - do_action( |
|
657 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
658 | - $new_default, |
|
659 | - $row, |
|
660 | - $ticket, |
|
661 | - $data |
|
662 | - ); |
|
663 | - } |
|
664 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
665 | - // for the given dtt that are related to the current ticket. |
|
666 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
667 | - // what current ticket the archived tickets are related to |
|
668 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
669 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
670 | - // save existing TKT |
|
671 | - $ticket->save(); |
|
672 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
673 | - // save new TKT |
|
674 | - $new_tkt->save(); |
|
675 | - // add new ticket to array |
|
676 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
677 | - do_action( |
|
678 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
679 | - $new_tkt, |
|
680 | - $row, |
|
681 | - $tkt, |
|
682 | - $data |
|
683 | - ); |
|
684 | - } else { |
|
685 | - // add tkt to saved tkts |
|
686 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
687 | - do_action( |
|
688 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
689 | - $ticket, |
|
690 | - $row, |
|
691 | - $tkt, |
|
692 | - $data |
|
693 | - ); |
|
694 | - } |
|
695 | - } |
|
696 | - // now we need to handle tickets actually "deleted permanently". |
|
697 | - // There are cases where we'd want this to happen |
|
698 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
699 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
700 | - // No sense in keeping all the related data in the db! |
|
701 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
702 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
703 | - foreach ($tickets_removed as $id) { |
|
704 | - $id = absint($id); |
|
705 | - // get the ticket for this id |
|
706 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
707 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
708 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
709 | - continue; |
|
710 | - } |
|
711 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
712 | - // because we don't actually permanently delete these tickets. |
|
713 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
714 | - $tkt_to_remove->delete(); |
|
715 | - continue; |
|
716 | - } |
|
717 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
718 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
719 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
720 | - foreach ($datetimes as $datetime) { |
|
721 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
722 | - } |
|
723 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
724 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
725 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
726 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
727 | - // finally let's delete this ticket |
|
728 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
729 | - $tkt_to_remove->delete_permanently(); |
|
730 | - } |
|
731 | - return $saved_tickets; |
|
732 | - } |
|
420 | + /** |
|
421 | + * update tickets |
|
422 | + * |
|
423 | + * @param EE_Event $event Event object being updated |
|
424 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
425 | + * @param array $data incoming request data |
|
426 | + * @return EE_Ticket[] |
|
427 | + * @throws Exception |
|
428 | + * @throws ReflectionException |
|
429 | + * @throws InvalidInterfaceException |
|
430 | + * @throws InvalidDataTypeException |
|
431 | + * @throws InvalidArgumentException |
|
432 | + * @throws EE_Error |
|
433 | + */ |
|
434 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
435 | + { |
|
436 | + $new_tkt = null; |
|
437 | + $new_default = null; |
|
438 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
439 | + $data = stripslashes_deep($data); |
|
440 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
441 | + $saved_tickets = $datetimes_on_existing = array(); |
|
442 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
443 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
444 | + throw new InvalidArgumentException( |
|
445 | + esc_html__( |
|
446 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
447 | + 'event_espresso' |
|
448 | + ) |
|
449 | + ); |
|
450 | + } |
|
451 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
452 | + $update_prices = $create_new_TKT = false; |
|
453 | + // figure out what datetimes were added to the ticket |
|
454 | + // and what datetimes were removed from the ticket in the session. |
|
455 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
456 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
457 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
458 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
459 | + // trim inputs to ensure any excess whitespace is removed. |
|
460 | + $tkt = array_map( |
|
461 | + function ($ticket_data) { |
|
462 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
463 | + }, |
|
464 | + $tkt |
|
465 | + ); |
|
466 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
467 | + // because we're doing calculations prior to using the models. |
|
468 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
469 | + $ticket_price = isset($tkt['TKT_price']) |
|
470 | + ? round((float) $tkt['TKT_price'], 3) |
|
471 | + : 0; |
|
472 | + // note incoming base price needs converted from localized value. |
|
473 | + $base_price = isset($tkt['TKT_base_price']) |
|
474 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
475 | + : 0; |
|
476 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
477 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
478 | + ? $base_price |
|
479 | + : $ticket_price; |
|
480 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
481 | + ? $tkt['TKT_base_price_ID'] |
|
482 | + : 0; |
|
483 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
484 | + ? $data['edit_prices'][ $row ] |
|
485 | + : array(); |
|
486 | + $now = null; |
|
487 | + if (empty($tkt['TKT_start_date'])) { |
|
488 | + // lets' use now in the set timezone. |
|
489 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
490 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
491 | + } |
|
492 | + if (empty($tkt['TKT_end_date'])) { |
|
493 | + /** |
|
494 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
495 | + */ |
|
496 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
497 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
498 | + } |
|
499 | + $TKT_values = array( |
|
500 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
501 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
502 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
503 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
504 | + && $tkt['TKT_description'] !== esc_html__( |
|
505 | + 'You can modify this description', |
|
506 | + 'event_espresso' |
|
507 | + ) |
|
508 | + ? $tkt['TKT_description'] |
|
509 | + : '', |
|
510 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
511 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
512 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
513 | + ? EE_INF |
|
514 | + : $tkt['TKT_qty'], |
|
515 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
516 | + ? EE_INF |
|
517 | + : $tkt['TKT_uses'], |
|
518 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
519 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
520 | + 'TKT_row' => $row, |
|
521 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
522 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
523 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
524 | + 'TKT_price' => $ticket_price, |
|
525 | + ); |
|
526 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
527 | + // which means in turn that the prices will become new prices as well. |
|
528 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
529 | + $TKT_values['TKT_ID'] = 0; |
|
530 | + $TKT_values['TKT_is_default'] = 0; |
|
531 | + $update_prices = true; |
|
532 | + } |
|
533 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
534 | + // we actually do our saves ahead of doing any add_relations to |
|
535 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
536 | + // but DID have it's items modified. |
|
537 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
538 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
539 | + if (absint($TKT_values['TKT_ID'])) { |
|
540 | + $ticket = EE_Registry::instance() |
|
541 | + ->load_model('Ticket', array($timezone)) |
|
542 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
543 | + if ($ticket instanceof EE_Ticket) { |
|
544 | + $ticket = $this->_update_ticket_datetimes( |
|
545 | + $ticket, |
|
546 | + $saved_datetimes, |
|
547 | + $datetimes_added, |
|
548 | + $datetimes_removed |
|
549 | + ); |
|
550 | + // are there any registrations using this ticket ? |
|
551 | + $tickets_sold = $ticket->count_related( |
|
552 | + 'Registration', |
|
553 | + array( |
|
554 | + array( |
|
555 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
556 | + ), |
|
557 | + ) |
|
558 | + ); |
|
559 | + // set ticket formats |
|
560 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
561 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
562 | + // let's just check the total price for the existing ticket |
|
563 | + // and determine if it matches the new total price. |
|
564 | + // if they are different then we create a new ticket (if tickets sold) |
|
565 | + // if they aren't different then we go ahead and modify existing ticket. |
|
566 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
567 | + // set new values |
|
568 | + foreach ($TKT_values as $field => $value) { |
|
569 | + if ($field === 'TKT_qty') { |
|
570 | + $ticket->set_qty($value); |
|
571 | + } else { |
|
572 | + $ticket->set($field, $value); |
|
573 | + } |
|
574 | + } |
|
575 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
576 | + // Otherwise we have to create a new ticket. |
|
577 | + if ($create_new_TKT) { |
|
578 | + $new_tkt = $this->_duplicate_ticket( |
|
579 | + $ticket, |
|
580 | + $price_rows, |
|
581 | + $ticket_price, |
|
582 | + $base_price, |
|
583 | + $base_price_id |
|
584 | + ); |
|
585 | + } |
|
586 | + } |
|
587 | + } else { |
|
588 | + // no TKT_id so a new TKT |
|
589 | + $ticket = EE_Ticket::new_instance( |
|
590 | + $TKT_values, |
|
591 | + $timezone, |
|
592 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
593 | + ); |
|
594 | + if ($ticket instanceof EE_Ticket) { |
|
595 | + // make sure ticket has an ID of setting relations won't work |
|
596 | + $ticket->save(); |
|
597 | + $ticket = $this->_update_ticket_datetimes( |
|
598 | + $ticket, |
|
599 | + $saved_datetimes, |
|
600 | + $datetimes_added, |
|
601 | + $datetimes_removed |
|
602 | + ); |
|
603 | + $update_prices = true; |
|
604 | + } |
|
605 | + } |
|
606 | + // make sure any current values have been saved. |
|
607 | + // $ticket->save(); |
|
608 | + // before going any further make sure our dates are setup correctly |
|
609 | + // so that the end date is always equal or greater than the start date. |
|
610 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
611 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
612 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
613 | + } |
|
614 | + // let's make sure the base price is handled |
|
615 | + $ticket = ! $create_new_TKT |
|
616 | + ? $this->_add_prices_to_ticket( |
|
617 | + array(), |
|
618 | + $ticket, |
|
619 | + $update_prices, |
|
620 | + $base_price, |
|
621 | + $base_price_id |
|
622 | + ) |
|
623 | + : $ticket; |
|
624 | + // add/update price_modifiers |
|
625 | + $ticket = ! $create_new_TKT |
|
626 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
627 | + : $ticket; |
|
628 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
629 | + $ticket->ensure_TKT_Price_correct(); |
|
630 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
631 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
632 | + $update_prices = true; |
|
633 | + $new_default = clone $ticket; |
|
634 | + $new_default->set('TKT_ID', 0); |
|
635 | + $new_default->set('TKT_is_default', 1); |
|
636 | + $new_default->set('TKT_row', 1); |
|
637 | + $new_default->set('TKT_price', $ticket_price); |
|
638 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
639 | + // (note this is just removing the cached relations in the object) |
|
640 | + $new_default->_remove_relations('Datetime'); |
|
641 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
642 | + $new_default = $this->_add_prices_to_ticket( |
|
643 | + $price_rows, |
|
644 | + $new_default, |
|
645 | + $update_prices |
|
646 | + ); |
|
647 | + // don't forget the base price! |
|
648 | + $new_default = $this->_add_prices_to_ticket( |
|
649 | + array(), |
|
650 | + $new_default, |
|
651 | + $update_prices, |
|
652 | + $base_price, |
|
653 | + $base_price_id |
|
654 | + ); |
|
655 | + $new_default->save(); |
|
656 | + do_action( |
|
657 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
658 | + $new_default, |
|
659 | + $row, |
|
660 | + $ticket, |
|
661 | + $data |
|
662 | + ); |
|
663 | + } |
|
664 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
665 | + // for the given dtt that are related to the current ticket. |
|
666 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
667 | + // what current ticket the archived tickets are related to |
|
668 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
669 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
670 | + // save existing TKT |
|
671 | + $ticket->save(); |
|
672 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
673 | + // save new TKT |
|
674 | + $new_tkt->save(); |
|
675 | + // add new ticket to array |
|
676 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
677 | + do_action( |
|
678 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
679 | + $new_tkt, |
|
680 | + $row, |
|
681 | + $tkt, |
|
682 | + $data |
|
683 | + ); |
|
684 | + } else { |
|
685 | + // add tkt to saved tkts |
|
686 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
687 | + do_action( |
|
688 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
689 | + $ticket, |
|
690 | + $row, |
|
691 | + $tkt, |
|
692 | + $data |
|
693 | + ); |
|
694 | + } |
|
695 | + } |
|
696 | + // now we need to handle tickets actually "deleted permanently". |
|
697 | + // There are cases where we'd want this to happen |
|
698 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
699 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
700 | + // No sense in keeping all the related data in the db! |
|
701 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
702 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
703 | + foreach ($tickets_removed as $id) { |
|
704 | + $id = absint($id); |
|
705 | + // get the ticket for this id |
|
706 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
707 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
708 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
709 | + continue; |
|
710 | + } |
|
711 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
712 | + // because we don't actually permanently delete these tickets. |
|
713 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
714 | + $tkt_to_remove->delete(); |
|
715 | + continue; |
|
716 | + } |
|
717 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
718 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
719 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
720 | + foreach ($datetimes as $datetime) { |
|
721 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
722 | + } |
|
723 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
724 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
725 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
726 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
727 | + // finally let's delete this ticket |
|
728 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
729 | + $tkt_to_remove->delete_permanently(); |
|
730 | + } |
|
731 | + return $saved_tickets; |
|
732 | + } |
|
733 | 733 | |
734 | 734 | |
735 | - /** |
|
736 | - * @access protected |
|
737 | - * @param EE_Ticket $ticket |
|
738 | - * @param \EE_Datetime[] $saved_datetimes |
|
739 | - * @param \EE_Datetime[] $added_datetimes |
|
740 | - * @param \EE_Datetime[] $removed_datetimes |
|
741 | - * @return EE_Ticket |
|
742 | - * @throws EE_Error |
|
743 | - */ |
|
744 | - protected function _update_ticket_datetimes( |
|
745 | - EE_Ticket $ticket, |
|
746 | - $saved_datetimes = array(), |
|
747 | - $added_datetimes = array(), |
|
748 | - $removed_datetimes = array() |
|
749 | - ) { |
|
750 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
751 | - // and removing the ticket from datetimes it got removed from. |
|
752 | - // first let's add datetimes |
|
753 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
754 | - foreach ($added_datetimes as $row_id) { |
|
755 | - $row_id = (int) $row_id; |
|
756 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
757 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
758 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
759 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
760 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
761 | - $saved_datetimes[ $row_id ]->increase_sold($ticket->sold()); |
|
762 | - $saved_datetimes[ $row_id ]->save(); |
|
763 | - } |
|
764 | - } |
|
765 | - } |
|
766 | - } |
|
767 | - // then remove datetimes |
|
768 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
769 | - foreach ($removed_datetimes as $row_id) { |
|
770 | - $row_id = (int) $row_id; |
|
771 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
772 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
773 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
774 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
775 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
776 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
777 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
778 | - $saved_datetimes[ $row_id ]->decrease_sold($ticket->sold()); |
|
779 | - $saved_datetimes[ $row_id ]->save(); |
|
780 | - } |
|
781 | - } |
|
782 | - } |
|
783 | - } |
|
784 | - // cap ticket qty by datetime reg limits |
|
785 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
786 | - return $ticket; |
|
787 | - } |
|
735 | + /** |
|
736 | + * @access protected |
|
737 | + * @param EE_Ticket $ticket |
|
738 | + * @param \EE_Datetime[] $saved_datetimes |
|
739 | + * @param \EE_Datetime[] $added_datetimes |
|
740 | + * @param \EE_Datetime[] $removed_datetimes |
|
741 | + * @return EE_Ticket |
|
742 | + * @throws EE_Error |
|
743 | + */ |
|
744 | + protected function _update_ticket_datetimes( |
|
745 | + EE_Ticket $ticket, |
|
746 | + $saved_datetimes = array(), |
|
747 | + $added_datetimes = array(), |
|
748 | + $removed_datetimes = array() |
|
749 | + ) { |
|
750 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
751 | + // and removing the ticket from datetimes it got removed from. |
|
752 | + // first let's add datetimes |
|
753 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
754 | + foreach ($added_datetimes as $row_id) { |
|
755 | + $row_id = (int) $row_id; |
|
756 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
757 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
758 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
759 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
760 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
761 | + $saved_datetimes[ $row_id ]->increase_sold($ticket->sold()); |
|
762 | + $saved_datetimes[ $row_id ]->save(); |
|
763 | + } |
|
764 | + } |
|
765 | + } |
|
766 | + } |
|
767 | + // then remove datetimes |
|
768 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
769 | + foreach ($removed_datetimes as $row_id) { |
|
770 | + $row_id = (int) $row_id; |
|
771 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
772 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
773 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
774 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
775 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
776 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
777 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
778 | + $saved_datetimes[ $row_id ]->decrease_sold($ticket->sold()); |
|
779 | + $saved_datetimes[ $row_id ]->save(); |
|
780 | + } |
|
781 | + } |
|
782 | + } |
|
783 | + } |
|
784 | + // cap ticket qty by datetime reg limits |
|
785 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
786 | + return $ticket; |
|
787 | + } |
|
788 | 788 | |
789 | 789 | |
790 | - /** |
|
791 | - * @access protected |
|
792 | - * @param EE_Ticket $ticket |
|
793 | - * @param array $price_rows |
|
794 | - * @param int $ticket_price |
|
795 | - * @param int $base_price |
|
796 | - * @param int $base_price_id |
|
797 | - * @return EE_Ticket |
|
798 | - * @throws ReflectionException |
|
799 | - * @throws InvalidArgumentException |
|
800 | - * @throws InvalidInterfaceException |
|
801 | - * @throws InvalidDataTypeException |
|
802 | - * @throws EE_Error |
|
803 | - */ |
|
804 | - protected function _duplicate_ticket( |
|
805 | - EE_Ticket $ticket, |
|
806 | - $price_rows = array(), |
|
807 | - $ticket_price = 0, |
|
808 | - $base_price = 0, |
|
809 | - $base_price_id = 0 |
|
810 | - ) { |
|
811 | - // create new ticket that's a copy of the existing |
|
812 | - // except a new id of course (and not archived) |
|
813 | - // AND has the new TKT_price associated with it. |
|
814 | - $new_ticket = clone $ticket; |
|
815 | - $new_ticket->set('TKT_ID', 0); |
|
816 | - $new_ticket->set_deleted(0); |
|
817 | - $new_ticket->set_price($ticket_price); |
|
818 | - $new_ticket->set_sold(0); |
|
819 | - // let's get a new ID for this ticket |
|
820 | - $new_ticket->save(); |
|
821 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
822 | - $datetimes_on_existing = $ticket->datetimes(); |
|
823 | - $new_ticket = $this->_update_ticket_datetimes( |
|
824 | - $new_ticket, |
|
825 | - $datetimes_on_existing, |
|
826 | - array_keys($datetimes_on_existing) |
|
827 | - ); |
|
828 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
829 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
830 | - // available. |
|
831 | - if ($ticket->sold() > 0) { |
|
832 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
833 | - $new_ticket->set_qty($new_qty); |
|
834 | - } |
|
835 | - // now we update the prices just for this ticket |
|
836 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
837 | - // and we update the base price |
|
838 | - $new_ticket = $this->_add_prices_to_ticket( |
|
839 | - array(), |
|
840 | - $new_ticket, |
|
841 | - true, |
|
842 | - $base_price, |
|
843 | - $base_price_id |
|
844 | - ); |
|
845 | - return $new_ticket; |
|
846 | - } |
|
790 | + /** |
|
791 | + * @access protected |
|
792 | + * @param EE_Ticket $ticket |
|
793 | + * @param array $price_rows |
|
794 | + * @param int $ticket_price |
|
795 | + * @param int $base_price |
|
796 | + * @param int $base_price_id |
|
797 | + * @return EE_Ticket |
|
798 | + * @throws ReflectionException |
|
799 | + * @throws InvalidArgumentException |
|
800 | + * @throws InvalidInterfaceException |
|
801 | + * @throws InvalidDataTypeException |
|
802 | + * @throws EE_Error |
|
803 | + */ |
|
804 | + protected function _duplicate_ticket( |
|
805 | + EE_Ticket $ticket, |
|
806 | + $price_rows = array(), |
|
807 | + $ticket_price = 0, |
|
808 | + $base_price = 0, |
|
809 | + $base_price_id = 0 |
|
810 | + ) { |
|
811 | + // create new ticket that's a copy of the existing |
|
812 | + // except a new id of course (and not archived) |
|
813 | + // AND has the new TKT_price associated with it. |
|
814 | + $new_ticket = clone $ticket; |
|
815 | + $new_ticket->set('TKT_ID', 0); |
|
816 | + $new_ticket->set_deleted(0); |
|
817 | + $new_ticket->set_price($ticket_price); |
|
818 | + $new_ticket->set_sold(0); |
|
819 | + // let's get a new ID for this ticket |
|
820 | + $new_ticket->save(); |
|
821 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
822 | + $datetimes_on_existing = $ticket->datetimes(); |
|
823 | + $new_ticket = $this->_update_ticket_datetimes( |
|
824 | + $new_ticket, |
|
825 | + $datetimes_on_existing, |
|
826 | + array_keys($datetimes_on_existing) |
|
827 | + ); |
|
828 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
829 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
830 | + // available. |
|
831 | + if ($ticket->sold() > 0) { |
|
832 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
833 | + $new_ticket->set_qty($new_qty); |
|
834 | + } |
|
835 | + // now we update the prices just for this ticket |
|
836 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
837 | + // and we update the base price |
|
838 | + $new_ticket = $this->_add_prices_to_ticket( |
|
839 | + array(), |
|
840 | + $new_ticket, |
|
841 | + true, |
|
842 | + $base_price, |
|
843 | + $base_price_id |
|
844 | + ); |
|
845 | + return $new_ticket; |
|
846 | + } |
|
847 | 847 | |
848 | 848 | |
849 | - /** |
|
850 | - * This attaches a list of given prices to a ticket. |
|
851 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
852 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
853 | - * price info and prices are automatically "archived" via the ticket. |
|
854 | - * |
|
855 | - * @access private |
|
856 | - * @param array $prices Array of prices from the form. |
|
857 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
858 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
859 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
860 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
861 | - * @return EE_Ticket |
|
862 | - * @throws ReflectionException |
|
863 | - * @throws InvalidArgumentException |
|
864 | - * @throws InvalidInterfaceException |
|
865 | - * @throws InvalidDataTypeException |
|
866 | - * @throws EE_Error |
|
867 | - */ |
|
868 | - protected function _add_prices_to_ticket( |
|
869 | - $prices = array(), |
|
870 | - EE_Ticket $ticket, |
|
871 | - $new_prices = false, |
|
872 | - $base_price = false, |
|
873 | - $base_price_id = false |
|
874 | - ) { |
|
875 | - // let's just get any current prices that may exist on the given ticket |
|
876 | - // so we can remove any prices that got trashed in this session. |
|
877 | - $current_prices_on_ticket = $base_price !== false |
|
878 | - ? $ticket->base_price(true) |
|
879 | - : $ticket->price_modifiers(); |
|
880 | - $updated_prices = array(); |
|
881 | - // if $base_price ! FALSE then updating a base price. |
|
882 | - if ($base_price !== false) { |
|
883 | - $prices[1] = array( |
|
884 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
885 | - 'PRT_ID' => 1, |
|
886 | - 'PRC_amount' => $base_price, |
|
887 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
888 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
889 | - ); |
|
890 | - } |
|
891 | - // possibly need to save tkt |
|
892 | - if (! $ticket->ID()) { |
|
893 | - $ticket->save(); |
|
894 | - } |
|
895 | - foreach ($prices as $row => $prc) { |
|
896 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
897 | - if (empty($prt_id)) { |
|
898 | - continue; |
|
899 | - } //prices MUST have a price type id. |
|
900 | - $PRC_values = array( |
|
901 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
902 | - 'PRT_ID' => $prt_id, |
|
903 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
904 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
905 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
906 | - 'PRC_is_default' => false, |
|
907 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
908 | - 'PRC_order' => $row, |
|
909 | - ); |
|
910 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
911 | - $PRC_values['PRC_ID'] = 0; |
|
912 | - $price = EE_Registry::instance()->load_class( |
|
913 | - 'Price', |
|
914 | - array($PRC_values), |
|
915 | - false, |
|
916 | - false |
|
917 | - ); |
|
918 | - } else { |
|
919 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
920 | - // update this price with new values |
|
921 | - foreach ($PRC_values as $field => $value) { |
|
922 | - $price->set($field, $value); |
|
923 | - } |
|
924 | - } |
|
925 | - $price->save(); |
|
926 | - $updated_prices[ $price->ID() ] = $price; |
|
927 | - $ticket->_add_relation_to($price, 'Price'); |
|
928 | - } |
|
929 | - // now let's remove any prices that got removed from the ticket |
|
930 | - if (! empty($current_prices_on_ticket)) { |
|
931 | - $current = array_keys($current_prices_on_ticket); |
|
932 | - $updated = array_keys($updated_prices); |
|
933 | - $prices_to_remove = array_diff($current, $updated); |
|
934 | - if (! empty($prices_to_remove)) { |
|
935 | - foreach ($prices_to_remove as $prc_id) { |
|
936 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
937 | - $ticket->_remove_relation_to($p, 'Price'); |
|
938 | - // delete permanently the price |
|
939 | - $p->delete_permanently(); |
|
940 | - } |
|
941 | - } |
|
942 | - } |
|
943 | - return $ticket; |
|
944 | - } |
|
849 | + /** |
|
850 | + * This attaches a list of given prices to a ticket. |
|
851 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
852 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
853 | + * price info and prices are automatically "archived" via the ticket. |
|
854 | + * |
|
855 | + * @access private |
|
856 | + * @param array $prices Array of prices from the form. |
|
857 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
858 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
859 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
860 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
861 | + * @return EE_Ticket |
|
862 | + * @throws ReflectionException |
|
863 | + * @throws InvalidArgumentException |
|
864 | + * @throws InvalidInterfaceException |
|
865 | + * @throws InvalidDataTypeException |
|
866 | + * @throws EE_Error |
|
867 | + */ |
|
868 | + protected function _add_prices_to_ticket( |
|
869 | + $prices = array(), |
|
870 | + EE_Ticket $ticket, |
|
871 | + $new_prices = false, |
|
872 | + $base_price = false, |
|
873 | + $base_price_id = false |
|
874 | + ) { |
|
875 | + // let's just get any current prices that may exist on the given ticket |
|
876 | + // so we can remove any prices that got trashed in this session. |
|
877 | + $current_prices_on_ticket = $base_price !== false |
|
878 | + ? $ticket->base_price(true) |
|
879 | + : $ticket->price_modifiers(); |
|
880 | + $updated_prices = array(); |
|
881 | + // if $base_price ! FALSE then updating a base price. |
|
882 | + if ($base_price !== false) { |
|
883 | + $prices[1] = array( |
|
884 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
885 | + 'PRT_ID' => 1, |
|
886 | + 'PRC_amount' => $base_price, |
|
887 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
888 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
889 | + ); |
|
890 | + } |
|
891 | + // possibly need to save tkt |
|
892 | + if (! $ticket->ID()) { |
|
893 | + $ticket->save(); |
|
894 | + } |
|
895 | + foreach ($prices as $row => $prc) { |
|
896 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
897 | + if (empty($prt_id)) { |
|
898 | + continue; |
|
899 | + } //prices MUST have a price type id. |
|
900 | + $PRC_values = array( |
|
901 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
902 | + 'PRT_ID' => $prt_id, |
|
903 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
904 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
905 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
906 | + 'PRC_is_default' => false, |
|
907 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
908 | + 'PRC_order' => $row, |
|
909 | + ); |
|
910 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
911 | + $PRC_values['PRC_ID'] = 0; |
|
912 | + $price = EE_Registry::instance()->load_class( |
|
913 | + 'Price', |
|
914 | + array($PRC_values), |
|
915 | + false, |
|
916 | + false |
|
917 | + ); |
|
918 | + } else { |
|
919 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
920 | + // update this price with new values |
|
921 | + foreach ($PRC_values as $field => $value) { |
|
922 | + $price->set($field, $value); |
|
923 | + } |
|
924 | + } |
|
925 | + $price->save(); |
|
926 | + $updated_prices[ $price->ID() ] = $price; |
|
927 | + $ticket->_add_relation_to($price, 'Price'); |
|
928 | + } |
|
929 | + // now let's remove any prices that got removed from the ticket |
|
930 | + if (! empty($current_prices_on_ticket)) { |
|
931 | + $current = array_keys($current_prices_on_ticket); |
|
932 | + $updated = array_keys($updated_prices); |
|
933 | + $prices_to_remove = array_diff($current, $updated); |
|
934 | + if (! empty($prices_to_remove)) { |
|
935 | + foreach ($prices_to_remove as $prc_id) { |
|
936 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
937 | + $ticket->_remove_relation_to($p, 'Price'); |
|
938 | + // delete permanently the price |
|
939 | + $p->delete_permanently(); |
|
940 | + } |
|
941 | + } |
|
942 | + } |
|
943 | + return $ticket; |
|
944 | + } |
|
945 | 945 | |
946 | 946 | |
947 | - /** |
|
948 | - * @param Events_Admin_Page $event_admin_obj |
|
949 | - * @return Events_Admin_Page |
|
950 | - */ |
|
951 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
952 | - { |
|
953 | - return $event_admin_obj; |
|
954 | - // doing nothing for the moment. |
|
955 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
956 | - // (use the set_template_args() method) |
|
957 | - /** |
|
958 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
959 | - * 1. TKT_is_default_selector (visible) |
|
960 | - * 2. TKT_is_default (hidden) |
|
961 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
962 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
963 | - * this ticket to be saved as a default. |
|
964 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
965 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
966 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
967 | - * the TKT HAS been saved as a default.. |
|
968 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
969 | - * On Autosave: |
|
970 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
971 | - * then set the TKT_is_default to false. |
|
972 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
973 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
974 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
975 | - */ |
|
976 | - } |
|
947 | + /** |
|
948 | + * @param Events_Admin_Page $event_admin_obj |
|
949 | + * @return Events_Admin_Page |
|
950 | + */ |
|
951 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
952 | + { |
|
953 | + return $event_admin_obj; |
|
954 | + // doing nothing for the moment. |
|
955 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
956 | + // (use the set_template_args() method) |
|
957 | + /** |
|
958 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
959 | + * 1. TKT_is_default_selector (visible) |
|
960 | + * 2. TKT_is_default (hidden) |
|
961 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
962 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
963 | + * this ticket to be saved as a default. |
|
964 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
965 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
966 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
967 | + * the TKT HAS been saved as a default.. |
|
968 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
969 | + * On Autosave: |
|
970 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
971 | + * then set the TKT_is_default to false. |
|
972 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
973 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
974 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
975 | + */ |
|
976 | + } |
|
977 | 977 | |
978 | 978 | |
979 | - /** |
|
980 | - * @throws ReflectionException |
|
981 | - * @throws InvalidArgumentException |
|
982 | - * @throws InvalidInterfaceException |
|
983 | - * @throws InvalidDataTypeException |
|
984 | - * @throws DomainException |
|
985 | - * @throws EE_Error |
|
986 | - */ |
|
987 | - public function pricing_metabox() |
|
988 | - { |
|
989 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
990 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
991 | - // set is_creating_event property. |
|
992 | - $EVT_ID = $event->ID(); |
|
993 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
994 | - // default main template args |
|
995 | - $main_template_args = array( |
|
996 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
997 | - 'event_editor_event_datetimes_help_tab', |
|
998 | - $this->_adminpage_obj->page_slug, |
|
999 | - $this->_adminpage_obj->get_req_action(), |
|
1000 | - false, |
|
1001 | - false |
|
1002 | - ), |
|
1003 | - // todo need to add a filter to the template for the help text |
|
1004 | - // in the Events_Admin_Page core file so we can add further help |
|
1005 | - 'existing_datetime_ids' => '', |
|
1006 | - 'total_dtt_rows' => 1, |
|
1007 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1008 | - 'add_new_dtt_info', |
|
1009 | - $this->_adminpage_obj->page_slug, |
|
1010 | - $this->_adminpage_obj->get_req_action(), |
|
1011 | - false, |
|
1012 | - false |
|
1013 | - ), |
|
1014 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1015 | - 'datetime_rows' => '', |
|
1016 | - 'show_tickets_container' => '', |
|
1017 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1018 | - 'ticket_rows' => '', |
|
1019 | - 'existing_ticket_ids' => '', |
|
1020 | - 'total_ticket_rows' => 1, |
|
1021 | - 'ticket_js_structure' => '', |
|
1022 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1023 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1024 | - ); |
|
1025 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1026 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | - /** |
|
1028 | - * 1. Start with retrieving Datetimes |
|
1029 | - * 2. For each datetime get related tickets |
|
1030 | - * 3. For each ticket get related prices |
|
1031 | - */ |
|
1032 | - /** @var EEM_Datetime $datetime_model */ |
|
1033 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1034 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1035 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1036 | - /** |
|
1037 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1038 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1039 | - */ |
|
1040 | - $datetime_row = 1; |
|
1041 | - foreach ($datetimes as $datetime) { |
|
1042 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1043 | - $datetime->set('DTT_order', $datetime_row); |
|
1044 | - $existing_datetime_ids[] = $DTT_ID; |
|
1045 | - // tickets attached |
|
1046 | - $related_tickets = $datetime->ID() > 0 |
|
1047 | - ? $datetime->get_many_related( |
|
1048 | - 'Ticket', |
|
1049 | - array( |
|
1050 | - array( |
|
1051 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1052 | - ), |
|
1053 | - 'default_where_conditions' => 'none', |
|
1054 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1055 | - ) |
|
1056 | - ) |
|
1057 | - : array(); |
|
1058 | - // if there are no related tickets this is likely a new event OR autodraft |
|
1059 | - // event so we need to generate the default tickets because datetimes |
|
1060 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1061 | - // datetime on the event. |
|
1062 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
1063 | - /** @var EEM_Ticket $ticket_model */ |
|
1064 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1065 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1066 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1067 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1068 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1069 | - $main_default_ticket = reset($related_tickets); |
|
1070 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1071 | - foreach ($default_prices as $default_price) { |
|
1072 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1073 | - continue; |
|
1074 | - } |
|
1075 | - $main_default_ticket->cache('Price', $default_price); |
|
1076 | - } |
|
1077 | - } |
|
1078 | - } |
|
1079 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1080 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1081 | - // So we're going to temporarily cache some of that information. |
|
1082 | - // loop through and setup the ticket rows and make sure the order is set. |
|
1083 | - foreach ($related_tickets as $ticket) { |
|
1084 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1085 | - $ticket_row = $ticket->get('TKT_row'); |
|
1086 | - // we only want unique tickets in our final display!! |
|
1087 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1088 | - $existing_ticket_ids[] = $TKT_ID; |
|
1089 | - $all_tickets[] = $ticket; |
|
1090 | - } |
|
1091 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1092 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1093 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1094 | - if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
1095 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1096 | - ) { |
|
1097 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1098 | - } |
|
1099 | - } |
|
1100 | - $datetime_row++; |
|
1101 | - } |
|
1102 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1103 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1104 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1105 | - // sort $all_tickets by order |
|
1106 | - usort( |
|
1107 | - $all_tickets, |
|
1108 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1109 | - $a_order = (int) $a->get('TKT_order'); |
|
1110 | - $b_order = (int) $b->get('TKT_order'); |
|
1111 | - if ($a_order === $b_order) { |
|
1112 | - return 0; |
|
1113 | - } |
|
1114 | - return ($a_order < $b_order) ? -1 : 1; |
|
1115 | - } |
|
1116 | - ); |
|
1117 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1118 | - // and ticket rows so we start our dtt loop again. |
|
1119 | - $datetime_row = 1; |
|
1120 | - foreach ($datetimes as $datetime) { |
|
1121 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1122 | - $datetime_row, |
|
1123 | - $datetime, |
|
1124 | - $datetime_tickets, |
|
1125 | - $all_tickets, |
|
1126 | - false, |
|
1127 | - $datetimes |
|
1128 | - ); |
|
1129 | - $datetime_row++; |
|
1130 | - } |
|
1131 | - // then loop through all tickets for the ticket rows. |
|
1132 | - $ticket_row = 1; |
|
1133 | - foreach ($all_tickets as $ticket) { |
|
1134 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1135 | - $ticket_row, |
|
1136 | - $ticket, |
|
1137 | - $ticket_datetimes, |
|
1138 | - $datetimes, |
|
1139 | - false, |
|
1140 | - $all_tickets |
|
1141 | - ); |
|
1142 | - $ticket_row++; |
|
1143 | - } |
|
1144 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1145 | - EEH_Template::display_template( |
|
1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1147 | - $main_template_args |
|
1148 | - ); |
|
1149 | - } |
|
979 | + /** |
|
980 | + * @throws ReflectionException |
|
981 | + * @throws InvalidArgumentException |
|
982 | + * @throws InvalidInterfaceException |
|
983 | + * @throws InvalidDataTypeException |
|
984 | + * @throws DomainException |
|
985 | + * @throws EE_Error |
|
986 | + */ |
|
987 | + public function pricing_metabox() |
|
988 | + { |
|
989 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
990 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
991 | + // set is_creating_event property. |
|
992 | + $EVT_ID = $event->ID(); |
|
993 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
994 | + // default main template args |
|
995 | + $main_template_args = array( |
|
996 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
997 | + 'event_editor_event_datetimes_help_tab', |
|
998 | + $this->_adminpage_obj->page_slug, |
|
999 | + $this->_adminpage_obj->get_req_action(), |
|
1000 | + false, |
|
1001 | + false |
|
1002 | + ), |
|
1003 | + // todo need to add a filter to the template for the help text |
|
1004 | + // in the Events_Admin_Page core file so we can add further help |
|
1005 | + 'existing_datetime_ids' => '', |
|
1006 | + 'total_dtt_rows' => 1, |
|
1007 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
1008 | + 'add_new_dtt_info', |
|
1009 | + $this->_adminpage_obj->page_slug, |
|
1010 | + $this->_adminpage_obj->get_req_action(), |
|
1011 | + false, |
|
1012 | + false |
|
1013 | + ), |
|
1014 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1015 | + 'datetime_rows' => '', |
|
1016 | + 'show_tickets_container' => '', |
|
1017 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
1018 | + 'ticket_rows' => '', |
|
1019 | + 'existing_ticket_ids' => '', |
|
1020 | + 'total_ticket_rows' => 1, |
|
1021 | + 'ticket_js_structure' => '', |
|
1022 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
1023 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
1024 | + ); |
|
1025 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
1026 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | + /** |
|
1028 | + * 1. Start with retrieving Datetimes |
|
1029 | + * 2. For each datetime get related tickets |
|
1030 | + * 3. For each ticket get related prices |
|
1031 | + */ |
|
1032 | + /** @var EEM_Datetime $datetime_model */ |
|
1033 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
1034 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
1035 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
1036 | + /** |
|
1037 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
1038 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
1039 | + */ |
|
1040 | + $datetime_row = 1; |
|
1041 | + foreach ($datetimes as $datetime) { |
|
1042 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1043 | + $datetime->set('DTT_order', $datetime_row); |
|
1044 | + $existing_datetime_ids[] = $DTT_ID; |
|
1045 | + // tickets attached |
|
1046 | + $related_tickets = $datetime->ID() > 0 |
|
1047 | + ? $datetime->get_many_related( |
|
1048 | + 'Ticket', |
|
1049 | + array( |
|
1050 | + array( |
|
1051 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1052 | + ), |
|
1053 | + 'default_where_conditions' => 'none', |
|
1054 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1055 | + ) |
|
1056 | + ) |
|
1057 | + : array(); |
|
1058 | + // if there are no related tickets this is likely a new event OR autodraft |
|
1059 | + // event so we need to generate the default tickets because datetimes |
|
1060 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1061 | + // datetime on the event. |
|
1062 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
1063 | + /** @var EEM_Ticket $ticket_model */ |
|
1064 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1065 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1066 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1067 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1068 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1069 | + $main_default_ticket = reset($related_tickets); |
|
1070 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1071 | + foreach ($default_prices as $default_price) { |
|
1072 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1073 | + continue; |
|
1074 | + } |
|
1075 | + $main_default_ticket->cache('Price', $default_price); |
|
1076 | + } |
|
1077 | + } |
|
1078 | + } |
|
1079 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1080 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1081 | + // So we're going to temporarily cache some of that information. |
|
1082 | + // loop through and setup the ticket rows and make sure the order is set. |
|
1083 | + foreach ($related_tickets as $ticket) { |
|
1084 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1085 | + $ticket_row = $ticket->get('TKT_row'); |
|
1086 | + // we only want unique tickets in our final display!! |
|
1087 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1088 | + $existing_ticket_ids[] = $TKT_ID; |
|
1089 | + $all_tickets[] = $ticket; |
|
1090 | + } |
|
1091 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1092 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1093 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1094 | + if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
1095 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1096 | + ) { |
|
1097 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1098 | + } |
|
1099 | + } |
|
1100 | + $datetime_row++; |
|
1101 | + } |
|
1102 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1103 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1104 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1105 | + // sort $all_tickets by order |
|
1106 | + usort( |
|
1107 | + $all_tickets, |
|
1108 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1109 | + $a_order = (int) $a->get('TKT_order'); |
|
1110 | + $b_order = (int) $b->get('TKT_order'); |
|
1111 | + if ($a_order === $b_order) { |
|
1112 | + return 0; |
|
1113 | + } |
|
1114 | + return ($a_order < $b_order) ? -1 : 1; |
|
1115 | + } |
|
1116 | + ); |
|
1117 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1118 | + // and ticket rows so we start our dtt loop again. |
|
1119 | + $datetime_row = 1; |
|
1120 | + foreach ($datetimes as $datetime) { |
|
1121 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1122 | + $datetime_row, |
|
1123 | + $datetime, |
|
1124 | + $datetime_tickets, |
|
1125 | + $all_tickets, |
|
1126 | + false, |
|
1127 | + $datetimes |
|
1128 | + ); |
|
1129 | + $datetime_row++; |
|
1130 | + } |
|
1131 | + // then loop through all tickets for the ticket rows. |
|
1132 | + $ticket_row = 1; |
|
1133 | + foreach ($all_tickets as $ticket) { |
|
1134 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1135 | + $ticket_row, |
|
1136 | + $ticket, |
|
1137 | + $ticket_datetimes, |
|
1138 | + $datetimes, |
|
1139 | + false, |
|
1140 | + $all_tickets |
|
1141 | + ); |
|
1142 | + $ticket_row++; |
|
1143 | + } |
|
1144 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1145 | + EEH_Template::display_template( |
|
1146 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1147 | + $main_template_args |
|
1148 | + ); |
|
1149 | + } |
|
1150 | 1150 | |
1151 | 1151 | |
1152 | - /** |
|
1153 | - * @param int $datetime_row |
|
1154 | - * @param EE_Datetime $datetime |
|
1155 | - * @param array $datetime_tickets |
|
1156 | - * @param array $all_tickets |
|
1157 | - * @param bool $default |
|
1158 | - * @param array $all_datetimes |
|
1159 | - * @return mixed |
|
1160 | - * @throws DomainException |
|
1161 | - * @throws EE_Error |
|
1162 | - */ |
|
1163 | - protected function _get_datetime_row( |
|
1164 | - $datetime_row, |
|
1165 | - EE_Datetime $datetime, |
|
1166 | - $datetime_tickets = array(), |
|
1167 | - $all_tickets = array(), |
|
1168 | - $default = false, |
|
1169 | - $all_datetimes = array() |
|
1170 | - ) { |
|
1171 | - $dtt_display_template_args = array( |
|
1172 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1173 | - $datetime_row, |
|
1174 | - $datetime, |
|
1175 | - $default, |
|
1176 | - $all_datetimes |
|
1177 | - ), |
|
1178 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1179 | - $datetime_row, |
|
1180 | - $datetime, |
|
1181 | - $datetime_tickets, |
|
1182 | - $all_tickets, |
|
1183 | - $default |
|
1184 | - ), |
|
1185 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1186 | - ); |
|
1187 | - return EEH_Template::display_template( |
|
1188 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1189 | - $dtt_display_template_args, |
|
1190 | - true |
|
1191 | - ); |
|
1192 | - } |
|
1152 | + /** |
|
1153 | + * @param int $datetime_row |
|
1154 | + * @param EE_Datetime $datetime |
|
1155 | + * @param array $datetime_tickets |
|
1156 | + * @param array $all_tickets |
|
1157 | + * @param bool $default |
|
1158 | + * @param array $all_datetimes |
|
1159 | + * @return mixed |
|
1160 | + * @throws DomainException |
|
1161 | + * @throws EE_Error |
|
1162 | + */ |
|
1163 | + protected function _get_datetime_row( |
|
1164 | + $datetime_row, |
|
1165 | + EE_Datetime $datetime, |
|
1166 | + $datetime_tickets = array(), |
|
1167 | + $all_tickets = array(), |
|
1168 | + $default = false, |
|
1169 | + $all_datetimes = array() |
|
1170 | + ) { |
|
1171 | + $dtt_display_template_args = array( |
|
1172 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
1173 | + $datetime_row, |
|
1174 | + $datetime, |
|
1175 | + $default, |
|
1176 | + $all_datetimes |
|
1177 | + ), |
|
1178 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1179 | + $datetime_row, |
|
1180 | + $datetime, |
|
1181 | + $datetime_tickets, |
|
1182 | + $all_tickets, |
|
1183 | + $default |
|
1184 | + ), |
|
1185 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1186 | + ); |
|
1187 | + return EEH_Template::display_template( |
|
1188 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1189 | + $dtt_display_template_args, |
|
1190 | + true |
|
1191 | + ); |
|
1192 | + } |
|
1193 | 1193 | |
1194 | 1194 | |
1195 | - /** |
|
1196 | - * This method is used to generate a dtt fields edit row. |
|
1197 | - * The same row is used to generate a row with valid DTT objects |
|
1198 | - * and the default row that is used as the skeleton by the js. |
|
1199 | - * |
|
1200 | - * @param int $datetime_row The row number for the row being generated. |
|
1201 | - * @param EE_Datetime $datetime |
|
1202 | - * @param bool $default Whether a default row is being generated or not. |
|
1203 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1204 | - * @return string |
|
1205 | - * @throws DomainException |
|
1206 | - * @throws EE_Error |
|
1207 | - */ |
|
1208 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1209 | - { |
|
1210 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1211 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1212 | - $template_args = array( |
|
1213 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1214 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1215 | - 'edit_dtt_expanded' => '', |
|
1216 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1217 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1218 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1219 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1220 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1221 | - 'DTT_reg_limit' => $default |
|
1222 | - ? '' |
|
1223 | - : $datetime->get_pretty( |
|
1224 | - 'DTT_reg_limit', |
|
1225 | - 'input' |
|
1226 | - ), |
|
1227 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1228 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1229 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1230 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1231 | - ? '' |
|
1232 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1233 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1234 | - ? 'ee-lock-icon' |
|
1235 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1236 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1237 | - ? '' |
|
1238 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1239 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1240 | - REG_ADMIN_URL |
|
1241 | - ), |
|
1242 | - ); |
|
1243 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1244 | - ? ' style="display:none"' |
|
1245 | - : ''; |
|
1246 | - // allow filtering of template args at this point. |
|
1247 | - $template_args = apply_filters( |
|
1248 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1249 | - $template_args, |
|
1250 | - $datetime_row, |
|
1251 | - $datetime, |
|
1252 | - $default, |
|
1253 | - $all_datetimes, |
|
1254 | - $this->_is_creating_event |
|
1255 | - ); |
|
1256 | - return EEH_Template::display_template( |
|
1257 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1258 | - $template_args, |
|
1259 | - true |
|
1260 | - ); |
|
1261 | - } |
|
1195 | + /** |
|
1196 | + * This method is used to generate a dtt fields edit row. |
|
1197 | + * The same row is used to generate a row with valid DTT objects |
|
1198 | + * and the default row that is used as the skeleton by the js. |
|
1199 | + * |
|
1200 | + * @param int $datetime_row The row number for the row being generated. |
|
1201 | + * @param EE_Datetime $datetime |
|
1202 | + * @param bool $default Whether a default row is being generated or not. |
|
1203 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1204 | + * @return string |
|
1205 | + * @throws DomainException |
|
1206 | + * @throws EE_Error |
|
1207 | + */ |
|
1208 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1209 | + { |
|
1210 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1211 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1212 | + $template_args = array( |
|
1213 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1214 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1215 | + 'edit_dtt_expanded' => '', |
|
1216 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1217 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1218 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1219 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1220 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1221 | + 'DTT_reg_limit' => $default |
|
1222 | + ? '' |
|
1223 | + : $datetime->get_pretty( |
|
1224 | + 'DTT_reg_limit', |
|
1225 | + 'input' |
|
1226 | + ), |
|
1227 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1228 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1229 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1230 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1231 | + ? '' |
|
1232 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1233 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1234 | + ? 'ee-lock-icon' |
|
1235 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1236 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1237 | + ? '' |
|
1238 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1239 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1240 | + REG_ADMIN_URL |
|
1241 | + ), |
|
1242 | + ); |
|
1243 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1244 | + ? ' style="display:none"' |
|
1245 | + : ''; |
|
1246 | + // allow filtering of template args at this point. |
|
1247 | + $template_args = apply_filters( |
|
1248 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1249 | + $template_args, |
|
1250 | + $datetime_row, |
|
1251 | + $datetime, |
|
1252 | + $default, |
|
1253 | + $all_datetimes, |
|
1254 | + $this->_is_creating_event |
|
1255 | + ); |
|
1256 | + return EEH_Template::display_template( |
|
1257 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1258 | + $template_args, |
|
1259 | + true |
|
1260 | + ); |
|
1261 | + } |
|
1262 | 1262 | |
1263 | 1263 | |
1264 | - /** |
|
1265 | - * @param int $datetime_row |
|
1266 | - * @param EE_Datetime $datetime |
|
1267 | - * @param array $datetime_tickets |
|
1268 | - * @param array $all_tickets |
|
1269 | - * @param bool $default |
|
1270 | - * @return mixed |
|
1271 | - * @throws DomainException |
|
1272 | - * @throws EE_Error |
|
1273 | - */ |
|
1274 | - protected function _get_dtt_attached_tickets_row( |
|
1275 | - $datetime_row, |
|
1276 | - $datetime, |
|
1277 | - $datetime_tickets = array(), |
|
1278 | - $all_tickets = array(), |
|
1279 | - $default |
|
1280 | - ) { |
|
1281 | - $template_args = array( |
|
1282 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1283 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1284 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1285 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1286 | - 'show_tickets_row' => ' style="display:none;"', |
|
1287 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1288 | - 'add_new_ticket_via_datetime', |
|
1289 | - $this->_adminpage_obj->page_slug, |
|
1290 | - $this->_adminpage_obj->get_req_action(), |
|
1291 | - false, |
|
1292 | - false |
|
1293 | - ), |
|
1294 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1295 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1296 | - ); |
|
1297 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1298 | - if (! $default) { |
|
1299 | - $ticket_row = 1; |
|
1300 | - foreach ($all_tickets as $ticket) { |
|
1301 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1302 | - $datetime_row, |
|
1303 | - $ticket_row, |
|
1304 | - $datetime, |
|
1305 | - $ticket, |
|
1306 | - $datetime_tickets, |
|
1307 | - $default |
|
1308 | - ); |
|
1309 | - $ticket_row++; |
|
1310 | - } |
|
1311 | - } |
|
1312 | - // filter template args at this point |
|
1313 | - $template_args = apply_filters( |
|
1314 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1315 | - $template_args, |
|
1316 | - $datetime_row, |
|
1317 | - $datetime, |
|
1318 | - $datetime_tickets, |
|
1319 | - $all_tickets, |
|
1320 | - $default, |
|
1321 | - $this->_is_creating_event |
|
1322 | - ); |
|
1323 | - return EEH_Template::display_template( |
|
1324 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1325 | - $template_args, |
|
1326 | - true |
|
1327 | - ); |
|
1328 | - } |
|
1264 | + /** |
|
1265 | + * @param int $datetime_row |
|
1266 | + * @param EE_Datetime $datetime |
|
1267 | + * @param array $datetime_tickets |
|
1268 | + * @param array $all_tickets |
|
1269 | + * @param bool $default |
|
1270 | + * @return mixed |
|
1271 | + * @throws DomainException |
|
1272 | + * @throws EE_Error |
|
1273 | + */ |
|
1274 | + protected function _get_dtt_attached_tickets_row( |
|
1275 | + $datetime_row, |
|
1276 | + $datetime, |
|
1277 | + $datetime_tickets = array(), |
|
1278 | + $all_tickets = array(), |
|
1279 | + $default |
|
1280 | + ) { |
|
1281 | + $template_args = array( |
|
1282 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1283 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1284 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1285 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1286 | + 'show_tickets_row' => ' style="display:none;"', |
|
1287 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1288 | + 'add_new_ticket_via_datetime', |
|
1289 | + $this->_adminpage_obj->page_slug, |
|
1290 | + $this->_adminpage_obj->get_req_action(), |
|
1291 | + false, |
|
1292 | + false |
|
1293 | + ), |
|
1294 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1295 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1296 | + ); |
|
1297 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
1298 | + if (! $default) { |
|
1299 | + $ticket_row = 1; |
|
1300 | + foreach ($all_tickets as $ticket) { |
|
1301 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1302 | + $datetime_row, |
|
1303 | + $ticket_row, |
|
1304 | + $datetime, |
|
1305 | + $ticket, |
|
1306 | + $datetime_tickets, |
|
1307 | + $default |
|
1308 | + ); |
|
1309 | + $ticket_row++; |
|
1310 | + } |
|
1311 | + } |
|
1312 | + // filter template args at this point |
|
1313 | + $template_args = apply_filters( |
|
1314 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1315 | + $template_args, |
|
1316 | + $datetime_row, |
|
1317 | + $datetime, |
|
1318 | + $datetime_tickets, |
|
1319 | + $all_tickets, |
|
1320 | + $default, |
|
1321 | + $this->_is_creating_event |
|
1322 | + ); |
|
1323 | + return EEH_Template::display_template( |
|
1324 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1325 | + $template_args, |
|
1326 | + true |
|
1327 | + ); |
|
1328 | + } |
|
1329 | 1329 | |
1330 | 1330 | |
1331 | - /** |
|
1332 | - * @param int $datetime_row |
|
1333 | - * @param int $ticket_row |
|
1334 | - * @param EE_Datetime $datetime |
|
1335 | - * @param EE_Ticket $ticket |
|
1336 | - * @param array $datetime_tickets |
|
1337 | - * @param bool $default |
|
1338 | - * @return mixed |
|
1339 | - * @throws DomainException |
|
1340 | - * @throws EE_Error |
|
1341 | - */ |
|
1342 | - protected function _get_datetime_tickets_list_item( |
|
1343 | - $datetime_row, |
|
1344 | - $ticket_row, |
|
1345 | - $datetime, |
|
1346 | - $ticket, |
|
1347 | - $datetime_tickets = array(), |
|
1348 | - $default |
|
1349 | - ) { |
|
1350 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1351 | - ? $datetime_tickets[ $datetime->ID() ] |
|
1352 | - : array(); |
|
1353 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1354 | - $no_ticket = $default && empty($ticket); |
|
1355 | - $template_args = array( |
|
1356 | - 'dtt_row' => $default |
|
1357 | - ? 'DTTNUM' |
|
1358 | - : $datetime_row, |
|
1359 | - 'tkt_row' => $no_ticket |
|
1360 | - ? 'TICKETNUM' |
|
1361 | - : $ticket_row, |
|
1362 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1363 | - ? ' checked="checked"' |
|
1364 | - : '', |
|
1365 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1366 | - ? ' ticket-selected' |
|
1367 | - : '', |
|
1368 | - 'TKT_name' => $no_ticket |
|
1369 | - ? 'TKTNAME' |
|
1370 | - : $ticket->get('TKT_name'), |
|
1371 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1372 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1373 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1374 | - ); |
|
1375 | - // filter template args |
|
1376 | - $template_args = apply_filters( |
|
1377 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1378 | - $template_args, |
|
1379 | - $datetime_row, |
|
1380 | - $ticket_row, |
|
1381 | - $datetime, |
|
1382 | - $ticket, |
|
1383 | - $datetime_tickets, |
|
1384 | - $default, |
|
1385 | - $this->_is_creating_event |
|
1386 | - ); |
|
1387 | - return EEH_Template::display_template( |
|
1388 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1389 | - $template_args, |
|
1390 | - true |
|
1391 | - ); |
|
1392 | - } |
|
1331 | + /** |
|
1332 | + * @param int $datetime_row |
|
1333 | + * @param int $ticket_row |
|
1334 | + * @param EE_Datetime $datetime |
|
1335 | + * @param EE_Ticket $ticket |
|
1336 | + * @param array $datetime_tickets |
|
1337 | + * @param bool $default |
|
1338 | + * @return mixed |
|
1339 | + * @throws DomainException |
|
1340 | + * @throws EE_Error |
|
1341 | + */ |
|
1342 | + protected function _get_datetime_tickets_list_item( |
|
1343 | + $datetime_row, |
|
1344 | + $ticket_row, |
|
1345 | + $datetime, |
|
1346 | + $ticket, |
|
1347 | + $datetime_tickets = array(), |
|
1348 | + $default |
|
1349 | + ) { |
|
1350 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1351 | + ? $datetime_tickets[ $datetime->ID() ] |
|
1352 | + : array(); |
|
1353 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1354 | + $no_ticket = $default && empty($ticket); |
|
1355 | + $template_args = array( |
|
1356 | + 'dtt_row' => $default |
|
1357 | + ? 'DTTNUM' |
|
1358 | + : $datetime_row, |
|
1359 | + 'tkt_row' => $no_ticket |
|
1360 | + ? 'TICKETNUM' |
|
1361 | + : $ticket_row, |
|
1362 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1363 | + ? ' checked="checked"' |
|
1364 | + : '', |
|
1365 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1366 | + ? ' ticket-selected' |
|
1367 | + : '', |
|
1368 | + 'TKT_name' => $no_ticket |
|
1369 | + ? 'TKTNAME' |
|
1370 | + : $ticket->get('TKT_name'), |
|
1371 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1372 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1373 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1374 | + ); |
|
1375 | + // filter template args |
|
1376 | + $template_args = apply_filters( |
|
1377 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1378 | + $template_args, |
|
1379 | + $datetime_row, |
|
1380 | + $ticket_row, |
|
1381 | + $datetime, |
|
1382 | + $ticket, |
|
1383 | + $datetime_tickets, |
|
1384 | + $default, |
|
1385 | + $this->_is_creating_event |
|
1386 | + ); |
|
1387 | + return EEH_Template::display_template( |
|
1388 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1389 | + $template_args, |
|
1390 | + true |
|
1391 | + ); |
|
1392 | + } |
|
1393 | 1393 | |
1394 | 1394 | |
1395 | - /** |
|
1396 | - * This generates the ticket row for tickets. |
|
1397 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1398 | - * (when default === true) |
|
1399 | - * |
|
1400 | - * @param int $ticket_row Represents the row number being generated. |
|
1401 | - * @param $ticket |
|
1402 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1403 | - * or empty for default |
|
1404 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1405 | - * @param bool $default Whether default row being generated or not. |
|
1406 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1407 | - * (or empty in the case of defaults) |
|
1408 | - * @return mixed |
|
1409 | - * @throws InvalidArgumentException |
|
1410 | - * @throws InvalidInterfaceException |
|
1411 | - * @throws InvalidDataTypeException |
|
1412 | - * @throws DomainException |
|
1413 | - * @throws EE_Error |
|
1414 | - * @throws ReflectionException |
|
1415 | - */ |
|
1416 | - protected function _get_ticket_row( |
|
1417 | - $ticket_row, |
|
1418 | - $ticket, |
|
1419 | - $ticket_datetimes, |
|
1420 | - $all_datetimes, |
|
1421 | - $default = false, |
|
1422 | - $all_tickets = array() |
|
1423 | - ) { |
|
1424 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1425 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1426 | - $prices = ! empty($ticket) && ! $default |
|
1427 | - ? $ticket->get_many_related( |
|
1428 | - 'Price', |
|
1429 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1430 | - ) |
|
1431 | - : array(); |
|
1432 | - // if there is only one price (which would be the base price) |
|
1433 | - // or NO prices and this ticket is a default ticket, |
|
1434 | - // let's just make sure there are no cached default prices on the object. |
|
1435 | - // This is done by not including any query_params. |
|
1436 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1437 | - $prices = $ticket->prices(); |
|
1438 | - } |
|
1439 | - // check if we're dealing with a default ticket in which case |
|
1440 | - // we don't want any starting_ticket_datetime_row values set |
|
1441 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1442 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1443 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1444 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1445 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
1446 | - : array(); |
|
1447 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1448 | - $base_price = $default ? null : $ticket->base_price(); |
|
1449 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1450 | - // breaking out complicated condition for ticket_status |
|
1451 | - if ($default) { |
|
1452 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1453 | - } else { |
|
1454 | - $ticket_status_class = $ticket->is_default() |
|
1455 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1456 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1457 | - } |
|
1458 | - // breaking out complicated condition for TKT_taxable |
|
1459 | - if ($default) { |
|
1460 | - $TKT_taxable = ''; |
|
1461 | - } else { |
|
1462 | - $TKT_taxable = $ticket->taxable() |
|
1463 | - ? ' checked="checked"' |
|
1464 | - : ''; |
|
1465 | - } |
|
1466 | - if ($default) { |
|
1467 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1468 | - } elseif ($ticket->is_default()) { |
|
1469 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1470 | - } else { |
|
1471 | - $TKT_status = $ticket->ticket_status(true); |
|
1472 | - } |
|
1473 | - if ($default) { |
|
1474 | - $TKT_min = ''; |
|
1475 | - } else { |
|
1476 | - $TKT_min = $ticket->min(); |
|
1477 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1478 | - $TKT_min = ''; |
|
1479 | - } |
|
1480 | - } |
|
1481 | - $template_args = array( |
|
1482 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1483 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1484 | - // on initial page load this will always be the correct order. |
|
1485 | - 'tkt_status_class' => $ticket_status_class, |
|
1486 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1487 | - 'edit_tkt_expanded' => '', |
|
1488 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1489 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1490 | - 'TKT_start_date' => $default |
|
1491 | - ? '' |
|
1492 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1493 | - 'TKT_end_date' => $default |
|
1494 | - ? '' |
|
1495 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1496 | - 'TKT_status' => $TKT_status, |
|
1497 | - 'TKT_price' => $default |
|
1498 | - ? '' |
|
1499 | - : EEH_Template::format_currency( |
|
1500 | - $ticket->get_ticket_total_with_taxes(), |
|
1501 | - false, |
|
1502 | - false |
|
1503 | - ), |
|
1504 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1505 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1506 | - 'TKT_qty' => $default |
|
1507 | - ? '' |
|
1508 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1509 | - 'TKT_qty_for_input' => $default |
|
1510 | - ? '' |
|
1511 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1512 | - 'TKT_uses' => $default |
|
1513 | - ? '' |
|
1514 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1515 | - 'TKT_min' => $TKT_min, |
|
1516 | - 'TKT_max' => $default |
|
1517 | - ? '' |
|
1518 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1519 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1520 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1521 | - 'TKT_registrations' => $default |
|
1522 | - ? 0 |
|
1523 | - : $ticket->count_registrations( |
|
1524 | - array( |
|
1525 | - array( |
|
1526 | - 'STS_ID' => array( |
|
1527 | - '!=', |
|
1528 | - EEM_Registration::status_id_incomplete, |
|
1529 | - ), |
|
1530 | - ), |
|
1531 | - ) |
|
1532 | - ), |
|
1533 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1534 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1535 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1536 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1537 | - 'TKT_is_default_selector' => '', |
|
1538 | - 'ticket_price_rows' => '', |
|
1539 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1540 | - ? '' |
|
1541 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1542 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1543 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1544 | - ? '' |
|
1545 | - : ' style="display:none;"', |
|
1546 | - 'show_price_mod_button' => count($prices) > 1 |
|
1547 | - || ($default && $count_price_mods > 0) |
|
1548 | - || (! $default && $ticket->deleted()) |
|
1549 | - ? ' style="display:none;"' |
|
1550 | - : '', |
|
1551 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1552 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1553 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1554 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1555 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1556 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1557 | - 'TKT_taxable' => $TKT_taxable, |
|
1558 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1559 | - ? '' |
|
1560 | - : ' style="display:none"', |
|
1561 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1562 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1563 | - $ticket_subtotal, |
|
1564 | - false, |
|
1565 | - false |
|
1566 | - ), |
|
1567 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1568 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1569 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1570 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1571 | - ? ' ticket-archived' |
|
1572 | - : '', |
|
1573 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
1574 | - && $ticket->deleted() |
|
1575 | - && ! $ticket->is_permanently_deleteable() |
|
1576 | - ? 'ee-lock-icon ' |
|
1577 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1578 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1579 | - ? '' |
|
1580 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1581 | - ); |
|
1582 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1583 | - ? ' style="display:none"' |
|
1584 | - : ''; |
|
1585 | - // handle rows that should NOT be empty |
|
1586 | - if (empty($template_args['TKT_start_date'])) { |
|
1587 | - // if empty then the start date will be now. |
|
1588 | - $template_args['TKT_start_date'] = date( |
|
1589 | - $this->_date_time_format, |
|
1590 | - current_time('timestamp') |
|
1591 | - ); |
|
1592 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1593 | - } |
|
1594 | - if (empty($template_args['TKT_end_date'])) { |
|
1595 | - // get the earliest datetime (if present); |
|
1596 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1597 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1598 | - 'Datetime', |
|
1599 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1600 | - ) |
|
1601 | - : null; |
|
1602 | - if (! empty($earliest_dtt)) { |
|
1603 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1604 | - 'DTT_EVT_start', |
|
1605 | - $this->_date_time_format |
|
1606 | - ); |
|
1607 | - } else { |
|
1608 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1609 | - $template_args['TKT_end_date'] = date( |
|
1610 | - $this->_date_time_format, |
|
1611 | - mktime( |
|
1612 | - 24, |
|
1613 | - 0, |
|
1614 | - 0, |
|
1615 | - date('m'), |
|
1616 | - date('d') + 29, |
|
1617 | - date('Y') |
|
1618 | - ) |
|
1619 | - ); |
|
1620 | - } |
|
1621 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1622 | - } |
|
1623 | - // generate ticket_datetime items |
|
1624 | - if (! $default) { |
|
1625 | - $datetime_row = 1; |
|
1626 | - foreach ($all_datetimes as $datetime) { |
|
1627 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1628 | - $datetime_row, |
|
1629 | - $ticket_row, |
|
1630 | - $datetime, |
|
1631 | - $ticket, |
|
1632 | - $ticket_datetimes, |
|
1633 | - $default |
|
1634 | - ); |
|
1635 | - $datetime_row++; |
|
1636 | - } |
|
1637 | - } |
|
1638 | - $price_row = 1; |
|
1639 | - foreach ($prices as $price) { |
|
1640 | - if (! $price instanceof EE_Price) { |
|
1641 | - continue; |
|
1642 | - } |
|
1643 | - if ($price->is_base_price()) { |
|
1644 | - $price_row++; |
|
1645 | - continue; |
|
1646 | - } |
|
1647 | - $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1648 | - $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1649 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1650 | - $ticket_row, |
|
1651 | - $price_row, |
|
1652 | - $price, |
|
1653 | - $default, |
|
1654 | - $ticket, |
|
1655 | - $show_trash, |
|
1656 | - $show_create |
|
1657 | - ); |
|
1658 | - $price_row++; |
|
1659 | - } |
|
1660 | - // filter $template_args |
|
1661 | - $template_args = apply_filters( |
|
1662 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1663 | - $template_args, |
|
1664 | - $ticket_row, |
|
1665 | - $ticket, |
|
1666 | - $ticket_datetimes, |
|
1667 | - $all_datetimes, |
|
1668 | - $default, |
|
1669 | - $all_tickets, |
|
1670 | - $this->_is_creating_event |
|
1671 | - ); |
|
1672 | - return EEH_Template::display_template( |
|
1673 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1674 | - $template_args, |
|
1675 | - true |
|
1676 | - ); |
|
1677 | - } |
|
1395 | + /** |
|
1396 | + * This generates the ticket row for tickets. |
|
1397 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1398 | + * (when default === true) |
|
1399 | + * |
|
1400 | + * @param int $ticket_row Represents the row number being generated. |
|
1401 | + * @param $ticket |
|
1402 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1403 | + * or empty for default |
|
1404 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1405 | + * @param bool $default Whether default row being generated or not. |
|
1406 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1407 | + * (or empty in the case of defaults) |
|
1408 | + * @return mixed |
|
1409 | + * @throws InvalidArgumentException |
|
1410 | + * @throws InvalidInterfaceException |
|
1411 | + * @throws InvalidDataTypeException |
|
1412 | + * @throws DomainException |
|
1413 | + * @throws EE_Error |
|
1414 | + * @throws ReflectionException |
|
1415 | + */ |
|
1416 | + protected function _get_ticket_row( |
|
1417 | + $ticket_row, |
|
1418 | + $ticket, |
|
1419 | + $ticket_datetimes, |
|
1420 | + $all_datetimes, |
|
1421 | + $default = false, |
|
1422 | + $all_tickets = array() |
|
1423 | + ) { |
|
1424 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1425 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1426 | + $prices = ! empty($ticket) && ! $default |
|
1427 | + ? $ticket->get_many_related( |
|
1428 | + 'Price', |
|
1429 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
1430 | + ) |
|
1431 | + : array(); |
|
1432 | + // if there is only one price (which would be the base price) |
|
1433 | + // or NO prices and this ticket is a default ticket, |
|
1434 | + // let's just make sure there are no cached default prices on the object. |
|
1435 | + // This is done by not including any query_params. |
|
1436 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1437 | + $prices = $ticket->prices(); |
|
1438 | + } |
|
1439 | + // check if we're dealing with a default ticket in which case |
|
1440 | + // we don't want any starting_ticket_datetime_row values set |
|
1441 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1442 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1443 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1444 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1445 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
1446 | + : array(); |
|
1447 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1448 | + $base_price = $default ? null : $ticket->base_price(); |
|
1449 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1450 | + // breaking out complicated condition for ticket_status |
|
1451 | + if ($default) { |
|
1452 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1453 | + } else { |
|
1454 | + $ticket_status_class = $ticket->is_default() |
|
1455 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1456 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1457 | + } |
|
1458 | + // breaking out complicated condition for TKT_taxable |
|
1459 | + if ($default) { |
|
1460 | + $TKT_taxable = ''; |
|
1461 | + } else { |
|
1462 | + $TKT_taxable = $ticket->taxable() |
|
1463 | + ? ' checked="checked"' |
|
1464 | + : ''; |
|
1465 | + } |
|
1466 | + if ($default) { |
|
1467 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1468 | + } elseif ($ticket->is_default()) { |
|
1469 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1470 | + } else { |
|
1471 | + $TKT_status = $ticket->ticket_status(true); |
|
1472 | + } |
|
1473 | + if ($default) { |
|
1474 | + $TKT_min = ''; |
|
1475 | + } else { |
|
1476 | + $TKT_min = $ticket->min(); |
|
1477 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1478 | + $TKT_min = ''; |
|
1479 | + } |
|
1480 | + } |
|
1481 | + $template_args = array( |
|
1482 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1483 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1484 | + // on initial page load this will always be the correct order. |
|
1485 | + 'tkt_status_class' => $ticket_status_class, |
|
1486 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1487 | + 'edit_tkt_expanded' => '', |
|
1488 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1489 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1490 | + 'TKT_start_date' => $default |
|
1491 | + ? '' |
|
1492 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1493 | + 'TKT_end_date' => $default |
|
1494 | + ? '' |
|
1495 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1496 | + 'TKT_status' => $TKT_status, |
|
1497 | + 'TKT_price' => $default |
|
1498 | + ? '' |
|
1499 | + : EEH_Template::format_currency( |
|
1500 | + $ticket->get_ticket_total_with_taxes(), |
|
1501 | + false, |
|
1502 | + false |
|
1503 | + ), |
|
1504 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1505 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1506 | + 'TKT_qty' => $default |
|
1507 | + ? '' |
|
1508 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1509 | + 'TKT_qty_for_input' => $default |
|
1510 | + ? '' |
|
1511 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1512 | + 'TKT_uses' => $default |
|
1513 | + ? '' |
|
1514 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1515 | + 'TKT_min' => $TKT_min, |
|
1516 | + 'TKT_max' => $default |
|
1517 | + ? '' |
|
1518 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1519 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1520 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1521 | + 'TKT_registrations' => $default |
|
1522 | + ? 0 |
|
1523 | + : $ticket->count_registrations( |
|
1524 | + array( |
|
1525 | + array( |
|
1526 | + 'STS_ID' => array( |
|
1527 | + '!=', |
|
1528 | + EEM_Registration::status_id_incomplete, |
|
1529 | + ), |
|
1530 | + ), |
|
1531 | + ) |
|
1532 | + ), |
|
1533 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1534 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1535 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1536 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1537 | + 'TKT_is_default_selector' => '', |
|
1538 | + 'ticket_price_rows' => '', |
|
1539 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1540 | + ? '' |
|
1541 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1542 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1543 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1544 | + ? '' |
|
1545 | + : ' style="display:none;"', |
|
1546 | + 'show_price_mod_button' => count($prices) > 1 |
|
1547 | + || ($default && $count_price_mods > 0) |
|
1548 | + || (! $default && $ticket->deleted()) |
|
1549 | + ? ' style="display:none;"' |
|
1550 | + : '', |
|
1551 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1552 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1553 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1554 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1555 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1556 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1557 | + 'TKT_taxable' => $TKT_taxable, |
|
1558 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1559 | + ? '' |
|
1560 | + : ' style="display:none"', |
|
1561 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1562 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1563 | + $ticket_subtotal, |
|
1564 | + false, |
|
1565 | + false |
|
1566 | + ), |
|
1567 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1568 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1569 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1570 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1571 | + ? ' ticket-archived' |
|
1572 | + : '', |
|
1573 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
1574 | + && $ticket->deleted() |
|
1575 | + && ! $ticket->is_permanently_deleteable() |
|
1576 | + ? 'ee-lock-icon ' |
|
1577 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1578 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1579 | + ? '' |
|
1580 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1581 | + ); |
|
1582 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1583 | + ? ' style="display:none"' |
|
1584 | + : ''; |
|
1585 | + // handle rows that should NOT be empty |
|
1586 | + if (empty($template_args['TKT_start_date'])) { |
|
1587 | + // if empty then the start date will be now. |
|
1588 | + $template_args['TKT_start_date'] = date( |
|
1589 | + $this->_date_time_format, |
|
1590 | + current_time('timestamp') |
|
1591 | + ); |
|
1592 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1593 | + } |
|
1594 | + if (empty($template_args['TKT_end_date'])) { |
|
1595 | + // get the earliest datetime (if present); |
|
1596 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1597 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1598 | + 'Datetime', |
|
1599 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1600 | + ) |
|
1601 | + : null; |
|
1602 | + if (! empty($earliest_dtt)) { |
|
1603 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1604 | + 'DTT_EVT_start', |
|
1605 | + $this->_date_time_format |
|
1606 | + ); |
|
1607 | + } else { |
|
1608 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1609 | + $template_args['TKT_end_date'] = date( |
|
1610 | + $this->_date_time_format, |
|
1611 | + mktime( |
|
1612 | + 24, |
|
1613 | + 0, |
|
1614 | + 0, |
|
1615 | + date('m'), |
|
1616 | + date('d') + 29, |
|
1617 | + date('Y') |
|
1618 | + ) |
|
1619 | + ); |
|
1620 | + } |
|
1621 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1622 | + } |
|
1623 | + // generate ticket_datetime items |
|
1624 | + if (! $default) { |
|
1625 | + $datetime_row = 1; |
|
1626 | + foreach ($all_datetimes as $datetime) { |
|
1627 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1628 | + $datetime_row, |
|
1629 | + $ticket_row, |
|
1630 | + $datetime, |
|
1631 | + $ticket, |
|
1632 | + $ticket_datetimes, |
|
1633 | + $default |
|
1634 | + ); |
|
1635 | + $datetime_row++; |
|
1636 | + } |
|
1637 | + } |
|
1638 | + $price_row = 1; |
|
1639 | + foreach ($prices as $price) { |
|
1640 | + if (! $price instanceof EE_Price) { |
|
1641 | + continue; |
|
1642 | + } |
|
1643 | + if ($price->is_base_price()) { |
|
1644 | + $price_row++; |
|
1645 | + continue; |
|
1646 | + } |
|
1647 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1648 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1649 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1650 | + $ticket_row, |
|
1651 | + $price_row, |
|
1652 | + $price, |
|
1653 | + $default, |
|
1654 | + $ticket, |
|
1655 | + $show_trash, |
|
1656 | + $show_create |
|
1657 | + ); |
|
1658 | + $price_row++; |
|
1659 | + } |
|
1660 | + // filter $template_args |
|
1661 | + $template_args = apply_filters( |
|
1662 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1663 | + $template_args, |
|
1664 | + $ticket_row, |
|
1665 | + $ticket, |
|
1666 | + $ticket_datetimes, |
|
1667 | + $all_datetimes, |
|
1668 | + $default, |
|
1669 | + $all_tickets, |
|
1670 | + $this->_is_creating_event |
|
1671 | + ); |
|
1672 | + return EEH_Template::display_template( |
|
1673 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1674 | + $template_args, |
|
1675 | + true |
|
1676 | + ); |
|
1677 | + } |
|
1678 | 1678 | |
1679 | 1679 | |
1680 | - /** |
|
1681 | - * @param int $ticket_row |
|
1682 | - * @param EE_Ticket|null $ticket |
|
1683 | - * @return string |
|
1684 | - * @throws DomainException |
|
1685 | - * @throws EE_Error |
|
1686 | - */ |
|
1687 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1688 | - { |
|
1689 | - $tax_rows = ''; |
|
1690 | - /** @var EE_Price[] $taxes */ |
|
1691 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1692 | - foreach ($taxes as $tax) { |
|
1693 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1694 | - $template_args = array( |
|
1695 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1696 | - ? '' |
|
1697 | - : ' style="display:none;"', |
|
1698 | - 'tax_id' => $tax->ID(), |
|
1699 | - 'tkt_row' => $ticket_row, |
|
1700 | - 'tax_label' => $tax->get('PRC_name'), |
|
1701 | - 'tax_added' => $tax_added, |
|
1702 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1703 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1704 | - ); |
|
1705 | - $template_args = apply_filters( |
|
1706 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1707 | - $template_args, |
|
1708 | - $ticket_row, |
|
1709 | - $ticket, |
|
1710 | - $this->_is_creating_event |
|
1711 | - ); |
|
1712 | - $tax_rows .= EEH_Template::display_template( |
|
1713 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1714 | - $template_args, |
|
1715 | - true |
|
1716 | - ); |
|
1717 | - } |
|
1718 | - return $tax_rows; |
|
1719 | - } |
|
1680 | + /** |
|
1681 | + * @param int $ticket_row |
|
1682 | + * @param EE_Ticket|null $ticket |
|
1683 | + * @return string |
|
1684 | + * @throws DomainException |
|
1685 | + * @throws EE_Error |
|
1686 | + */ |
|
1687 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1688 | + { |
|
1689 | + $tax_rows = ''; |
|
1690 | + /** @var EE_Price[] $taxes */ |
|
1691 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1692 | + foreach ($taxes as $tax) { |
|
1693 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1694 | + $template_args = array( |
|
1695 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1696 | + ? '' |
|
1697 | + : ' style="display:none;"', |
|
1698 | + 'tax_id' => $tax->ID(), |
|
1699 | + 'tkt_row' => $ticket_row, |
|
1700 | + 'tax_label' => $tax->get('PRC_name'), |
|
1701 | + 'tax_added' => $tax_added, |
|
1702 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1703 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1704 | + ); |
|
1705 | + $template_args = apply_filters( |
|
1706 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1707 | + $template_args, |
|
1708 | + $ticket_row, |
|
1709 | + $ticket, |
|
1710 | + $this->_is_creating_event |
|
1711 | + ); |
|
1712 | + $tax_rows .= EEH_Template::display_template( |
|
1713 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1714 | + $template_args, |
|
1715 | + true |
|
1716 | + ); |
|
1717 | + } |
|
1718 | + return $tax_rows; |
|
1719 | + } |
|
1720 | 1720 | |
1721 | 1721 | |
1722 | - /** |
|
1723 | - * @param EE_Price $tax |
|
1724 | - * @param EE_Ticket|null $ticket |
|
1725 | - * @return float|int |
|
1726 | - * @throws EE_Error |
|
1727 | - */ |
|
1728 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1729 | - { |
|
1730 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1731 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1732 | - } |
|
1722 | + /** |
|
1723 | + * @param EE_Price $tax |
|
1724 | + * @param EE_Ticket|null $ticket |
|
1725 | + * @return float|int |
|
1726 | + * @throws EE_Error |
|
1727 | + */ |
|
1728 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1729 | + { |
|
1730 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1731 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1732 | + } |
|
1733 | 1733 | |
1734 | 1734 | |
1735 | - /** |
|
1736 | - * @param int $ticket_row |
|
1737 | - * @param int $price_row |
|
1738 | - * @param EE_Price|null $price |
|
1739 | - * @param bool $default |
|
1740 | - * @param EE_Ticket|null $ticket |
|
1741 | - * @param bool $show_trash |
|
1742 | - * @param bool $show_create |
|
1743 | - * @return mixed |
|
1744 | - * @throws InvalidArgumentException |
|
1745 | - * @throws InvalidInterfaceException |
|
1746 | - * @throws InvalidDataTypeException |
|
1747 | - * @throws DomainException |
|
1748 | - * @throws EE_Error |
|
1749 | - * @throws ReflectionException |
|
1750 | - */ |
|
1751 | - protected function _get_ticket_price_row( |
|
1752 | - $ticket_row, |
|
1753 | - $price_row, |
|
1754 | - $price, |
|
1755 | - $default, |
|
1756 | - $ticket, |
|
1757 | - $show_trash = true, |
|
1758 | - $show_create = true |
|
1759 | - ) { |
|
1760 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1761 | - $template_args = array( |
|
1762 | - 'tkt_row' => $default && empty($ticket) |
|
1763 | - ? 'TICKETNUM' |
|
1764 | - : $ticket_row, |
|
1765 | - 'PRC_order' => $default && empty($price) |
|
1766 | - ? 'PRICENUM' |
|
1767 | - : $price_row, |
|
1768 | - 'edit_prices_name' => $default && empty($price) |
|
1769 | - ? 'PRICENAMEATTR' |
|
1770 | - : 'edit_prices', |
|
1771 | - 'price_type_selector' => $default && empty($price) |
|
1772 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1773 | - : $this->_get_price_type_selector( |
|
1774 | - $ticket_row, |
|
1775 | - $price_row, |
|
1776 | - $price, |
|
1777 | - $default, |
|
1778 | - $send_disabled |
|
1779 | - ), |
|
1780 | - 'PRC_ID' => $default && empty($price) |
|
1781 | - ? 0 |
|
1782 | - : $price->ID(), |
|
1783 | - 'PRC_is_default' => $default && empty($price) |
|
1784 | - ? 0 |
|
1785 | - : $price->get('PRC_is_default'), |
|
1786 | - 'PRC_name' => $default && empty($price) |
|
1787 | - ? '' |
|
1788 | - : $price->get('PRC_name'), |
|
1789 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1790 | - 'show_plus_or_minus' => $default && empty($price) |
|
1791 | - ? '' |
|
1792 | - : ' style="display:none;"', |
|
1793 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1794 | - ? ' style="display:none;"' |
|
1795 | - : '', |
|
1796 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1797 | - ? ' style="display:none;"' |
|
1798 | - : '', |
|
1799 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1800 | - ? ' style="display:none"' |
|
1801 | - : '', |
|
1802 | - 'PRC_amount' => $default && empty($price) |
|
1803 | - ? 0 |
|
1804 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1805 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1806 | - ? ' style="display:none;"' |
|
1807 | - : '', |
|
1808 | - 'show_trash_icon' => $show_trash |
|
1809 | - ? '' |
|
1810 | - : ' style="display:none;"', |
|
1811 | - 'show_create_button' => $show_create |
|
1812 | - ? '' |
|
1813 | - : ' style="display:none;"', |
|
1814 | - 'PRC_desc' => $default && empty($price) |
|
1815 | - ? '' |
|
1816 | - : $price->get('PRC_desc'), |
|
1817 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1818 | - ); |
|
1819 | - $template_args = apply_filters( |
|
1820 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1821 | - $template_args, |
|
1822 | - $ticket_row, |
|
1823 | - $price_row, |
|
1824 | - $price, |
|
1825 | - $default, |
|
1826 | - $ticket, |
|
1827 | - $show_trash, |
|
1828 | - $show_create, |
|
1829 | - $this->_is_creating_event |
|
1830 | - ); |
|
1831 | - return EEH_Template::display_template( |
|
1832 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1833 | - $template_args, |
|
1834 | - true |
|
1835 | - ); |
|
1836 | - } |
|
1735 | + /** |
|
1736 | + * @param int $ticket_row |
|
1737 | + * @param int $price_row |
|
1738 | + * @param EE_Price|null $price |
|
1739 | + * @param bool $default |
|
1740 | + * @param EE_Ticket|null $ticket |
|
1741 | + * @param bool $show_trash |
|
1742 | + * @param bool $show_create |
|
1743 | + * @return mixed |
|
1744 | + * @throws InvalidArgumentException |
|
1745 | + * @throws InvalidInterfaceException |
|
1746 | + * @throws InvalidDataTypeException |
|
1747 | + * @throws DomainException |
|
1748 | + * @throws EE_Error |
|
1749 | + * @throws ReflectionException |
|
1750 | + */ |
|
1751 | + protected function _get_ticket_price_row( |
|
1752 | + $ticket_row, |
|
1753 | + $price_row, |
|
1754 | + $price, |
|
1755 | + $default, |
|
1756 | + $ticket, |
|
1757 | + $show_trash = true, |
|
1758 | + $show_create = true |
|
1759 | + ) { |
|
1760 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1761 | + $template_args = array( |
|
1762 | + 'tkt_row' => $default && empty($ticket) |
|
1763 | + ? 'TICKETNUM' |
|
1764 | + : $ticket_row, |
|
1765 | + 'PRC_order' => $default && empty($price) |
|
1766 | + ? 'PRICENUM' |
|
1767 | + : $price_row, |
|
1768 | + 'edit_prices_name' => $default && empty($price) |
|
1769 | + ? 'PRICENAMEATTR' |
|
1770 | + : 'edit_prices', |
|
1771 | + 'price_type_selector' => $default && empty($price) |
|
1772 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1773 | + : $this->_get_price_type_selector( |
|
1774 | + $ticket_row, |
|
1775 | + $price_row, |
|
1776 | + $price, |
|
1777 | + $default, |
|
1778 | + $send_disabled |
|
1779 | + ), |
|
1780 | + 'PRC_ID' => $default && empty($price) |
|
1781 | + ? 0 |
|
1782 | + : $price->ID(), |
|
1783 | + 'PRC_is_default' => $default && empty($price) |
|
1784 | + ? 0 |
|
1785 | + : $price->get('PRC_is_default'), |
|
1786 | + 'PRC_name' => $default && empty($price) |
|
1787 | + ? '' |
|
1788 | + : $price->get('PRC_name'), |
|
1789 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1790 | + 'show_plus_or_minus' => $default && empty($price) |
|
1791 | + ? '' |
|
1792 | + : ' style="display:none;"', |
|
1793 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1794 | + ? ' style="display:none;"' |
|
1795 | + : '', |
|
1796 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1797 | + ? ' style="display:none;"' |
|
1798 | + : '', |
|
1799 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1800 | + ? ' style="display:none"' |
|
1801 | + : '', |
|
1802 | + 'PRC_amount' => $default && empty($price) |
|
1803 | + ? 0 |
|
1804 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
1805 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1806 | + ? ' style="display:none;"' |
|
1807 | + : '', |
|
1808 | + 'show_trash_icon' => $show_trash |
|
1809 | + ? '' |
|
1810 | + : ' style="display:none;"', |
|
1811 | + 'show_create_button' => $show_create |
|
1812 | + ? '' |
|
1813 | + : ' style="display:none;"', |
|
1814 | + 'PRC_desc' => $default && empty($price) |
|
1815 | + ? '' |
|
1816 | + : $price->get('PRC_desc'), |
|
1817 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1818 | + ); |
|
1819 | + $template_args = apply_filters( |
|
1820 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1821 | + $template_args, |
|
1822 | + $ticket_row, |
|
1823 | + $price_row, |
|
1824 | + $price, |
|
1825 | + $default, |
|
1826 | + $ticket, |
|
1827 | + $show_trash, |
|
1828 | + $show_create, |
|
1829 | + $this->_is_creating_event |
|
1830 | + ); |
|
1831 | + return EEH_Template::display_template( |
|
1832 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1833 | + $template_args, |
|
1834 | + true |
|
1835 | + ); |
|
1836 | + } |
|
1837 | 1837 | |
1838 | 1838 | |
1839 | - /** |
|
1840 | - * @param int $ticket_row |
|
1841 | - * @param int $price_row |
|
1842 | - * @param EE_Price $price |
|
1843 | - * @param bool $default |
|
1844 | - * @param bool $disabled |
|
1845 | - * @return mixed |
|
1846 | - * @throws ReflectionException |
|
1847 | - * @throws InvalidArgumentException |
|
1848 | - * @throws InvalidInterfaceException |
|
1849 | - * @throws InvalidDataTypeException |
|
1850 | - * @throws DomainException |
|
1851 | - * @throws EE_Error |
|
1852 | - */ |
|
1853 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1854 | - { |
|
1855 | - if ($price->is_base_price()) { |
|
1856 | - return $this->_get_base_price_template( |
|
1857 | - $ticket_row, |
|
1858 | - $price_row, |
|
1859 | - $price, |
|
1860 | - $default |
|
1861 | - ); |
|
1862 | - } |
|
1863 | - return $this->_get_price_modifier_template( |
|
1864 | - $ticket_row, |
|
1865 | - $price_row, |
|
1866 | - $price, |
|
1867 | - $default, |
|
1868 | - $disabled |
|
1869 | - ); |
|
1870 | - } |
|
1839 | + /** |
|
1840 | + * @param int $ticket_row |
|
1841 | + * @param int $price_row |
|
1842 | + * @param EE_Price $price |
|
1843 | + * @param bool $default |
|
1844 | + * @param bool $disabled |
|
1845 | + * @return mixed |
|
1846 | + * @throws ReflectionException |
|
1847 | + * @throws InvalidArgumentException |
|
1848 | + * @throws InvalidInterfaceException |
|
1849 | + * @throws InvalidDataTypeException |
|
1850 | + * @throws DomainException |
|
1851 | + * @throws EE_Error |
|
1852 | + */ |
|
1853 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1854 | + { |
|
1855 | + if ($price->is_base_price()) { |
|
1856 | + return $this->_get_base_price_template( |
|
1857 | + $ticket_row, |
|
1858 | + $price_row, |
|
1859 | + $price, |
|
1860 | + $default |
|
1861 | + ); |
|
1862 | + } |
|
1863 | + return $this->_get_price_modifier_template( |
|
1864 | + $ticket_row, |
|
1865 | + $price_row, |
|
1866 | + $price, |
|
1867 | + $default, |
|
1868 | + $disabled |
|
1869 | + ); |
|
1870 | + } |
|
1871 | 1871 | |
1872 | 1872 | |
1873 | - /** |
|
1874 | - * @param int $ticket_row |
|
1875 | - * @param int $price_row |
|
1876 | - * @param EE_Price $price |
|
1877 | - * @param bool $default |
|
1878 | - * @return mixed |
|
1879 | - * @throws DomainException |
|
1880 | - * @throws EE_Error |
|
1881 | - */ |
|
1882 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1883 | - { |
|
1884 | - $template_args = array( |
|
1885 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1886 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1887 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1888 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1889 | - 'price_selected_operator' => '+', |
|
1890 | - 'price_selected_is_percent' => 0, |
|
1891 | - ); |
|
1892 | - $template_args = apply_filters( |
|
1893 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1894 | - $template_args, |
|
1895 | - $ticket_row, |
|
1896 | - $price_row, |
|
1897 | - $price, |
|
1898 | - $default, |
|
1899 | - $this->_is_creating_event |
|
1900 | - ); |
|
1901 | - return EEH_Template::display_template( |
|
1902 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1903 | - $template_args, |
|
1904 | - true |
|
1905 | - ); |
|
1906 | - } |
|
1873 | + /** |
|
1874 | + * @param int $ticket_row |
|
1875 | + * @param int $price_row |
|
1876 | + * @param EE_Price $price |
|
1877 | + * @param bool $default |
|
1878 | + * @return mixed |
|
1879 | + * @throws DomainException |
|
1880 | + * @throws EE_Error |
|
1881 | + */ |
|
1882 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1883 | + { |
|
1884 | + $template_args = array( |
|
1885 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1886 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1887 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1888 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1889 | + 'price_selected_operator' => '+', |
|
1890 | + 'price_selected_is_percent' => 0, |
|
1891 | + ); |
|
1892 | + $template_args = apply_filters( |
|
1893 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1894 | + $template_args, |
|
1895 | + $ticket_row, |
|
1896 | + $price_row, |
|
1897 | + $price, |
|
1898 | + $default, |
|
1899 | + $this->_is_creating_event |
|
1900 | + ); |
|
1901 | + return EEH_Template::display_template( |
|
1902 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1903 | + $template_args, |
|
1904 | + true |
|
1905 | + ); |
|
1906 | + } |
|
1907 | 1907 | |
1908 | 1908 | |
1909 | - /** |
|
1910 | - * @param int $ticket_row |
|
1911 | - * @param int $price_row |
|
1912 | - * @param EE_Price $price |
|
1913 | - * @param bool $default |
|
1914 | - * @param bool $disabled |
|
1915 | - * @return mixed |
|
1916 | - * @throws ReflectionException |
|
1917 | - * @throws InvalidArgumentException |
|
1918 | - * @throws InvalidInterfaceException |
|
1919 | - * @throws InvalidDataTypeException |
|
1920 | - * @throws DomainException |
|
1921 | - * @throws EE_Error |
|
1922 | - */ |
|
1923 | - protected function _get_price_modifier_template( |
|
1924 | - $ticket_row, |
|
1925 | - $price_row, |
|
1926 | - $price, |
|
1927 | - $default, |
|
1928 | - $disabled = false |
|
1929 | - ) { |
|
1930 | - $select_name = $default && ! $price instanceof EE_Price |
|
1931 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1932 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1933 | - /** @var EEM_Price_Type $price_type_model */ |
|
1934 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1935 | - $price_types = $price_type_model->get_all(array( |
|
1936 | - array( |
|
1937 | - 'OR' => array( |
|
1938 | - 'PBT_ID' => '2', |
|
1939 | - 'PBT_ID*' => '3', |
|
1940 | - ), |
|
1941 | - ), |
|
1942 | - )); |
|
1943 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1944 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1945 | - : array(); |
|
1946 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1947 | - $price_option_spans = ''; |
|
1948 | - // setup price types for selector |
|
1949 | - foreach ($price_types as $price_type) { |
|
1950 | - if (! $price_type instanceof EE_Price_Type) { |
|
1951 | - continue; |
|
1952 | - } |
|
1953 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1954 | - // while we're in the loop let's setup the option spans used by js |
|
1955 | - $span_args = array( |
|
1956 | - 'PRT_ID' => $price_type->ID(), |
|
1957 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1958 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1959 | - ); |
|
1960 | - $price_option_spans .= EEH_Template::display_template( |
|
1961 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1962 | - $span_args, |
|
1963 | - true |
|
1964 | - ); |
|
1965 | - } |
|
1966 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1967 | - : $select_name; |
|
1968 | - $select_input = new EE_Select_Input( |
|
1969 | - $all_price_types, |
|
1970 | - array( |
|
1971 | - 'default' => $selected_price_type_id, |
|
1972 | - 'html_name' => $select_name, |
|
1973 | - 'html_class' => 'edit-price-PRT_ID', |
|
1974 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1975 | - ) |
|
1976 | - ); |
|
1977 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1978 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1979 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1980 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1981 | - $template_args = array( |
|
1982 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1983 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1984 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1985 | - 'main_name' => $select_name, |
|
1986 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1987 | - 'price_option_spans' => $price_option_spans, |
|
1988 | - 'price_selected_operator' => $price_selected_operator, |
|
1989 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1990 | - 'disabled' => $disabled, |
|
1991 | - ); |
|
1992 | - $template_args = apply_filters( |
|
1993 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1994 | - $template_args, |
|
1995 | - $ticket_row, |
|
1996 | - $price_row, |
|
1997 | - $price, |
|
1998 | - $default, |
|
1999 | - $disabled, |
|
2000 | - $this->_is_creating_event |
|
2001 | - ); |
|
2002 | - return EEH_Template::display_template( |
|
2003 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2004 | - $template_args, |
|
2005 | - true |
|
2006 | - ); |
|
2007 | - } |
|
1909 | + /** |
|
1910 | + * @param int $ticket_row |
|
1911 | + * @param int $price_row |
|
1912 | + * @param EE_Price $price |
|
1913 | + * @param bool $default |
|
1914 | + * @param bool $disabled |
|
1915 | + * @return mixed |
|
1916 | + * @throws ReflectionException |
|
1917 | + * @throws InvalidArgumentException |
|
1918 | + * @throws InvalidInterfaceException |
|
1919 | + * @throws InvalidDataTypeException |
|
1920 | + * @throws DomainException |
|
1921 | + * @throws EE_Error |
|
1922 | + */ |
|
1923 | + protected function _get_price_modifier_template( |
|
1924 | + $ticket_row, |
|
1925 | + $price_row, |
|
1926 | + $price, |
|
1927 | + $default, |
|
1928 | + $disabled = false |
|
1929 | + ) { |
|
1930 | + $select_name = $default && ! $price instanceof EE_Price |
|
1931 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1932 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1933 | + /** @var EEM_Price_Type $price_type_model */ |
|
1934 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1935 | + $price_types = $price_type_model->get_all(array( |
|
1936 | + array( |
|
1937 | + 'OR' => array( |
|
1938 | + 'PBT_ID' => '2', |
|
1939 | + 'PBT_ID*' => '3', |
|
1940 | + ), |
|
1941 | + ), |
|
1942 | + )); |
|
1943 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1944 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1945 | + : array(); |
|
1946 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1947 | + $price_option_spans = ''; |
|
1948 | + // setup price types for selector |
|
1949 | + foreach ($price_types as $price_type) { |
|
1950 | + if (! $price_type instanceof EE_Price_Type) { |
|
1951 | + continue; |
|
1952 | + } |
|
1953 | + $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1954 | + // while we're in the loop let's setup the option spans used by js |
|
1955 | + $span_args = array( |
|
1956 | + 'PRT_ID' => $price_type->ID(), |
|
1957 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1958 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1959 | + ); |
|
1960 | + $price_option_spans .= EEH_Template::display_template( |
|
1961 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1962 | + $span_args, |
|
1963 | + true |
|
1964 | + ); |
|
1965 | + } |
|
1966 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1967 | + : $select_name; |
|
1968 | + $select_input = new EE_Select_Input( |
|
1969 | + $all_price_types, |
|
1970 | + array( |
|
1971 | + 'default' => $selected_price_type_id, |
|
1972 | + 'html_name' => $select_name, |
|
1973 | + 'html_class' => 'edit-price-PRT_ID', |
|
1974 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1975 | + ) |
|
1976 | + ); |
|
1977 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1978 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1979 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1980 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1981 | + $template_args = array( |
|
1982 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1983 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1984 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1985 | + 'main_name' => $select_name, |
|
1986 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1987 | + 'price_option_spans' => $price_option_spans, |
|
1988 | + 'price_selected_operator' => $price_selected_operator, |
|
1989 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1990 | + 'disabled' => $disabled, |
|
1991 | + ); |
|
1992 | + $template_args = apply_filters( |
|
1993 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1994 | + $template_args, |
|
1995 | + $ticket_row, |
|
1996 | + $price_row, |
|
1997 | + $price, |
|
1998 | + $default, |
|
1999 | + $disabled, |
|
2000 | + $this->_is_creating_event |
|
2001 | + ); |
|
2002 | + return EEH_Template::display_template( |
|
2003 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2004 | + $template_args, |
|
2005 | + true |
|
2006 | + ); |
|
2007 | + } |
|
2008 | 2008 | |
2009 | 2009 | |
2010 | - /** |
|
2011 | - * @param int $datetime_row |
|
2012 | - * @param int $ticket_row |
|
2013 | - * @param EE_Datetime|null $datetime |
|
2014 | - * @param EE_Ticket|null $ticket |
|
2015 | - * @param array $ticket_datetimes |
|
2016 | - * @param bool $default |
|
2017 | - * @return mixed |
|
2018 | - * @throws DomainException |
|
2019 | - * @throws EE_Error |
|
2020 | - */ |
|
2021 | - protected function _get_ticket_datetime_list_item( |
|
2022 | - $datetime_row, |
|
2023 | - $ticket_row, |
|
2024 | - $datetime, |
|
2025 | - $ticket, |
|
2026 | - $ticket_datetimes = array(), |
|
2027 | - $default |
|
2028 | - ) { |
|
2029 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2030 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
2031 | - : array(); |
|
2032 | - $template_args = array( |
|
2033 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2034 | - ? 'DTTNUM' |
|
2035 | - : $datetime_row, |
|
2036 | - 'tkt_row' => $default |
|
2037 | - ? 'TICKETNUM' |
|
2038 | - : $ticket_row, |
|
2039 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2040 | - ? ' ticket-selected' |
|
2041 | - : '', |
|
2042 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2043 | - ? ' checked="checked"' |
|
2044 | - : '', |
|
2045 | - 'DTT_name' => $default && empty($datetime) |
|
2046 | - ? 'DTTNAME' |
|
2047 | - : $datetime->get_dtt_display_name(true), |
|
2048 | - 'tkt_status_class' => '', |
|
2049 | - ); |
|
2050 | - $template_args = apply_filters( |
|
2051 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2052 | - $template_args, |
|
2053 | - $datetime_row, |
|
2054 | - $ticket_row, |
|
2055 | - $datetime, |
|
2056 | - $ticket, |
|
2057 | - $ticket_datetimes, |
|
2058 | - $default, |
|
2059 | - $this->_is_creating_event |
|
2060 | - ); |
|
2061 | - return EEH_Template::display_template( |
|
2062 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2063 | - $template_args, |
|
2064 | - true |
|
2065 | - ); |
|
2066 | - } |
|
2010 | + /** |
|
2011 | + * @param int $datetime_row |
|
2012 | + * @param int $ticket_row |
|
2013 | + * @param EE_Datetime|null $datetime |
|
2014 | + * @param EE_Ticket|null $ticket |
|
2015 | + * @param array $ticket_datetimes |
|
2016 | + * @param bool $default |
|
2017 | + * @return mixed |
|
2018 | + * @throws DomainException |
|
2019 | + * @throws EE_Error |
|
2020 | + */ |
|
2021 | + protected function _get_ticket_datetime_list_item( |
|
2022 | + $datetime_row, |
|
2023 | + $ticket_row, |
|
2024 | + $datetime, |
|
2025 | + $ticket, |
|
2026 | + $ticket_datetimes = array(), |
|
2027 | + $default |
|
2028 | + ) { |
|
2029 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2030 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
2031 | + : array(); |
|
2032 | + $template_args = array( |
|
2033 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
2034 | + ? 'DTTNUM' |
|
2035 | + : $datetime_row, |
|
2036 | + 'tkt_row' => $default |
|
2037 | + ? 'TICKETNUM' |
|
2038 | + : $ticket_row, |
|
2039 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
2040 | + ? ' ticket-selected' |
|
2041 | + : '', |
|
2042 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
2043 | + ? ' checked="checked"' |
|
2044 | + : '', |
|
2045 | + 'DTT_name' => $default && empty($datetime) |
|
2046 | + ? 'DTTNAME' |
|
2047 | + : $datetime->get_dtt_display_name(true), |
|
2048 | + 'tkt_status_class' => '', |
|
2049 | + ); |
|
2050 | + $template_args = apply_filters( |
|
2051 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
2052 | + $template_args, |
|
2053 | + $datetime_row, |
|
2054 | + $ticket_row, |
|
2055 | + $datetime, |
|
2056 | + $ticket, |
|
2057 | + $ticket_datetimes, |
|
2058 | + $default, |
|
2059 | + $this->_is_creating_event |
|
2060 | + ); |
|
2061 | + return EEH_Template::display_template( |
|
2062 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2063 | + $template_args, |
|
2064 | + true |
|
2065 | + ); |
|
2066 | + } |
|
2067 | 2067 | |
2068 | 2068 | |
2069 | - /** |
|
2070 | - * @param array $all_datetimes |
|
2071 | - * @param array $all_tickets |
|
2072 | - * @return mixed |
|
2073 | - * @throws ReflectionException |
|
2074 | - * @throws InvalidArgumentException |
|
2075 | - * @throws InvalidInterfaceException |
|
2076 | - * @throws InvalidDataTypeException |
|
2077 | - * @throws DomainException |
|
2078 | - * @throws EE_Error |
|
2079 | - */ |
|
2080 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2081 | - { |
|
2082 | - $template_args = array( |
|
2083 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2084 | - 'DTTNUM', |
|
2085 | - null, |
|
2086 | - true, |
|
2087 | - $all_datetimes |
|
2088 | - ), |
|
2089 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2090 | - 'TICKETNUM', |
|
2091 | - null, |
|
2092 | - array(), |
|
2093 | - array(), |
|
2094 | - true |
|
2095 | - ), |
|
2096 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2097 | - 'TICKETNUM', |
|
2098 | - 'PRICENUM', |
|
2099 | - null, |
|
2100 | - true, |
|
2101 | - null |
|
2102 | - ), |
|
2103 | - 'default_price_rows' => '', |
|
2104 | - 'default_base_price_amount' => 0, |
|
2105 | - 'default_base_price_name' => '', |
|
2106 | - 'default_base_price_description' => '', |
|
2107 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2108 | - 'TICKETNUM', |
|
2109 | - 'PRICENUM', |
|
2110 | - null, |
|
2111 | - true |
|
2112 | - ), |
|
2113 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2114 | - 'DTTNUM', |
|
2115 | - null, |
|
2116 | - array(), |
|
2117 | - array(), |
|
2118 | - true |
|
2119 | - ), |
|
2120 | - 'existing_available_datetime_tickets_list' => '', |
|
2121 | - 'existing_available_ticket_datetimes_list' => '', |
|
2122 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2123 | - 'DTTNUM', |
|
2124 | - 'TICKETNUM', |
|
2125 | - null, |
|
2126 | - null, |
|
2127 | - array(), |
|
2128 | - true |
|
2129 | - ), |
|
2130 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2131 | - 'DTTNUM', |
|
2132 | - 'TICKETNUM', |
|
2133 | - null, |
|
2134 | - null, |
|
2135 | - array(), |
|
2136 | - true |
|
2137 | - ), |
|
2138 | - ); |
|
2139 | - $ticket_row = 1; |
|
2140 | - foreach ($all_tickets as $ticket) { |
|
2141 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2142 | - 'DTTNUM', |
|
2143 | - $ticket_row, |
|
2144 | - null, |
|
2145 | - $ticket, |
|
2146 | - array(), |
|
2147 | - true |
|
2148 | - ); |
|
2149 | - $ticket_row++; |
|
2150 | - } |
|
2151 | - $datetime_row = 1; |
|
2152 | - foreach ($all_datetimes as $datetime) { |
|
2153 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2154 | - $datetime_row, |
|
2155 | - 'TICKETNUM', |
|
2156 | - $datetime, |
|
2157 | - null, |
|
2158 | - array(), |
|
2159 | - true |
|
2160 | - ); |
|
2161 | - $datetime_row++; |
|
2162 | - } |
|
2163 | - /** @var EEM_Price $price_model */ |
|
2164 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2165 | - $default_prices = $price_model->get_all_default_prices(); |
|
2166 | - $price_row = 1; |
|
2167 | - foreach ($default_prices as $price) { |
|
2168 | - if (! $price instanceof EE_Price) { |
|
2169 | - continue; |
|
2170 | - } |
|
2171 | - if ($price->is_base_price()) { |
|
2172 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2173 | - 'PRC_amount', |
|
2174 | - 'localized_float' |
|
2175 | - ); |
|
2176 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2177 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2178 | - $price_row++; |
|
2179 | - continue; |
|
2180 | - } |
|
2181 | - $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2182 | - || count($default_prices) === 1); |
|
2183 | - $show_create = ! (count($default_prices) > 1 |
|
2184 | - && count($default_prices) |
|
2185 | - !== $price_row); |
|
2186 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2187 | - 'TICKETNUM', |
|
2188 | - $price_row, |
|
2189 | - $price, |
|
2190 | - true, |
|
2191 | - null, |
|
2192 | - $show_trash, |
|
2193 | - $show_create |
|
2194 | - ); |
|
2195 | - $price_row++; |
|
2196 | - } |
|
2197 | - $template_args = apply_filters( |
|
2198 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2199 | - $template_args, |
|
2200 | - $all_datetimes, |
|
2201 | - $all_tickets, |
|
2202 | - $this->_is_creating_event |
|
2203 | - ); |
|
2204 | - return EEH_Template::display_template( |
|
2205 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2206 | - $template_args, |
|
2207 | - true |
|
2208 | - ); |
|
2209 | - } |
|
2069 | + /** |
|
2070 | + * @param array $all_datetimes |
|
2071 | + * @param array $all_tickets |
|
2072 | + * @return mixed |
|
2073 | + * @throws ReflectionException |
|
2074 | + * @throws InvalidArgumentException |
|
2075 | + * @throws InvalidInterfaceException |
|
2076 | + * @throws InvalidDataTypeException |
|
2077 | + * @throws DomainException |
|
2078 | + * @throws EE_Error |
|
2079 | + */ |
|
2080 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2081 | + { |
|
2082 | + $template_args = array( |
|
2083 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2084 | + 'DTTNUM', |
|
2085 | + null, |
|
2086 | + true, |
|
2087 | + $all_datetimes |
|
2088 | + ), |
|
2089 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2090 | + 'TICKETNUM', |
|
2091 | + null, |
|
2092 | + array(), |
|
2093 | + array(), |
|
2094 | + true |
|
2095 | + ), |
|
2096 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2097 | + 'TICKETNUM', |
|
2098 | + 'PRICENUM', |
|
2099 | + null, |
|
2100 | + true, |
|
2101 | + null |
|
2102 | + ), |
|
2103 | + 'default_price_rows' => '', |
|
2104 | + 'default_base_price_amount' => 0, |
|
2105 | + 'default_base_price_name' => '', |
|
2106 | + 'default_base_price_description' => '', |
|
2107 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2108 | + 'TICKETNUM', |
|
2109 | + 'PRICENUM', |
|
2110 | + null, |
|
2111 | + true |
|
2112 | + ), |
|
2113 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2114 | + 'DTTNUM', |
|
2115 | + null, |
|
2116 | + array(), |
|
2117 | + array(), |
|
2118 | + true |
|
2119 | + ), |
|
2120 | + 'existing_available_datetime_tickets_list' => '', |
|
2121 | + 'existing_available_ticket_datetimes_list' => '', |
|
2122 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2123 | + 'DTTNUM', |
|
2124 | + 'TICKETNUM', |
|
2125 | + null, |
|
2126 | + null, |
|
2127 | + array(), |
|
2128 | + true |
|
2129 | + ), |
|
2130 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2131 | + 'DTTNUM', |
|
2132 | + 'TICKETNUM', |
|
2133 | + null, |
|
2134 | + null, |
|
2135 | + array(), |
|
2136 | + true |
|
2137 | + ), |
|
2138 | + ); |
|
2139 | + $ticket_row = 1; |
|
2140 | + foreach ($all_tickets as $ticket) { |
|
2141 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2142 | + 'DTTNUM', |
|
2143 | + $ticket_row, |
|
2144 | + null, |
|
2145 | + $ticket, |
|
2146 | + array(), |
|
2147 | + true |
|
2148 | + ); |
|
2149 | + $ticket_row++; |
|
2150 | + } |
|
2151 | + $datetime_row = 1; |
|
2152 | + foreach ($all_datetimes as $datetime) { |
|
2153 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2154 | + $datetime_row, |
|
2155 | + 'TICKETNUM', |
|
2156 | + $datetime, |
|
2157 | + null, |
|
2158 | + array(), |
|
2159 | + true |
|
2160 | + ); |
|
2161 | + $datetime_row++; |
|
2162 | + } |
|
2163 | + /** @var EEM_Price $price_model */ |
|
2164 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2165 | + $default_prices = $price_model->get_all_default_prices(); |
|
2166 | + $price_row = 1; |
|
2167 | + foreach ($default_prices as $price) { |
|
2168 | + if (! $price instanceof EE_Price) { |
|
2169 | + continue; |
|
2170 | + } |
|
2171 | + if ($price->is_base_price()) { |
|
2172 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2173 | + 'PRC_amount', |
|
2174 | + 'localized_float' |
|
2175 | + ); |
|
2176 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2177 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2178 | + $price_row++; |
|
2179 | + continue; |
|
2180 | + } |
|
2181 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
2182 | + || count($default_prices) === 1); |
|
2183 | + $show_create = ! (count($default_prices) > 1 |
|
2184 | + && count($default_prices) |
|
2185 | + !== $price_row); |
|
2186 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2187 | + 'TICKETNUM', |
|
2188 | + $price_row, |
|
2189 | + $price, |
|
2190 | + true, |
|
2191 | + null, |
|
2192 | + $show_trash, |
|
2193 | + $show_create |
|
2194 | + ); |
|
2195 | + $price_row++; |
|
2196 | + } |
|
2197 | + $template_args = apply_filters( |
|
2198 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2199 | + $template_args, |
|
2200 | + $all_datetimes, |
|
2201 | + $all_tickets, |
|
2202 | + $this->_is_creating_event |
|
2203 | + ); |
|
2204 | + return EEH_Template::display_template( |
|
2205 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2206 | + $template_args, |
|
2207 | + true |
|
2208 | + ); |
|
2209 | + } |
|
2210 | 2210 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | $this->_name = 'pricing'; |
50 | 50 | // capability check |
51 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
51 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
52 | 52 | 'ee_read_default_prices', |
53 | 53 | 'advanced_ticket_datetime_metabox' |
54 | 54 | )) { |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | ); |
149 | 149 | $msg .= '</p><ul>'; |
150 | 150 | foreach ($format_validation as $error) { |
151 | - $msg .= '<li>' . $error . '</li>'; |
|
151 | + $msg .= '<li>'.$error.'</li>'; |
|
152 | 152 | } |
153 | 153 | $msg .= '</ul><p>'; |
154 | 154 | $msg .= sprintf( |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | $this->_scripts_styles = array( |
178 | 178 | 'registers' => array( |
179 | 179 | 'ee-tickets-datetimes-css' => array( |
180 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
180 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
181 | 181 | 'type' => 'css', |
182 | 182 | ), |
183 | 183 | 'ee-dtt-ticket-metabox' => array( |
184 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
184 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
185 | 185 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
186 | 186 | ), |
187 | 187 | ), |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | 'event_espresso' |
206 | 206 | ), |
207 | 207 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
208 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
208 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
209 | 209 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
210 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
210 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
211 | 211 | 'single_warning_from_tkt' => esc_html__( |
212 | 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 | 213 | 'event_espresso' |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | 'event_espresso' |
218 | 218 | ), |
219 | 219 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
220 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
220 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
221 | 221 | ), |
222 | 222 | 'DTT_ERROR_MSG' => array( |
223 | 223 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | { |
256 | 256 | foreach ($update_callbacks as $key => $callback) { |
257 | 257 | if ($callback[1] === '_default_tickets_update') { |
258 | - unset($update_callbacks[ $key ]); |
|
258 | + unset($update_callbacks[$key]); |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
314 | 314 | // trim all values to ensure any excess whitespace is removed. |
315 | 315 | $datetime_data = array_map( |
316 | - function ($datetime_data) { |
|
316 | + function($datetime_data) { |
|
317 | 317 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
318 | 318 | }, |
319 | 319 | $datetime_data |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | ); |
344 | 344 | // if we have an id then let's get existing object first and then set the new values. |
345 | 345 | // Otherwise we instantiate a new object for save. |
346 | - if (! empty($datetime_data['DTT_ID'])) { |
|
346 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
347 | 347 | $datetime = EE_Registry::instance() |
348 | 348 | ->load_model('Datetime', array($timezone)) |
349 | 349 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | // after the add_relation_to() the autosave replaces it. |
358 | 358 | // We need to do this so we dont' TRASH the parent DTT. |
359 | 359 | // (save the ID for both key and value to avoid duplications) |
360 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
360 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
361 | 361 | } else { |
362 | 362 | $datetime = EE_Registry::instance()->load_class( |
363 | 363 | 'Datetime', |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | // because it is possible there was a new one created for the autosave. |
387 | 387 | // (save the ID for both key and value to avoid duplications) |
388 | 388 | $DTT_ID = $datetime->ID(); |
389 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
390 | - $saved_dtt_objs[ $row ] = $datetime; |
|
389 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
390 | + $saved_dtt_objs[$row] = $datetime; |
|
391 | 391 | // @todo if ANY of these updates fail then we want the appropriate global error message. |
392 | 392 | } |
393 | 393 | $event->save(); |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | $update_prices = $create_new_TKT = false; |
453 | 453 | // figure out what datetimes were added to the ticket |
454 | 454 | // and what datetimes were removed from the ticket in the session. |
455 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
456 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
455 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
456 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
457 | 457 | $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
458 | 458 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
459 | 459 | // trim inputs to ensure any excess whitespace is removed. |
460 | 460 | $tkt = array_map( |
461 | - function ($ticket_data) { |
|
461 | + function($ticket_data) { |
|
462 | 462 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
463 | 463 | }, |
464 | 464 | $tkt |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | $base_price_id = isset($tkt['TKT_base_price_ID']) |
481 | 481 | ? $tkt['TKT_base_price_ID'] |
482 | 482 | : 0; |
483 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
484 | - ? $data['edit_prices'][ $row ] |
|
483 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
484 | + ? $data['edit_prices'][$row] |
|
485 | 485 | : array(); |
486 | 486 | $now = null; |
487 | 487 | if (empty($tkt['TKT_start_date'])) { |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | /** |
494 | 494 | * set the TKT_end_date to the first datetime attached to the ticket. |
495 | 495 | */ |
496 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
496 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
497 | 497 | $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
498 | 498 | } |
499 | 499 | $TKT_values = array( |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | // need to make sue that the TKT_price is accurate after saving the prices. |
629 | 629 | $ticket->ensure_TKT_Price_correct(); |
630 | 630 | // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
631 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
631 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
632 | 632 | $update_prices = true; |
633 | 633 | $new_default = clone $ticket; |
634 | 634 | $new_default->set('TKT_ID', 0); |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | // save new TKT |
674 | 674 | $new_tkt->save(); |
675 | 675 | // add new ticket to array |
676 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
676 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
677 | 677 | do_action( |
678 | 678 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
679 | 679 | $new_tkt, |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | ); |
684 | 684 | } else { |
685 | 685 | // add tkt to saved tkts |
686 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
686 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
687 | 687 | do_action( |
688 | 688 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
689 | 689 | $ticket, |
@@ -750,33 +750,33 @@ discard block |
||
750 | 750 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
751 | 751 | // and removing the ticket from datetimes it got removed from. |
752 | 752 | // first let's add datetimes |
753 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
753 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
754 | 754 | foreach ($added_datetimes as $row_id) { |
755 | 755 | $row_id = (int) $row_id; |
756 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
757 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
756 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
757 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
758 | 758 | // Is this an existing ticket (has an ID) and does it have any sold? |
759 | 759 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
760 | 760 | if ($ticket->ID() && $ticket->sold() > 0) { |
761 | - $saved_datetimes[ $row_id ]->increase_sold($ticket->sold()); |
|
762 | - $saved_datetimes[ $row_id ]->save(); |
|
761 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
762 | + $saved_datetimes[$row_id]->save(); |
|
763 | 763 | } |
764 | 764 | } |
765 | 765 | } |
766 | 766 | } |
767 | 767 | // then remove datetimes |
768 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
768 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
769 | 769 | foreach ($removed_datetimes as $row_id) { |
770 | 770 | $row_id = (int) $row_id; |
771 | 771 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
772 | 772 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
773 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
774 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
773 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
774 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
775 | 775 | // Is this an existing ticket (has an ID) and does it have any sold? |
776 | 776 | // If so, then we need to remove it's sold from the DTT_sold. |
777 | 777 | if ($ticket->ID() && $ticket->sold() > 0) { |
778 | - $saved_datetimes[ $row_id ]->decrease_sold($ticket->sold()); |
|
779 | - $saved_datetimes[ $row_id ]->save(); |
|
778 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
779 | + $saved_datetimes[$row_id]->save(); |
|
780 | 780 | } |
781 | 781 | } |
782 | 782 | } |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | ); |
890 | 890 | } |
891 | 891 | // possibly need to save tkt |
892 | - if (! $ticket->ID()) { |
|
892 | + if ( ! $ticket->ID()) { |
|
893 | 893 | $ticket->save(); |
894 | 894 | } |
895 | 895 | foreach ($prices as $row => $prc) { |
@@ -923,17 +923,17 @@ discard block |
||
923 | 923 | } |
924 | 924 | } |
925 | 925 | $price->save(); |
926 | - $updated_prices[ $price->ID() ] = $price; |
|
926 | + $updated_prices[$price->ID()] = $price; |
|
927 | 927 | $ticket->_add_relation_to($price, 'Price'); |
928 | 928 | } |
929 | 929 | // now let's remove any prices that got removed from the ticket |
930 | - if (! empty($current_prices_on_ticket)) { |
|
930 | + if ( ! empty($current_prices_on_ticket)) { |
|
931 | 931 | $current = array_keys($current_prices_on_ticket); |
932 | 932 | $updated = array_keys($updated_prices); |
933 | 933 | $prices_to_remove = array_diff($current, $updated); |
934 | - if (! empty($prices_to_remove)) { |
|
934 | + if ( ! empty($prices_to_remove)) { |
|
935 | 935 | foreach ($prices_to_remove as $prc_id) { |
936 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
936 | + $p = $current_prices_on_ticket[$prc_id]; |
|
937 | 937 | $ticket->_remove_relation_to($p, 'Price'); |
938 | 938 | // delete permanently the price |
939 | 939 | $p->delete_permanently(); |
@@ -1084,17 +1084,17 @@ discard block |
||
1084 | 1084 | $TKT_ID = $ticket->get('TKT_ID'); |
1085 | 1085 | $ticket_row = $ticket->get('TKT_row'); |
1086 | 1086 | // we only want unique tickets in our final display!! |
1087 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1087 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1088 | 1088 | $existing_ticket_ids[] = $TKT_ID; |
1089 | 1089 | $all_tickets[] = $ticket; |
1090 | 1090 | } |
1091 | 1091 | // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
1092 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
1092 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1093 | 1093 | // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
1094 | - if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
1095 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
1094 | + if ( ! isset($ticket_datetimes[$TKT_ID]) |
|
1095 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1096 | 1096 | ) { |
1097 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
1097 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1098 | 1098 | } |
1099 | 1099 | } |
1100 | 1100 | $datetime_row++; |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | // sort $all_tickets by order |
1106 | 1106 | usort( |
1107 | 1107 | $all_tickets, |
1108 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1108 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
1109 | 1109 | $a_order = (int) $a->get('TKT_order'); |
1110 | 1110 | $b_order = (int) $b->get('TKT_order'); |
1111 | 1111 | if ($a_order === $b_order) { |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | } |
1144 | 1144 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
1145 | 1145 | EEH_Template::display_template( |
1146 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1146 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
1147 | 1147 | $main_template_args |
1148 | 1148 | ); |
1149 | 1149 | } |
@@ -1185,7 +1185,7 @@ discard block |
||
1185 | 1185 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
1186 | 1186 | ); |
1187 | 1187 | return EEH_Template::display_template( |
1188 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1188 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
1189 | 1189 | $dtt_display_template_args, |
1190 | 1190 | true |
1191 | 1191 | ); |
@@ -1254,7 +1254,7 @@ discard block |
||
1254 | 1254 | $this->_is_creating_event |
1255 | 1255 | ); |
1256 | 1256 | return EEH_Template::display_template( |
1257 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1257 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
1258 | 1258 | $template_args, |
1259 | 1259 | true |
1260 | 1260 | ); |
@@ -1295,7 +1295,7 @@ discard block |
||
1295 | 1295 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
1296 | 1296 | ); |
1297 | 1297 | // need to setup the list items (but only if this isn't a default skeleton setup) |
1298 | - if (! $default) { |
|
1298 | + if ( ! $default) { |
|
1299 | 1299 | $ticket_row = 1; |
1300 | 1300 | foreach ($all_tickets as $ticket) { |
1301 | 1301 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1321,7 +1321,7 @@ discard block |
||
1321 | 1321 | $this->_is_creating_event |
1322 | 1322 | ); |
1323 | 1323 | return EEH_Template::display_template( |
1324 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1324 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
1325 | 1325 | $template_args, |
1326 | 1326 | true |
1327 | 1327 | ); |
@@ -1347,8 +1347,8 @@ discard block |
||
1347 | 1347 | $datetime_tickets = array(), |
1348 | 1348 | $default |
1349 | 1349 | ) { |
1350 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
1351 | - ? $datetime_tickets[ $datetime->ID() ] |
|
1350 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1351 | + ? $datetime_tickets[$datetime->ID()] |
|
1352 | 1352 | : array(); |
1353 | 1353 | $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
1354 | 1354 | $no_ticket = $default && empty($ticket); |
@@ -1369,8 +1369,8 @@ discard block |
||
1369 | 1369 | ? 'TKTNAME' |
1370 | 1370 | : $ticket->get('TKT_name'), |
1371 | 1371 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
1372 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1373 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1372 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1373 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
1374 | 1374 | ); |
1375 | 1375 | // filter template args |
1376 | 1376 | $template_args = apply_filters( |
@@ -1385,7 +1385,7 @@ discard block |
||
1385 | 1385 | $this->_is_creating_event |
1386 | 1386 | ); |
1387 | 1387 | return EEH_Template::display_template( |
1388 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1388 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1389 | 1389 | $template_args, |
1390 | 1390 | true |
1391 | 1391 | ); |
@@ -1441,19 +1441,19 @@ discard block |
||
1441 | 1441 | // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
1442 | 1442 | // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
1443 | 1443 | $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
1444 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
1445 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
1444 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1445 | + ? $ticket_datetimes[$ticket->ID()] |
|
1446 | 1446 | : array(); |
1447 | 1447 | $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
1448 | 1448 | $base_price = $default ? null : $ticket->base_price(); |
1449 | 1449 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
1450 | 1450 | // breaking out complicated condition for ticket_status |
1451 | 1451 | if ($default) { |
1452 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1452 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
1453 | 1453 | } else { |
1454 | 1454 | $ticket_status_class = $ticket->is_default() |
1455 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1456 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1455 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1456 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
1457 | 1457 | } |
1458 | 1458 | // breaking out complicated condition for TKT_taxable |
1459 | 1459 | if ($default) { |
@@ -1545,7 +1545,7 @@ discard block |
||
1545 | 1545 | : ' style="display:none;"', |
1546 | 1546 | 'show_price_mod_button' => count($prices) > 1 |
1547 | 1547 | || ($default && $count_price_mods > 0) |
1548 | - || (! $default && $ticket->deleted()) |
|
1548 | + || ( ! $default && $ticket->deleted()) |
|
1549 | 1549 | ? ' style="display:none;"' |
1550 | 1550 | : '', |
1551 | 1551 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1589,7 +1589,7 @@ discard block |
||
1589 | 1589 | $this->_date_time_format, |
1590 | 1590 | current_time('timestamp') |
1591 | 1591 | ); |
1592 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1592 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1593 | 1593 | } |
1594 | 1594 | if (empty($template_args['TKT_end_date'])) { |
1595 | 1595 | // get the earliest datetime (if present); |
@@ -1599,7 +1599,7 @@ discard block |
||
1599 | 1599 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1600 | 1600 | ) |
1601 | 1601 | : null; |
1602 | - if (! empty($earliest_dtt)) { |
|
1602 | + if ( ! empty($earliest_dtt)) { |
|
1603 | 1603 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
1604 | 1604 | 'DTT_EVT_start', |
1605 | 1605 | $this->_date_time_format |
@@ -1618,10 +1618,10 @@ discard block |
||
1618 | 1618 | ) |
1619 | 1619 | ); |
1620 | 1620 | } |
1621 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1621 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1622 | 1622 | } |
1623 | 1623 | // generate ticket_datetime items |
1624 | - if (! $default) { |
|
1624 | + if ( ! $default) { |
|
1625 | 1625 | $datetime_row = 1; |
1626 | 1626 | foreach ($all_datetimes as $datetime) { |
1627 | 1627 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1637,7 +1637,7 @@ discard block |
||
1637 | 1637 | } |
1638 | 1638 | $price_row = 1; |
1639 | 1639 | foreach ($prices as $price) { |
1640 | - if (! $price instanceof EE_Price) { |
|
1640 | + if ( ! $price instanceof EE_Price) { |
|
1641 | 1641 | continue; |
1642 | 1642 | } |
1643 | 1643 | if ($price->is_base_price()) { |
@@ -1670,7 +1670,7 @@ discard block |
||
1670 | 1670 | $this->_is_creating_event |
1671 | 1671 | ); |
1672 | 1672 | return EEH_Template::display_template( |
1673 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1673 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
1674 | 1674 | $template_args, |
1675 | 1675 | true |
1676 | 1676 | ); |
@@ -1710,7 +1710,7 @@ discard block |
||
1710 | 1710 | $this->_is_creating_event |
1711 | 1711 | ); |
1712 | 1712 | $tax_rows .= EEH_Template::display_template( |
1713 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1713 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
1714 | 1714 | $template_args, |
1715 | 1715 | true |
1716 | 1716 | ); |
@@ -1829,7 +1829,7 @@ discard block |
||
1829 | 1829 | $this->_is_creating_event |
1830 | 1830 | ); |
1831 | 1831 | return EEH_Template::display_template( |
1832 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1832 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
1833 | 1833 | $template_args, |
1834 | 1834 | true |
1835 | 1835 | ); |
@@ -1899,7 +1899,7 @@ discard block |
||
1899 | 1899 | $this->_is_creating_event |
1900 | 1900 | ); |
1901 | 1901 | return EEH_Template::display_template( |
1902 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1902 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
1903 | 1903 | $template_args, |
1904 | 1904 | true |
1905 | 1905 | ); |
@@ -1929,7 +1929,7 @@ discard block |
||
1929 | 1929 | ) { |
1930 | 1930 | $select_name = $default && ! $price instanceof EE_Price |
1931 | 1931 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
1932 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1932 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
1933 | 1933 | /** @var EEM_Price_Type $price_type_model */ |
1934 | 1934 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
1935 | 1935 | $price_types = $price_type_model->get_all(array( |
@@ -1947,10 +1947,10 @@ discard block |
||
1947 | 1947 | $price_option_spans = ''; |
1948 | 1948 | // setup price types for selector |
1949 | 1949 | foreach ($price_types as $price_type) { |
1950 | - if (! $price_type instanceof EE_Price_Type) { |
|
1950 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
1951 | 1951 | continue; |
1952 | 1952 | } |
1953 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
1953 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1954 | 1954 | // while we're in the loop let's setup the option spans used by js |
1955 | 1955 | $span_args = array( |
1956 | 1956 | 'PRT_ID' => $price_type->ID(), |
@@ -1958,12 +1958,12 @@ discard block |
||
1958 | 1958 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
1959 | 1959 | ); |
1960 | 1960 | $price_option_spans .= EEH_Template::display_template( |
1961 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1961 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
1962 | 1962 | $span_args, |
1963 | 1963 | true |
1964 | 1964 | ); |
1965 | 1965 | } |
1966 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
1966 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' |
|
1967 | 1967 | : $select_name; |
1968 | 1968 | $select_input = new EE_Select_Input( |
1969 | 1969 | $all_price_types, |
@@ -2000,7 +2000,7 @@ discard block |
||
2000 | 2000 | $this->_is_creating_event |
2001 | 2001 | ); |
2002 | 2002 | return EEH_Template::display_template( |
2003 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
2003 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
2004 | 2004 | $template_args, |
2005 | 2005 | true |
2006 | 2006 | ); |
@@ -2026,8 +2026,8 @@ discard block |
||
2026 | 2026 | $ticket_datetimes = array(), |
2027 | 2027 | $default |
2028 | 2028 | ) { |
2029 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
2030 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
2029 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
2030 | + ? $ticket_datetimes[$ticket->ID()] |
|
2031 | 2031 | : array(); |
2032 | 2032 | $template_args = array( |
2033 | 2033 | 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
@@ -2059,7 +2059,7 @@ discard block |
||
2059 | 2059 | $this->_is_creating_event |
2060 | 2060 | ); |
2061 | 2061 | return EEH_Template::display_template( |
2062 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2062 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
2063 | 2063 | $template_args, |
2064 | 2064 | true |
2065 | 2065 | ); |
@@ -2165,7 +2165,7 @@ discard block |
||
2165 | 2165 | $default_prices = $price_model->get_all_default_prices(); |
2166 | 2166 | $price_row = 1; |
2167 | 2167 | foreach ($default_prices as $price) { |
2168 | - if (! $price instanceof EE_Price) { |
|
2168 | + if ( ! $price instanceof EE_Price) { |
|
2169 | 2169 | continue; |
2170 | 2170 | } |
2171 | 2171 | if ($price->is_base_price()) { |
@@ -2202,7 +2202,7 @@ discard block |
||
2202 | 2202 | $this->_is_creating_event |
2203 | 2203 | ); |
2204 | 2204 | return EEH_Template::display_template( |
2205 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2205 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
2206 | 2206 | $template_args, |
2207 | 2207 | true |
2208 | 2208 | ); |