@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use WP_Post; |
| 17 | 17 | |
| 18 | 18 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 19 | - exit( 'No direct script access allowed' ); |
|
| 19 | + exit( 'No direct script access allowed' ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -33,679 +33,679 @@ discard block |
||
| 33 | 33 | class DisplayTicketSelector |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * event that ticket selector is being generated for |
|
| 38 | - * |
|
| 39 | - * @access protected |
|
| 40 | - * @var EE_Event $event |
|
| 41 | - */ |
|
| 42 | - protected $event; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | - * |
|
| 47 | - * @var bool $iframe |
|
| 48 | - */ |
|
| 49 | - protected $iframe = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * max attendees that can register for event at one time |
|
| 53 | - * |
|
| 54 | - * @var int $max_attendees |
|
| 55 | - */ |
|
| 56 | - private $max_attendees = EE_INF; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - *@var string $date_format |
|
| 60 | - */ |
|
| 61 | - private $date_format; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - *@var string $time_format |
|
| 65 | - */ |
|
| 66 | - private $time_format; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * DisplayTicketSelector constructor. |
|
| 72 | - */ |
|
| 73 | - public function __construct() |
|
| 74 | - { |
|
| 75 | - $this->date_format = apply_filters( |
|
| 76 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 77 | - get_option('date_format') |
|
| 78 | - ); |
|
| 79 | - $this->time_format = apply_filters( |
|
| 80 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 81 | - get_option('time_format') |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param boolean $iframe |
|
| 89 | - */ |
|
| 90 | - public function setIframe( $iframe = true ) |
|
| 91 | - { |
|
| 92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * finds and sets the \EE_Event object for use throughout class |
|
| 98 | - * |
|
| 99 | - * @param mixed $event |
|
| 100 | - * @return bool |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function setEvent( $event = null ) |
|
| 104 | - { |
|
| 105 | - if ( $event === null ) { |
|
| 106 | - global $post; |
|
| 107 | - $event = $post; |
|
| 108 | - } |
|
| 109 | - if ( $event instanceof EE_Event ) { |
|
| 110 | - $this->event = $event; |
|
| 111 | - } else if ( $event instanceof WP_Post ) { |
|
| 112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 113 | - $this->event = $event->EE_Event; |
|
| 114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 116 | - $this->event = $event->EE_Event; |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | - $dev_msg = $user_msg . __( |
|
| 121 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 122 | - 'event_espresso' |
|
| 123 | - ); |
|
| 124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - return true; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function getMaxAttendees() |
|
| 136 | - { |
|
| 137 | - return $this->max_attendees; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param int $max_attendees |
|
| 144 | - */ |
|
| 145 | - public function setMaxAttendees($max_attendees) |
|
| 146 | - { |
|
| 147 | - $this->max_attendees = absint( |
|
| 148 | - apply_filters( |
|
| 149 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 150 | - $max_attendees |
|
| 151 | - ) |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * creates buttons for selecting number of attendees for an event |
|
| 159 | - * |
|
| 160 | - * @param WP_Post|int $event |
|
| 161 | - * @param bool $view_details |
|
| 162 | - * @return string |
|
| 163 | - * @throws EE_Error |
|
| 164 | - */ |
|
| 165 | - public function display( $event = null, $view_details = false ) |
|
| 166 | - { |
|
| 167 | - // reset filter for displaying submit button |
|
| 168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 169 | - // poke and prod incoming event till it tells us what it is |
|
| 170 | - if ( ! $this->setEvent( $event ) ) { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - // begin gathering template arguments by getting event status |
|
| 174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 176 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 177 | - } |
|
| 178 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 179 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
| 180 | - if ($this->getMaxAttendees() < 1) { |
|
| 181 | - return $this->ticketSalesClosedMessage(); |
|
| 182 | - } |
|
| 183 | - // is the event expired ? |
|
| 184 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 186 | - return $this->expiredEventMessage(); |
|
| 187 | - } |
|
| 188 | - // get all tickets for this event ordered by the datetime |
|
| 189 | - $tickets = $this->getTickets(); |
|
| 190 | - if (count($tickets) < 1) { |
|
| 191 | - return $this->noTicketAvailableMessage(); |
|
| 192 | - } |
|
| 193 | - if (EED_Events_Archive::is_iframe()){ |
|
| 194 | - $this->setIframe(); |
|
| 195 | - } |
|
| 196 | - // redirecting to another site for registration ?? |
|
| 197 | - $external_url = (string) $this->event->external_url(); |
|
| 198 | - // if redirecting to another site for registration, then we don't load the TS |
|
| 199 | - $ticket_selector = $external_url |
|
| 200 | - ? $this->externalEventRegistration() |
|
| 201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
| 202 | - // now set up the form (but not for the admin) |
|
| 203 | - $ticket_selector = ! is_admin() |
|
| 204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 205 | - : $ticket_selector; |
|
| 206 | - // submit button and form close tag |
|
| 207 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
| 208 | - return $ticket_selector; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * displayTicketSelector |
|
| 215 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 216 | - * |
|
| 217 | - * @param WP_Post|int $event |
|
| 218 | - * @param string $_event_active_status |
|
| 219 | - * @param bool $view_details |
|
| 220 | - * @return bool |
|
| 221 | - * @throws EE_Error |
|
| 222 | - */ |
|
| 223 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 224 | - { |
|
| 225 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 226 | - return ! is_admin() |
|
| 227 | - && ( |
|
| 228 | - ! $this->event->display_ticket_selector() |
|
| 229 | - || $view_details |
|
| 230 | - || post_password_required($event_post) |
|
| 231 | - || ( |
|
| 232 | - $_event_active_status !== EE_Datetime::active |
|
| 233 | - && $_event_active_status !== EE_Datetime::upcoming |
|
| 234 | - && $_event_active_status !== EE_Datetime::sold_out |
|
| 235 | - && ! ( |
|
| 236 | - $_event_active_status === EE_Datetime::inactive |
|
| 237 | - && is_user_logged_in() |
|
| 238 | - ) |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * noTicketAvailableMessage |
|
| 247 | - * notice displayed if event is expired |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - * @throws EE_Error |
|
| 251 | - */ |
|
| 252 | - protected function expiredEventMessage() |
|
| 253 | - { |
|
| 254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 255 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 256 | - 'event_espresso' |
|
| 257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * noTicketAvailableMessage |
|
| 264 | - * notice displayed if event has no more tickets available |
|
| 265 | - * |
|
| 266 | - * @return string |
|
| 267 | - * @throws EE_Error |
|
| 268 | - */ |
|
| 269 | - protected function noTicketAvailableMessage() |
|
| 270 | - { |
|
| 271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 272 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 273 | - $no_ticket_available_msg .= sprintf( |
|
| 274 | - esc_html__( |
|
| 275 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 276 | - 'event_espresso' |
|
| 277 | - ), |
|
| 278 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 279 | - '</b><br />', |
|
| 280 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 281 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - return ' |
|
| 36 | + /** |
|
| 37 | + * event that ticket selector is being generated for |
|
| 38 | + * |
|
| 39 | + * @access protected |
|
| 40 | + * @var EE_Event $event |
|
| 41 | + */ |
|
| 42 | + protected $event; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | + * |
|
| 47 | + * @var bool $iframe |
|
| 48 | + */ |
|
| 49 | + protected $iframe = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * max attendees that can register for event at one time |
|
| 53 | + * |
|
| 54 | + * @var int $max_attendees |
|
| 55 | + */ |
|
| 56 | + private $max_attendees = EE_INF; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + *@var string $date_format |
|
| 60 | + */ |
|
| 61 | + private $date_format; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + *@var string $time_format |
|
| 65 | + */ |
|
| 66 | + private $time_format; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * DisplayTicketSelector constructor. |
|
| 72 | + */ |
|
| 73 | + public function __construct() |
|
| 74 | + { |
|
| 75 | + $this->date_format = apply_filters( |
|
| 76 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 77 | + get_option('date_format') |
|
| 78 | + ); |
|
| 79 | + $this->time_format = apply_filters( |
|
| 80 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 81 | + get_option('time_format') |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param boolean $iframe |
|
| 89 | + */ |
|
| 90 | + public function setIframe( $iframe = true ) |
|
| 91 | + { |
|
| 92 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * finds and sets the \EE_Event object for use throughout class |
|
| 98 | + * |
|
| 99 | + * @param mixed $event |
|
| 100 | + * @return bool |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function setEvent( $event = null ) |
|
| 104 | + { |
|
| 105 | + if ( $event === null ) { |
|
| 106 | + global $post; |
|
| 107 | + $event = $post; |
|
| 108 | + } |
|
| 109 | + if ( $event instanceof EE_Event ) { |
|
| 110 | + $this->event = $event; |
|
| 111 | + } else if ( $event instanceof WP_Post ) { |
|
| 112 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 113 | + $this->event = $event->EE_Event; |
|
| 114 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 116 | + $this->event = $event->EE_Event; |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | + $dev_msg = $user_msg . __( |
|
| 121 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 122 | + 'event_espresso' |
|
| 123 | + ); |
|
| 124 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + return true; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function getMaxAttendees() |
|
| 136 | + { |
|
| 137 | + return $this->max_attendees; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param int $max_attendees |
|
| 144 | + */ |
|
| 145 | + public function setMaxAttendees($max_attendees) |
|
| 146 | + { |
|
| 147 | + $this->max_attendees = absint( |
|
| 148 | + apply_filters( |
|
| 149 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 150 | + $max_attendees |
|
| 151 | + ) |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * creates buttons for selecting number of attendees for an event |
|
| 159 | + * |
|
| 160 | + * @param WP_Post|int $event |
|
| 161 | + * @param bool $view_details |
|
| 162 | + * @return string |
|
| 163 | + * @throws EE_Error |
|
| 164 | + */ |
|
| 165 | + public function display( $event = null, $view_details = false ) |
|
| 166 | + { |
|
| 167 | + // reset filter for displaying submit button |
|
| 168 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 169 | + // poke and prod incoming event till it tells us what it is |
|
| 170 | + if ( ! $this->setEvent( $event ) ) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + // begin gathering template arguments by getting event status |
|
| 174 | + $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | + if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 176 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 177 | + } |
|
| 178 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 179 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
| 180 | + if ($this->getMaxAttendees() < 1) { |
|
| 181 | + return $this->ticketSalesClosedMessage(); |
|
| 182 | + } |
|
| 183 | + // is the event expired ? |
|
| 184 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 185 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
| 186 | + return $this->expiredEventMessage(); |
|
| 187 | + } |
|
| 188 | + // get all tickets for this event ordered by the datetime |
|
| 189 | + $tickets = $this->getTickets(); |
|
| 190 | + if (count($tickets) < 1) { |
|
| 191 | + return $this->noTicketAvailableMessage(); |
|
| 192 | + } |
|
| 193 | + if (EED_Events_Archive::is_iframe()){ |
|
| 194 | + $this->setIframe(); |
|
| 195 | + } |
|
| 196 | + // redirecting to another site for registration ?? |
|
| 197 | + $external_url = (string) $this->event->external_url(); |
|
| 198 | + // if redirecting to another site for registration, then we don't load the TS |
|
| 199 | + $ticket_selector = $external_url |
|
| 200 | + ? $this->externalEventRegistration() |
|
| 201 | + : $this->loadTicketSelector($tickets,$template_args); |
|
| 202 | + // now set up the form (but not for the admin) |
|
| 203 | + $ticket_selector = ! is_admin() |
|
| 204 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 205 | + : $ticket_selector; |
|
| 206 | + // submit button and form close tag |
|
| 207 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
| 208 | + return $ticket_selector; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * displayTicketSelector |
|
| 215 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 216 | + * |
|
| 217 | + * @param WP_Post|int $event |
|
| 218 | + * @param string $_event_active_status |
|
| 219 | + * @param bool $view_details |
|
| 220 | + * @return bool |
|
| 221 | + * @throws EE_Error |
|
| 222 | + */ |
|
| 223 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 224 | + { |
|
| 225 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 226 | + return ! is_admin() |
|
| 227 | + && ( |
|
| 228 | + ! $this->event->display_ticket_selector() |
|
| 229 | + || $view_details |
|
| 230 | + || post_password_required($event_post) |
|
| 231 | + || ( |
|
| 232 | + $_event_active_status !== EE_Datetime::active |
|
| 233 | + && $_event_active_status !== EE_Datetime::upcoming |
|
| 234 | + && $_event_active_status !== EE_Datetime::sold_out |
|
| 235 | + && ! ( |
|
| 236 | + $_event_active_status === EE_Datetime::inactive |
|
| 237 | + && is_user_logged_in() |
|
| 238 | + ) |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * noTicketAvailableMessage |
|
| 247 | + * notice displayed if event is expired |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + * @throws EE_Error |
|
| 251 | + */ |
|
| 252 | + protected function expiredEventMessage() |
|
| 253 | + { |
|
| 254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 255 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 256 | + 'event_espresso' |
|
| 257 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * noTicketAvailableMessage |
|
| 264 | + * notice displayed if event has no more tickets available |
|
| 265 | + * |
|
| 266 | + * @return string |
|
| 267 | + * @throws EE_Error |
|
| 268 | + */ |
|
| 269 | + protected function noTicketAvailableMessage() |
|
| 270 | + { |
|
| 271 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 272 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 273 | + $no_ticket_available_msg .= sprintf( |
|
| 274 | + esc_html__( |
|
| 275 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 276 | + 'event_espresso' |
|
| 277 | + ), |
|
| 278 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 279 | + '</b><br />', |
|
| 280 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 281 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + return ' |
|
| 285 | 285 | <div class="ee-event-expired-notice"> |
| 286 | 286 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
| 287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * ticketSalesClosed |
|
| 294 | - * notice displayed if event ticket sales are turned off |
|
| 295 | - * |
|
| 296 | - * @return string |
|
| 297 | - * @throws EE_Error |
|
| 298 | - */ |
|
| 299 | - protected function ticketSalesClosedMessage() |
|
| 300 | - { |
|
| 301 | - $sales_closed_msg = esc_html__( |
|
| 302 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 303 | - 'event_espresso' |
|
| 304 | - ); |
|
| 305 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 306 | - $sales_closed_msg .= sprintf( |
|
| 307 | - esc_html__( |
|
| 308 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 309 | - 'event_espresso' |
|
| 310 | - ), |
|
| 311 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 312 | - '</b><br />', |
|
| 313 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 314 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * getTickets |
|
| 324 | - * |
|
| 325 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 326 | - * @throws EE_Error |
|
| 327 | - */ |
|
| 328 | - protected function getTickets() |
|
| 329 | - { |
|
| 330 | - $ticket_query_args = array( |
|
| 331 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 332 | - 'order_by' => array( |
|
| 333 | - 'TKT_order' => 'ASC', |
|
| 334 | - 'TKT_required' => 'DESC', |
|
| 335 | - 'TKT_start_date' => 'ASC', |
|
| 336 | - 'TKT_end_date' => 'ASC', |
|
| 337 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 338 | - ), |
|
| 339 | - ); |
|
| 340 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
| 341 | - //use the correct applicable time query depending on what version of core is being run. |
|
| 342 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 343 | - ? time() |
|
| 344 | - : current_time('timestamp'); |
|
| 345 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 346 | - } |
|
| 347 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * loadTicketSelector |
|
| 354 | - * begins to assemble template arguments |
|
| 355 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
| 356 | - * |
|
| 357 | - * @param \EE_Ticket[] $tickets |
|
| 358 | - * @param array $template_args |
|
| 359 | - * @return string |
|
| 360 | - * @throws EE_Error |
|
| 361 | - */ |
|
| 362 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 363 | - { |
|
| 364 | - $template_args['event'] = $this->event; |
|
| 365 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
| 366 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 367 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 368 | - $template_args['date_format'] = $this->date_format; |
|
| 369 | - $template_args['time_format'] = $this->time_format; |
|
| 370 | - /** |
|
| 371 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 372 | - * |
|
| 373 | - * @since 4.9.13 |
|
| 374 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 375 | - * @param int $EVT_ID The Event ID |
|
| 376 | - */ |
|
| 377 | - $template_args['anchor_id'] = apply_filters( |
|
| 378 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 380 | - $this->event->ID() |
|
| 381 | - ); |
|
| 382 | - $template_args['tickets'] = $tickets; |
|
| 383 | - $template_args['ticket_count'] = count($tickets); |
|
| 384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 385 | - return $ticket_selector instanceof TicketSelectorSimple |
|
| 386 | - ? $ticket_selector |
|
| 387 | - : new TicketSelectorStandard( |
|
| 388 | - $this->event, |
|
| 389 | - $tickets, |
|
| 390 | - $this->getMaxAttendees(), |
|
| 391 | - $template_args, |
|
| 392 | - $this->date_format, |
|
| 393 | - $this->time_format |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * simpleTicketSelector |
|
| 401 | - * there's one ticket, and max attendees is set to one, |
|
| 402 | - * so if the event is free, then this is a "simple" ticket selector |
|
| 403 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 404 | - * |
|
| 405 | - * @param \EE_Ticket[] $tickets |
|
| 406 | - * @param array $template_args |
|
| 407 | - * @return string |
|
| 408 | - * @throws EE_Error |
|
| 409 | - */ |
|
| 410 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
| 411 | - { |
|
| 412 | - // if there is only ONE ticket with a max qty of ONE |
|
| 413 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 414 | - return ''; |
|
| 415 | - } |
|
| 416 | - /** @var \EE_Ticket $ticket */ |
|
| 417 | - $ticket = reset($tickets); |
|
| 418 | - // if the ticket is free... then not much need for the ticket selector |
|
| 419 | - if ( |
|
| 420 | - apply_filters( |
|
| 421 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 422 | - $ticket->is_free(), |
|
| 423 | - $this->event->ID() |
|
| 424 | - ) |
|
| 425 | - ) { |
|
| 426 | - return new TicketSelectorSimple( |
|
| 427 | - $this->event, |
|
| 428 | - $ticket, |
|
| 429 | - $this->getMaxAttendees(), |
|
| 430 | - $template_args |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * externalEventRegistration |
|
| 440 | - * |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function externalEventRegistration() |
|
| 444 | - { |
|
| 445 | - // if not we still need to trigger the display of the submit button |
|
| 446 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 447 | - //display notice to admin that registration is external |
|
| 448 | - return is_admin() |
|
| 449 | - ? esc_html__( |
|
| 450 | - 'Registration is at an external URL for this event.', |
|
| 451 | - 'event_espresso' |
|
| 452 | - ) |
|
| 453 | - : ''; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * formOpen |
|
| 460 | - * |
|
| 461 | - * @param int $ID |
|
| 462 | - * @param string $external_url |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 466 | - { |
|
| 467 | - // if redirecting, we don't need any anything else |
|
| 468 | - if ( $external_url ) { |
|
| 469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 470 | - // open link in new window ? |
|
| 471 | - $html .= apply_filters( |
|
| 472 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 473 | - EED_Events_Archive::is_iframe() |
|
| 474 | - ) |
|
| 475 | - ? ' target="_blank"' |
|
| 476 | - : ''; |
|
| 477 | - $html .= '>'; |
|
| 478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 481 | - } |
|
| 482 | - return $html; |
|
| 483 | - } |
|
| 484 | - // if there is no submit button, then don't start building a form |
|
| 485 | - // because the "View Details" button will build its own form |
|
| 486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | - if ( ! $checkout_url ) { |
|
| 491 | - EE_Error::add_error( |
|
| 492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 493 | - __FILE__, |
|
| 494 | - __FUNCTION__, |
|
| 495 | - __LINE__ |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - // set no cache headers and constants |
|
| 499 | - EE_System::do_not_cache(); |
|
| 500 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 502 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 504 | - return $html; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * displaySubmitButton |
|
| 511 | - * |
|
| 512 | - * @param string $external_url |
|
| 513 | - * @return string |
|
| 514 | - * @throws EE_Error |
|
| 515 | - */ |
|
| 516 | - public function displaySubmitButton($external_url = '') |
|
| 517 | - { |
|
| 518 | - $html = ''; |
|
| 519 | - if ( ! is_admin()) { |
|
| 520 | - // standard TS displayed with submit button, ie: "Register Now" |
|
| 521 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 522 | - $html .= $this->displayRegisterNowButton(); |
|
| 523 | - $html .= empty($external_url) |
|
| 524 | - ? $this->ticketSelectorEndDiv() |
|
| 525 | - : $this->clearTicketSelector(); |
|
| 526 | - $html .= '<br/>' . $this->formClose(); |
|
| 527 | - } else if ($this->getMaxAttendees() === 1) { |
|
| 528 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 529 | - if ($this->event->is_sold_out()) { |
|
| 530 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 531 | - $html .= apply_filters( |
|
| 532 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 533 | - sprintf( |
|
| 534 | - __( |
|
| 535 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 536 | - 'event_espresso' |
|
| 537 | - ), |
|
| 538 | - '<p class="no-ticket-selector-msg clear-float">', |
|
| 539 | - $this->event->name(), |
|
| 540 | - '</p>', |
|
| 541 | - '<br />' |
|
| 542 | - ), |
|
| 543 | - $this->event |
|
| 544 | - ); |
|
| 545 | - if ( |
|
| 546 | - apply_filters( |
|
| 547 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 548 | - false, |
|
| 549 | - $this->event |
|
| 550 | - ) |
|
| 551 | - ) { |
|
| 552 | - $html .= $this->displayRegisterNowButton(); |
|
| 553 | - } |
|
| 554 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 555 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | - } else if ( |
|
| 557 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 558 | - && ! is_single() |
|
| 559 | - ) { |
|
| 560 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 561 | - // but no tickets are available, so display event's "View Details" button. |
|
| 562 | - // it is being viewed via somewhere other than a single post |
|
| 563 | - $html .= $this->displayViewDetailsButton(true); |
|
| 564 | - } else { |
|
| 565 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 566 | - } |
|
| 567 | - } else if (is_archive()) { |
|
| 568 | - // event list, no tickets available so display event's "View Details" button |
|
| 569 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 570 | - $html .= $this->displayViewDetailsButton(); |
|
| 571 | - } else { |
|
| 572 | - if ( |
|
| 573 | - apply_filters( |
|
| 574 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 575 | - false, |
|
| 576 | - $this->event |
|
| 577 | - ) |
|
| 578 | - ) { |
|
| 579 | - $html .= $this->displayRegisterNowButton(); |
|
| 580 | - } |
|
| 581 | - // no submit or view details button, and no additional content |
|
| 582 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 583 | - } |
|
| 584 | - if ( ! $this->iframe && ! is_archive()) { |
|
| 585 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - return $html; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * @return string |
|
| 595 | - * @throws EE_Error |
|
| 596 | - */ |
|
| 597 | - public function displayRegisterNowButton() |
|
| 598 | - { |
|
| 599 | - $btn_text = apply_filters( |
|
| 600 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 601 | - __('Register Now', 'event_espresso'), |
|
| 602 | - $this->event |
|
| 603 | - ); |
|
| 604 | - $external_url = $this->event->external_url(); |
|
| 605 | - $html = EEH_HTML::div( |
|
| 606 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 607 | - ); |
|
| 608 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 609 | - $html .= ' class="ticket-selector-submit-btn '; |
|
| 610 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 611 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 612 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 613 | - $html .= apply_filters( |
|
| 614 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 615 | - '', |
|
| 616 | - $this->event |
|
| 617 | - ); |
|
| 618 | - return $html; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /** |
|
| 623 | - * displayViewDetailsButton |
|
| 624 | - * |
|
| 625 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 626 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 627 | - * either because they are sold out, expired, or not yet on sale. |
|
| 628 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
| 629 | - * @return string |
|
| 630 | - * @throws EE_Error |
|
| 631 | - */ |
|
| 632 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 633 | - { |
|
| 634 | - if ( ! $this->event->get_permalink() ) { |
|
| 635 | - EE_Error::add_error( |
|
| 636 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 637 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 638 | - ); |
|
| 639 | - } |
|
| 640 | - $view_details_btn = '<form method="POST" action="'; |
|
| 641 | - $view_details_btn .= apply_filters( |
|
| 642 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 643 | - $this->event->get_permalink(), |
|
| 644 | - $this->event |
|
| 645 | - ); |
|
| 646 | - $view_details_btn .= '"'; |
|
| 647 | - // open link in new window ? |
|
| 648 | - $view_details_btn .= apply_filters( |
|
| 649 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 650 | - EED_Events_Archive::is_iframe() |
|
| 651 | - ) |
|
| 652 | - ? ' target="_blank"' |
|
| 653 | - : ''; |
|
| 654 | - $view_details_btn .='>'; |
|
| 655 | - $btn_text = apply_filters( |
|
| 656 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 657 | - esc_html__('View Details', 'event_espresso'), |
|
| 658 | - $this->event |
|
| 659 | - ); |
|
| 660 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 661 | - . $this->event->ID() |
|
| 662 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 663 | - . $btn_text |
|
| 664 | - . '" />'; |
|
| 665 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 666 | - if ($DWMTS) { |
|
| 667 | - $view_details_btn .= $this->formClose(); |
|
| 668 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 669 | - $view_details_btn .= '<br/>'; |
|
| 670 | - } else { |
|
| 671 | - $view_details_btn .= $this->clearTicketSelector(); |
|
| 672 | - $view_details_btn .= '<br/>'; |
|
| 673 | - $view_details_btn .= $this->formClose(); |
|
| 674 | - } |
|
| 675 | - return $view_details_btn; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function ticketSelectorEndDiv() |
|
| 684 | - { |
|
| 685 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * @return string |
|
| 692 | - */ |
|
| 693 | - public function clearTicketSelector() |
|
| 694 | - { |
|
| 695 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 696 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * @access public |
|
| 703 | - * @return string |
|
| 704 | - */ |
|
| 705 | - public function formClose() |
|
| 706 | - { |
|
| 707 | - return '</form>'; |
|
| 708 | - } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * ticketSalesClosed |
|
| 294 | + * notice displayed if event ticket sales are turned off |
|
| 295 | + * |
|
| 296 | + * @return string |
|
| 297 | + * @throws EE_Error |
|
| 298 | + */ |
|
| 299 | + protected function ticketSalesClosedMessage() |
|
| 300 | + { |
|
| 301 | + $sales_closed_msg = esc_html__( |
|
| 302 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 303 | + 'event_espresso' |
|
| 304 | + ); |
|
| 305 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 306 | + $sales_closed_msg .= sprintf( |
|
| 307 | + esc_html__( |
|
| 308 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 309 | + 'event_espresso' |
|
| 310 | + ), |
|
| 311 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 312 | + '</b><br />', |
|
| 313 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 314 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * getTickets |
|
| 324 | + * |
|
| 325 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 326 | + * @throws EE_Error |
|
| 327 | + */ |
|
| 328 | + protected function getTickets() |
|
| 329 | + { |
|
| 330 | + $ticket_query_args = array( |
|
| 331 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 332 | + 'order_by' => array( |
|
| 333 | + 'TKT_order' => 'ASC', |
|
| 334 | + 'TKT_required' => 'DESC', |
|
| 335 | + 'TKT_start_date' => 'ASC', |
|
| 336 | + 'TKT_end_date' => 'ASC', |
|
| 337 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 338 | + ), |
|
| 339 | + ); |
|
| 340 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
| 341 | + //use the correct applicable time query depending on what version of core is being run. |
|
| 342 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 343 | + ? time() |
|
| 344 | + : current_time('timestamp'); |
|
| 345 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 346 | + } |
|
| 347 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * loadTicketSelector |
|
| 354 | + * begins to assemble template arguments |
|
| 355 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
| 356 | + * |
|
| 357 | + * @param \EE_Ticket[] $tickets |
|
| 358 | + * @param array $template_args |
|
| 359 | + * @return string |
|
| 360 | + * @throws EE_Error |
|
| 361 | + */ |
|
| 362 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 363 | + { |
|
| 364 | + $template_args['event'] = $this->event; |
|
| 365 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
| 366 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 367 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 368 | + $template_args['date_format'] = $this->date_format; |
|
| 369 | + $template_args['time_format'] = $this->time_format; |
|
| 370 | + /** |
|
| 371 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 372 | + * |
|
| 373 | + * @since 4.9.13 |
|
| 374 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 375 | + * @param int $EVT_ID The Event ID |
|
| 376 | + */ |
|
| 377 | + $template_args['anchor_id'] = apply_filters( |
|
| 378 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 379 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 380 | + $this->event->ID() |
|
| 381 | + ); |
|
| 382 | + $template_args['tickets'] = $tickets; |
|
| 383 | + $template_args['ticket_count'] = count($tickets); |
|
| 384 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 385 | + return $ticket_selector instanceof TicketSelectorSimple |
|
| 386 | + ? $ticket_selector |
|
| 387 | + : new TicketSelectorStandard( |
|
| 388 | + $this->event, |
|
| 389 | + $tickets, |
|
| 390 | + $this->getMaxAttendees(), |
|
| 391 | + $template_args, |
|
| 392 | + $this->date_format, |
|
| 393 | + $this->time_format |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * simpleTicketSelector |
|
| 401 | + * there's one ticket, and max attendees is set to one, |
|
| 402 | + * so if the event is free, then this is a "simple" ticket selector |
|
| 403 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 404 | + * |
|
| 405 | + * @param \EE_Ticket[] $tickets |
|
| 406 | + * @param array $template_args |
|
| 407 | + * @return string |
|
| 408 | + * @throws EE_Error |
|
| 409 | + */ |
|
| 410 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
| 411 | + { |
|
| 412 | + // if there is only ONE ticket with a max qty of ONE |
|
| 413 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 414 | + return ''; |
|
| 415 | + } |
|
| 416 | + /** @var \EE_Ticket $ticket */ |
|
| 417 | + $ticket = reset($tickets); |
|
| 418 | + // if the ticket is free... then not much need for the ticket selector |
|
| 419 | + if ( |
|
| 420 | + apply_filters( |
|
| 421 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 422 | + $ticket->is_free(), |
|
| 423 | + $this->event->ID() |
|
| 424 | + ) |
|
| 425 | + ) { |
|
| 426 | + return new TicketSelectorSimple( |
|
| 427 | + $this->event, |
|
| 428 | + $ticket, |
|
| 429 | + $this->getMaxAttendees(), |
|
| 430 | + $template_args |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * externalEventRegistration |
|
| 440 | + * |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function externalEventRegistration() |
|
| 444 | + { |
|
| 445 | + // if not we still need to trigger the display of the submit button |
|
| 446 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 447 | + //display notice to admin that registration is external |
|
| 448 | + return is_admin() |
|
| 449 | + ? esc_html__( |
|
| 450 | + 'Registration is at an external URL for this event.', |
|
| 451 | + 'event_espresso' |
|
| 452 | + ) |
|
| 453 | + : ''; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * formOpen |
|
| 460 | + * |
|
| 461 | + * @param int $ID |
|
| 462 | + * @param string $external_url |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
| 466 | + { |
|
| 467 | + // if redirecting, we don't need any anything else |
|
| 468 | + if ( $external_url ) { |
|
| 469 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 470 | + // open link in new window ? |
|
| 471 | + $html .= apply_filters( |
|
| 472 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 473 | + EED_Events_Archive::is_iframe() |
|
| 474 | + ) |
|
| 475 | + ? ' target="_blank"' |
|
| 476 | + : ''; |
|
| 477 | + $html .= '>'; |
|
| 478 | + $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 481 | + } |
|
| 482 | + return $html; |
|
| 483 | + } |
|
| 484 | + // if there is no submit button, then don't start building a form |
|
| 485 | + // because the "View Details" button will build its own form |
|
| 486 | + if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | + if ( ! $checkout_url ) { |
|
| 491 | + EE_Error::add_error( |
|
| 492 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 493 | + __FILE__, |
|
| 494 | + __FUNCTION__, |
|
| 495 | + __LINE__ |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + // set no cache headers and constants |
|
| 499 | + EE_System::do_not_cache(); |
|
| 500 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 501 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 502 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 503 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 504 | + return $html; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * displaySubmitButton |
|
| 511 | + * |
|
| 512 | + * @param string $external_url |
|
| 513 | + * @return string |
|
| 514 | + * @throws EE_Error |
|
| 515 | + */ |
|
| 516 | + public function displaySubmitButton($external_url = '') |
|
| 517 | + { |
|
| 518 | + $html = ''; |
|
| 519 | + if ( ! is_admin()) { |
|
| 520 | + // standard TS displayed with submit button, ie: "Register Now" |
|
| 521 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 522 | + $html .= $this->displayRegisterNowButton(); |
|
| 523 | + $html .= empty($external_url) |
|
| 524 | + ? $this->ticketSelectorEndDiv() |
|
| 525 | + : $this->clearTicketSelector(); |
|
| 526 | + $html .= '<br/>' . $this->formClose(); |
|
| 527 | + } else if ($this->getMaxAttendees() === 1) { |
|
| 528 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 529 | + if ($this->event->is_sold_out()) { |
|
| 530 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 531 | + $html .= apply_filters( |
|
| 532 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 533 | + sprintf( |
|
| 534 | + __( |
|
| 535 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 536 | + 'event_espresso' |
|
| 537 | + ), |
|
| 538 | + '<p class="no-ticket-selector-msg clear-float">', |
|
| 539 | + $this->event->name(), |
|
| 540 | + '</p>', |
|
| 541 | + '<br />' |
|
| 542 | + ), |
|
| 543 | + $this->event |
|
| 544 | + ); |
|
| 545 | + if ( |
|
| 546 | + apply_filters( |
|
| 547 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 548 | + false, |
|
| 549 | + $this->event |
|
| 550 | + ) |
|
| 551 | + ) { |
|
| 552 | + $html .= $this->displayRegisterNowButton(); |
|
| 553 | + } |
|
| 554 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 555 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | + } else if ( |
|
| 557 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 558 | + && ! is_single() |
|
| 559 | + ) { |
|
| 560 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 561 | + // but no tickets are available, so display event's "View Details" button. |
|
| 562 | + // it is being viewed via somewhere other than a single post |
|
| 563 | + $html .= $this->displayViewDetailsButton(true); |
|
| 564 | + } else { |
|
| 565 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 566 | + } |
|
| 567 | + } else if (is_archive()) { |
|
| 568 | + // event list, no tickets available so display event's "View Details" button |
|
| 569 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 570 | + $html .= $this->displayViewDetailsButton(); |
|
| 571 | + } else { |
|
| 572 | + if ( |
|
| 573 | + apply_filters( |
|
| 574 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 575 | + false, |
|
| 576 | + $this->event |
|
| 577 | + ) |
|
| 578 | + ) { |
|
| 579 | + $html .= $this->displayRegisterNowButton(); |
|
| 580 | + } |
|
| 581 | + // no submit or view details button, and no additional content |
|
| 582 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 583 | + } |
|
| 584 | + if ( ! $this->iframe && ! is_archive()) { |
|
| 585 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + return $html; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * @return string |
|
| 595 | + * @throws EE_Error |
|
| 596 | + */ |
|
| 597 | + public function displayRegisterNowButton() |
|
| 598 | + { |
|
| 599 | + $btn_text = apply_filters( |
|
| 600 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 601 | + __('Register Now', 'event_espresso'), |
|
| 602 | + $this->event |
|
| 603 | + ); |
|
| 604 | + $external_url = $this->event->external_url(); |
|
| 605 | + $html = EEH_HTML::div( |
|
| 606 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 607 | + ); |
|
| 608 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 609 | + $html .= ' class="ticket-selector-submit-btn '; |
|
| 610 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 611 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 612 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 613 | + $html .= apply_filters( |
|
| 614 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 615 | + '', |
|
| 616 | + $this->event |
|
| 617 | + ); |
|
| 618 | + return $html; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * displayViewDetailsButton |
|
| 624 | + * |
|
| 625 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 626 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 627 | + * either because they are sold out, expired, or not yet on sale. |
|
| 628 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
| 629 | + * @return string |
|
| 630 | + * @throws EE_Error |
|
| 631 | + */ |
|
| 632 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
| 633 | + { |
|
| 634 | + if ( ! $this->event->get_permalink() ) { |
|
| 635 | + EE_Error::add_error( |
|
| 636 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 637 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 638 | + ); |
|
| 639 | + } |
|
| 640 | + $view_details_btn = '<form method="POST" action="'; |
|
| 641 | + $view_details_btn .= apply_filters( |
|
| 642 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 643 | + $this->event->get_permalink(), |
|
| 644 | + $this->event |
|
| 645 | + ); |
|
| 646 | + $view_details_btn .= '"'; |
|
| 647 | + // open link in new window ? |
|
| 648 | + $view_details_btn .= apply_filters( |
|
| 649 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 650 | + EED_Events_Archive::is_iframe() |
|
| 651 | + ) |
|
| 652 | + ? ' target="_blank"' |
|
| 653 | + : ''; |
|
| 654 | + $view_details_btn .='>'; |
|
| 655 | + $btn_text = apply_filters( |
|
| 656 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 657 | + esc_html__('View Details', 'event_espresso'), |
|
| 658 | + $this->event |
|
| 659 | + ); |
|
| 660 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 661 | + . $this->event->ID() |
|
| 662 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 663 | + . $btn_text |
|
| 664 | + . '" />'; |
|
| 665 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 666 | + if ($DWMTS) { |
|
| 667 | + $view_details_btn .= $this->formClose(); |
|
| 668 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 669 | + $view_details_btn .= '<br/>'; |
|
| 670 | + } else { |
|
| 671 | + $view_details_btn .= $this->clearTicketSelector(); |
|
| 672 | + $view_details_btn .= '<br/>'; |
|
| 673 | + $view_details_btn .= $this->formClose(); |
|
| 674 | + } |
|
| 675 | + return $view_details_btn; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function ticketSelectorEndDiv() |
|
| 684 | + { |
|
| 685 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * @return string |
|
| 692 | + */ |
|
| 693 | + public function clearTicketSelector() |
|
| 694 | + { |
|
| 695 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 696 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * @access public |
|
| 703 | + * @return string |
|
| 704 | + */ |
|
| 705 | + public function formClose() |
|
| 706 | + { |
|
| 707 | + return '</form>'; |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | 710 | |
| 711 | 711 | |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | use EEM_Ticket; |
| 16 | 16 | use WP_Post; |
| 17 | 17 | |
| 18 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 19 | - exit( 'No direct script access allowed' ); |
|
| 18 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 19 | + exit('No direct script access allowed'); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * @param boolean $iframe |
| 89 | 89 | */ |
| 90 | - public function setIframe( $iframe = true ) |
|
| 90 | + public function setIframe($iframe = true) |
|
| 91 | 91 | { |
| 92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 92 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -100,28 +100,28 @@ discard block |
||
| 100 | 100 | * @return bool |
| 101 | 101 | * @throws EE_Error |
| 102 | 102 | */ |
| 103 | - protected function setEvent( $event = null ) |
|
| 103 | + protected function setEvent($event = null) |
|
| 104 | 104 | { |
| 105 | - if ( $event === null ) { |
|
| 105 | + if ($event === null) { |
|
| 106 | 106 | global $post; |
| 107 | 107 | $event = $post; |
| 108 | 108 | } |
| 109 | - if ( $event instanceof EE_Event ) { |
|
| 109 | + if ($event instanceof EE_Event) { |
|
| 110 | 110 | $this->event = $event; |
| 111 | - } else if ( $event instanceof WP_Post ) { |
|
| 112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 111 | + } else if ($event instanceof WP_Post) { |
|
| 112 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
| 113 | 113 | $this->event = $event->EE_Event; |
| 114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 114 | + } else if ($event->post_type === 'espresso_events') { |
|
| 115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
| 116 | 116 | $this->event = $event->EE_Event; |
| 117 | 117 | } |
| 118 | 118 | } else { |
| 119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | - $dev_msg = $user_msg . __( |
|
| 119 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
| 120 | + $dev_msg = $user_msg.__( |
|
| 121 | 121 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
| 122 | 122 | 'event_espresso' |
| 123 | 123 | ); |
| 124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 124 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | return true; |
@@ -162,17 +162,17 @@ discard block |
||
| 162 | 162 | * @return string |
| 163 | 163 | * @throws EE_Error |
| 164 | 164 | */ |
| 165 | - public function display( $event = null, $view_details = false ) |
|
| 165 | + public function display($event = null, $view_details = false) |
|
| 166 | 166 | { |
| 167 | 167 | // reset filter for displaying submit button |
| 168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 168 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 169 | 169 | // poke and prod incoming event till it tells us what it is |
| 170 | - if ( ! $this->setEvent( $event ) ) { |
|
| 170 | + if ( ! $this->setEvent($event)) { |
|
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | 173 | // begin gathering template arguments by getting event status |
| 174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 174 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
| 175 | + if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) { |
|
| 176 | 176 | return ! is_single() ? $this->displayViewDetailsButton() : ''; |
| 177 | 177 | } |
| 178 | 178 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | // is the event expired ? |
| 184 | 184 | $template_args['event_is_expired'] = $this->event->is_expired(); |
| 185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 185 | + if ($template_args['event_is_expired']) { |
|
| 186 | 186 | return $this->expiredEventMessage(); |
| 187 | 187 | } |
| 188 | 188 | // get all tickets for this event ordered by the datetime |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | if (count($tickets) < 1) { |
| 191 | 191 | return $this->noTicketAvailableMessage(); |
| 192 | 192 | } |
| 193 | - if (EED_Events_Archive::is_iframe()){ |
|
| 193 | + if (EED_Events_Archive::is_iframe()) { |
|
| 194 | 194 | $this->setIframe(); |
| 195 | 195 | } |
| 196 | 196 | // redirecting to another site for registration ?? |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | // if redirecting to another site for registration, then we don't load the TS |
| 199 | 199 | $ticket_selector = $external_url |
| 200 | 200 | ? $this->externalEventRegistration() |
| 201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
| 201 | + : $this->loadTicketSelector($tickets, $template_args); |
|
| 202 | 202 | // now set up the form (but not for the admin) |
| 203 | 203 | $ticket_selector = ! is_admin() |
| 204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 204 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
| 205 | 205 | : $ticket_selector; |
| 206 | 206 | // submit button and form close tag |
| 207 | 207 | $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | protected function expiredEventMessage() |
| 253 | 253 | { |
| 254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
| 255 | 255 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
| 256 | 256 | 'event_espresso' |
| 257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 257 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | protected function noTicketAvailableMessage() |
| 270 | 270 | { |
| 271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 271 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
| 272 | 272 | if (current_user_can('edit_post', $this->event->ID())) { |
| 273 | 273 | $no_ticket_available_msg .= sprintf( |
| 274 | 274 | esc_html__( |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | return ' |
| 285 | 285 | <div class="ee-event-expired-notice"> |
| 286 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
| 286 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
| 287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
| 315 | 315 | ); |
| 316 | 316 | } |
| 317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 317 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -376,12 +376,12 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | $template_args['anchor_id'] = apply_filters( |
| 378 | 378 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
| 379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 379 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
| 380 | 380 | $this->event->ID() |
| 381 | 381 | ); |
| 382 | 382 | $template_args['tickets'] = $tickets; |
| 383 | 383 | $template_args['ticket_count'] = count($tickets); |
| 384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 384 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
| 385 | 385 | return $ticket_selector instanceof TicketSelectorSimple |
| 386 | 386 | ? $ticket_selector |
| 387 | 387 | : new TicketSelectorStandard( |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * @param string $external_url |
| 463 | 463 | * @return string |
| 464 | 464 | */ |
| 465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 465 | + public function formOpen($ID = 0, $external_url = '') |
|
| 466 | 466 | { |
| 467 | 467 | // if redirecting, we don't need any anything else |
| 468 | - if ( $external_url ) { |
|
| 469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 468 | + if ($external_url) { |
|
| 469 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
| 470 | 470 | // open link in new window ? |
| 471 | 471 | $html .= apply_filters( |
| 472 | 472 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -475,21 +475,21 @@ discard block |
||
| 475 | 475 | ? ' target="_blank"' |
| 476 | 476 | : ''; |
| 477 | 477 | $html .= '>'; |
| 478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 478 | + $query_args = EEH_URL::get_query_string($external_url); |
|
| 479 | + foreach ((array) $query_args as $query_arg => $value) { |
|
| 480 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
| 481 | 481 | } |
| 482 | 482 | return $html; |
| 483 | 483 | } |
| 484 | 484 | // if there is no submit button, then don't start building a form |
| 485 | 485 | // because the "View Details" button will build its own form |
| 486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 486 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 487 | 487 | return ''; |
| 488 | 488 | } |
| 489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | - if ( ! $checkout_url ) { |
|
| 489 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
| 490 | + if ( ! $checkout_url) { |
|
| 491 | 491 | EE_Error::add_error( |
| 492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 492 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 493 | 493 | __FILE__, |
| 494 | 494 | __FUNCTION__, |
| 495 | 495 | __LINE__ |
@@ -498,9 +498,9 @@ discard block |
||
| 498 | 498 | // set no cache headers and constants |
| 499 | 499 | EE_System::do_not_cache(); |
| 500 | 500 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
| 501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 501 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
| 502 | 502 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
| 503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 503 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
| 504 | 504 | return $html; |
| 505 | 505 | } |
| 506 | 506 | |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | $html .= empty($external_url) |
| 524 | 524 | ? $this->ticketSelectorEndDiv() |
| 525 | 525 | : $this->clearTicketSelector(); |
| 526 | - $html .= '<br/>' . $this->formClose(); |
|
| 526 | + $html .= '<br/>'.$this->formClose(); |
|
| 527 | 527 | } else if ($this->getMaxAttendees() === 1) { |
| 528 | 528 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
| 529 | 529 | if ($this->event->is_sold_out()) { |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | $html .= $this->displayRegisterNowButton(); |
| 553 | 553 | } |
| 554 | 554 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
| 555 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 555 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | 556 | } else if ( |
| 557 | 557 | apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
| 558 | 558 | && ! is_single() |
@@ -603,13 +603,13 @@ discard block |
||
| 603 | 603 | ); |
| 604 | 604 | $external_url = $this->event->external_url(); |
| 605 | 605 | $html = EEH_HTML::div( |
| 606 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 606 | + '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 607 | 607 | ); |
| 608 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 608 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
| 609 | 609 | $html .= ' class="ticket-selector-submit-btn '; |
| 610 | 610 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
| 611 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 612 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 611 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
| 612 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 613 | 613 | $html .= apply_filters( |
| 614 | 614 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
| 615 | 615 | '', |
@@ -629,11 +629,11 @@ discard block |
||
| 629 | 629 | * @return string |
| 630 | 630 | * @throws EE_Error |
| 631 | 631 | */ |
| 632 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 632 | + public function displayViewDetailsButton($DWMTS = false) |
|
| 633 | 633 | { |
| 634 | - if ( ! $this->event->get_permalink() ) { |
|
| 634 | + if ( ! $this->event->get_permalink()) { |
|
| 635 | 635 | EE_Error::add_error( |
| 636 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 636 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 637 | 637 | __FILE__, __FUNCTION__, __LINE__ |
| 638 | 638 | ); |
| 639 | 639 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | ) |
| 652 | 652 | ? ' target="_blank"' |
| 653 | 653 | : ''; |
| 654 | - $view_details_btn .='>'; |
|
| 654 | + $view_details_btn .= '>'; |
|
| 655 | 655 | $btn_text = apply_filters( |
| 656 | 656 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
| 657 | 657 | esc_html__('View Details', 'event_espresso'), |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
| 663 | 663 | . $btn_text |
| 664 | 664 | . '" />'; |
| 665 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 665 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
| 666 | 666 | if ($DWMTS) { |
| 667 | 667 | $view_details_btn .= $this->formClose(); |
| 668 | 668 | $view_details_btn .= $this->ticketSelectorEndDiv(); |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | */ |
| 683 | 683 | public function ticketSelectorEndDiv() |
| 684 | 684 | { |
| 685 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 685 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,570 +19,570 @@ discard block |
||
| 19 | 19 | class ProcessTicketSelector |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * array of datetimes and the spaces available for them |
|
| 24 | - * |
|
| 25 | - * @access private |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private static $_available_spaces = array(); |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * cancelTicketSelections |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function cancelTicketSelections() |
|
| 38 | - { |
|
| 39 | - // check nonce |
|
| 40 | - if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 43 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 44 | - if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
| 45 | - wp_safe_redirect( |
|
| 46 | - \EEH_Event_View::event_link_url( |
|
| 47 | - \EE_Registry::instance()->REQ->get('event_id') |
|
| 48 | - ) |
|
| 49 | - ); |
|
| 50 | - } else { |
|
| 51 | - wp_safe_redirect( |
|
| 52 | - site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
| 53 | - ); |
|
| 54 | - } |
|
| 55 | - exit(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * processTicketSelectorNonce |
|
| 62 | - * |
|
| 63 | - * @param string $nonce_name |
|
| 64 | - * @param string $id |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 68 | - { |
|
| 69 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 70 | - if ( |
|
| 71 | - ! is_admin() |
|
| 72 | - && ( |
|
| 73 | - ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
| 74 | - || ! wp_verify_nonce( |
|
| 75 | - \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
| 76 | - $nonce_name |
|
| 77 | - ) |
|
| 78 | - ) |
|
| 79 | - ) { |
|
| 80 | - \EE_Error::add_error( |
|
| 81 | - sprintf( |
|
| 82 | - __( |
|
| 83 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 84 | - 'event_espresso' |
|
| 85 | - ), |
|
| 86 | - '<br/>' |
|
| 87 | - ), |
|
| 88 | - __FILE__, |
|
| 89 | - __FUNCTION__, |
|
| 90 | - __LINE__ |
|
| 91 | - ); |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * process_ticket_selections |
|
| 101 | - * |
|
| 102 | - * @return array|bool |
|
| 103 | - * @throws \EE_Error |
|
| 104 | - */ |
|
| 105 | - public function processTicketSelections() |
|
| 106 | - { |
|
| 107 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 108 | - // do we have an event id? |
|
| 109 | - if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 110 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 111 | - \EE_Error::add_error( |
|
| 112 | - sprintf( |
|
| 113 | - __( |
|
| 114 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 115 | - 'event_espresso' |
|
| 116 | - ), |
|
| 117 | - '<br/>' |
|
| 118 | - ), |
|
| 119 | - __FILE__, |
|
| 120 | - __FUNCTION__, |
|
| 121 | - __LINE__ |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - //if event id is valid |
|
| 125 | - $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
| 126 | - // d( \EE_Registry::instance()->REQ ); |
|
| 127 | - self::$_available_spaces = array( |
|
| 128 | - 'tickets' => array(), |
|
| 129 | - 'datetimes' => array(), |
|
| 130 | - ); |
|
| 131 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 132 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 133 | - \EE_Registry::instance()->load_core('Session'); |
|
| 134 | - // unless otherwise requested, clear the session |
|
| 135 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 136 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 137 | - } |
|
| 138 | - //d( \EE_Registry::instance()->SSN ); |
|
| 139 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 140 | - // validate/sanitize data |
|
| 141 | - $valid = $this->validatePostData($id); |
|
| 142 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 143 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 144 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 145 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 146 | - //check total tickets ordered vs max number of attendees that can register |
|
| 147 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 148 | - // ordering too many tickets !!! |
|
| 149 | - $total_tickets_string = _n( |
|
| 150 | - 'You have attempted to purchase %s ticket.', |
|
| 151 | - 'You have attempted to purchase %s tickets.', |
|
| 152 | - $valid['total_tickets'], |
|
| 153 | - 'event_espresso' |
|
| 154 | - ); |
|
| 155 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 156 | - // dev only message |
|
| 157 | - $max_atndz_string = _n( |
|
| 158 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 159 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 160 | - $valid['max_atndz'], |
|
| 161 | - 'event_espresso' |
|
| 162 | - ); |
|
| 163 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 164 | - \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - } else { |
|
| 166 | - // all data appears to be valid |
|
| 167 | - $tckts_slctd = false; |
|
| 168 | - $tickets_added = 0; |
|
| 169 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
| 170 | - if ($valid['total_tickets'] > 0) { |
|
| 171 | - // load cart |
|
| 172 | - \EE_Registry::instance()->load_core('Cart'); |
|
| 173 | - // cycle thru the number of data rows sent from the event listing |
|
| 174 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 175 | - // does this row actually contain a ticket quantity? |
|
| 176 | - if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 177 | - // YES we have a ticket quantity |
|
| 178 | - $tckts_slctd = true; |
|
| 179 | - // d( $valid['ticket_obj'][$x] ); |
|
| 180 | - if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
| 181 | - // then add ticket to cart |
|
| 182 | - $tickets_added += $this->addTicketToCart( |
|
| 183 | - $valid['ticket_obj'][$x], |
|
| 184 | - $valid['qty'][$x] |
|
| 185 | - ); |
|
| 186 | - if (\EE_Error::has_error()) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - // nothing added to cart retrieved |
|
| 191 | - \EE_Error::add_error( |
|
| 192 | - sprintf( |
|
| 193 | - __( |
|
| 194 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ), |
|
| 197 | - '<br/>' |
|
| 198 | - ), |
|
| 199 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - do_action( |
|
| 206 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 207 | - \EE_Registry::instance()->CART, |
|
| 208 | - $this |
|
| 209 | - ); |
|
| 210 | - //d( \EE_Registry::instance()->CART ); |
|
| 211 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 212 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
| 213 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 214 | - do_action( |
|
| 215 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 216 | - \EE_Registry::instance()->CART, |
|
| 217 | - $this |
|
| 218 | - ); |
|
| 219 | - \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 220 | - \EE_Registry::instance()->CART->save_cart(false); |
|
| 221 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 222 | - // just return TRUE for registrations being made from admin |
|
| 223 | - if (is_admin()) { |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 226 | - \EE_Error::get_notices(false, true); |
|
| 227 | - wp_safe_redirect( |
|
| 228 | - apply_filters( |
|
| 229 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 230 | - \EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - exit(); |
|
| 234 | - } else { |
|
| 235 | - if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
| 236 | - // nothing added to cart |
|
| 237 | - \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
| 238 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } else { |
|
| 242 | - // no ticket quantities were selected |
|
| 243 | - \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
| 244 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 248 | - // at this point, just return if registration is being made from admin |
|
| 249 | - if (is_admin()) { |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - if ($valid['return_url']) { |
|
| 253 | - \EE_Error::get_notices(false, true); |
|
| 254 | - wp_safe_redirect($valid['return_url']); |
|
| 255 | - exit(); |
|
| 256 | - } elseif (isset($event_to_add['id'])) { |
|
| 257 | - \EE_Error::get_notices(false, true); |
|
| 258 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
| 259 | - exit(); |
|
| 260 | - } else { |
|
| 261 | - echo \EE_Error::get_notices(); |
|
| 262 | - } |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * validate_post_data |
|
| 270 | - * |
|
| 271 | - * @param int $id |
|
| 272 | - * @return array|FALSE |
|
| 273 | - */ |
|
| 274 | - private function validatePostData($id = 0) |
|
| 275 | - { |
|
| 276 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 277 | - if ( ! $id) { |
|
| 278 | - \EE_Error::add_error( |
|
| 279 | - __('The event id provided was not valid.', 'event_espresso'), |
|
| 280 | - __FILE__, |
|
| 281 | - __FUNCTION__, |
|
| 282 | - __LINE__ |
|
| 283 | - ); |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - // start with an empty array() |
|
| 287 | - $valid_data = array(); |
|
| 288 | - // grab valid id |
|
| 289 | - $valid_data['id'] = $id; |
|
| 290 | - // array of other form names |
|
| 291 | - $inputs_to_clean = array( |
|
| 292 | - 'event_id' => 'tkt-slctr-event-id', |
|
| 293 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 294 | - 'rows' => 'tkt-slctr-rows-', |
|
| 295 | - 'qty' => 'tkt-slctr-qty-', |
|
| 296 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 297 | - 'return_url' => 'tkt-slctr-return-url-', |
|
| 298 | - ); |
|
| 299 | - // let's track the total number of tickets ordered.' |
|
| 300 | - $valid_data['total_tickets'] = 0; |
|
| 301 | - // cycle through $inputs_to_clean array |
|
| 302 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 303 | - // check for POST data |
|
| 304 | - if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
| 305 | - // grab value |
|
| 306 | - $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
| 307 | - switch ($what) { |
|
| 308 | - // integers |
|
| 309 | - case 'event_id': |
|
| 310 | - $valid_data[$what] = absint($input_value); |
|
| 311 | - // get event via the event id we put in the form |
|
| 312 | - $valid_data['event'] = \EE_Registry::instance() |
|
| 313 | - ->load_model('Event') |
|
| 314 | - ->get_one_by_ID($valid_data['event_id']); |
|
| 315 | - break; |
|
| 316 | - case 'rows': |
|
| 317 | - case 'max_atndz': |
|
| 318 | - $valid_data[$what] = absint($input_value); |
|
| 319 | - break; |
|
| 320 | - // arrays of integers |
|
| 321 | - case 'qty': |
|
| 322 | - /** @var array $row_qty */ |
|
| 323 | - $row_qty = $input_value; |
|
| 324 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 325 | - if ( ! is_array($row_qty)) { |
|
| 326 | - // get number of rows |
|
| 327 | - $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
| 328 | - ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
| 329 | - : 1; |
|
| 330 | - // explode ints by the dash |
|
| 331 | - $row_qty = explode('-', $row_qty); |
|
| 332 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 333 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 334 | - $row_qty = array($row => $qty); |
|
| 335 | - for ($x = 1; $x <= $rows; $x++) { |
|
| 336 | - if ( ! isset($row_qty[$x])) { |
|
| 337 | - $row_qty[$x] = 0; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - ksort($row_qty); |
|
| 342 | - // cycle thru values |
|
| 343 | - foreach ($row_qty as $qty) { |
|
| 344 | - $qty = absint($qty); |
|
| 345 | - // sanitize as integers |
|
| 346 | - $valid_data[$what][] = $qty; |
|
| 347 | - $valid_data['total_tickets'] += $qty; |
|
| 348 | - } |
|
| 349 | - break; |
|
| 350 | - // array of integers |
|
| 351 | - case 'ticket_id': |
|
| 352 | - $value_array = array(); |
|
| 353 | - // cycle thru values |
|
| 354 | - foreach ((array)$input_value as $key => $value) { |
|
| 355 | - // allow only numbers, letters, spaces, commas and dashes |
|
| 356 | - $value_array[$key] = wp_strip_all_tags($value); |
|
| 357 | - // get ticket via the ticket id we put in the form |
|
| 358 | - $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
| 359 | - $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
| 360 | - } |
|
| 361 | - $valid_data[$what] = $value_array; |
|
| 362 | - break; |
|
| 363 | - case 'return_url' : |
|
| 364 | - // grab and sanitize return-url |
|
| 365 | - $input_value = esc_url_raw($input_value); |
|
| 366 | - // was the request coming from an iframe ? if so, then: |
|
| 367 | - if (strpos($input_value, 'event_list=iframe')) { |
|
| 368 | - // get anchor fragment |
|
| 369 | - $input_value = explode('#', $input_value); |
|
| 370 | - $input_value = end($input_value); |
|
| 371 | - // use event list url instead, but append anchor |
|
| 372 | - $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 373 | - } |
|
| 374 | - $valid_data[$what] = $input_value; |
|
| 375 | - break; |
|
| 376 | - } // end switch $what |
|
| 377 | - } |
|
| 378 | - } // end foreach $inputs_to_clean |
|
| 379 | - return $valid_data; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * adds a ticket to the cart |
|
| 386 | - * |
|
| 387 | - * @param \EE_Ticket $ticket |
|
| 388 | - * @param int $qty |
|
| 389 | - * @return TRUE on success, FALSE on fail |
|
| 390 | - * @throws \EE_Error |
|
| 391 | - */ |
|
| 392 | - private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
| 393 | - { |
|
| 394 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 395 | - // get the number of spaces left for this datetime ticket |
|
| 396 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
| 397 | - // compare available spaces against the number of tickets being purchased |
|
| 398 | - if ($available_spaces >= $qty) { |
|
| 399 | - // allow addons to prevent a ticket from being added to cart |
|
| 400 | - if ( |
|
| 401 | - ! apply_filters( |
|
| 402 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 403 | - true, |
|
| 404 | - $ticket, |
|
| 405 | - $qty, |
|
| 406 | - $available_spaces |
|
| 407 | - ) |
|
| 408 | - ) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 412 | - // add event to cart |
|
| 413 | - if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
| 414 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 415 | - return true; |
|
| 416 | - } |
|
| 417 | - return false; |
|
| 418 | - } |
|
| 419 | - // tickets can not be purchased but let's find the exact number left |
|
| 420 | - // for the last ticket selected PRIOR to subtracting tickets |
|
| 421 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
| 422 | - // greedy greedy greedy eh? |
|
| 423 | - if ($available_spaces > 0) { |
|
| 424 | - if ( |
|
| 425 | - apply_filters( |
|
| 426 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
| 427 | - true, |
|
| 428 | - $ticket, |
|
| 429 | - $qty, |
|
| 430 | - $available_spaces |
|
| 431 | - ) |
|
| 432 | - ) { |
|
| 433 | - $this->displayAvailabilityError($available_spaces); |
|
| 434 | - } |
|
| 435 | - } else { |
|
| 436 | - \EE_Error::add_error( |
|
| 437 | - __( |
|
| 438 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 439 | - 'event_espresso' |
|
| 440 | - ), |
|
| 441 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - return false; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param int $available_spaces |
|
| 451 | - * @throws \EE_Error |
|
| 452 | - */ |
|
| 453 | - private function displayAvailabilityError($available_spaces = 1) |
|
| 454 | - { |
|
| 455 | - // add error messaging - we're using the _n function that will generate |
|
| 456 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
| 457 | - if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
| 458 | - $msg = sprintf( |
|
| 459 | - _n( |
|
| 460 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 461 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 462 | - $available_spaces, |
|
| 463 | - 'event_espresso' |
|
| 464 | - ), |
|
| 465 | - $available_spaces, |
|
| 466 | - '<br />' |
|
| 467 | - ); |
|
| 468 | - } else { |
|
| 469 | - $msg = sprintf( |
|
| 470 | - _n( |
|
| 471 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 472 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 473 | - $available_spaces, |
|
| 474 | - 'event_espresso' |
|
| 475 | - ), |
|
| 476 | - $available_spaces, |
|
| 477 | - '<br />' |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * ticketDatetimeAvailability |
|
| 487 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 488 | - * and tracks the spaces remaining for each of those datetimes |
|
| 489 | - * |
|
| 490 | - * @param \EE_Ticket $ticket - selected ticket |
|
| 491 | - * @param bool $get_original_ticket_spaces |
|
| 492 | - * @return int |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 495 | - private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
| 496 | - { |
|
| 497 | - // if the $_available_spaces array has not been set up yet... |
|
| 498 | - if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 499 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
| 500 | - } |
|
| 501 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 502 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 503 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 504 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 505 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 506 | - if ($get_original_ticket_spaces) { |
|
| 507 | - // then grab the available spaces from the "tickets" array |
|
| 508 | - // and compare with the above to get the lowest number |
|
| 509 | - $available_spaces = min( |
|
| 510 | - $available_spaces, |
|
| 511 | - self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
| 512 | - ); |
|
| 513 | - } else { |
|
| 514 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
| 515 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - return $available_spaces; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * @param \EE_Ticket $ticket |
|
| 526 | - * @return void |
|
| 527 | - * @throws \EE_Error |
|
| 528 | - */ |
|
| 529 | - private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
| 530 | - { |
|
| 531 | - // first, get all of the datetimes that are available to this ticket |
|
| 532 | - $datetimes = $ticket->get_many_related( |
|
| 533 | - 'Datetime', |
|
| 534 | - array( |
|
| 535 | - array( |
|
| 536 | - 'DTT_EVT_end' => array( |
|
| 537 | - '>=', |
|
| 538 | - \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 539 | - ), |
|
| 540 | - ), |
|
| 541 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 542 | - ) |
|
| 543 | - ); |
|
| 544 | - if ( ! empty($datetimes)) { |
|
| 545 | - // now loop thru all of the datetimes |
|
| 546 | - foreach ($datetimes as $datetime) { |
|
| 547 | - if ($datetime instanceof \EE_Datetime) { |
|
| 548 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 549 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
| 550 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 551 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 552 | - self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
| 553 | - $ticket->qty() - $ticket->sold(), |
|
| 554 | - $spaces_remaining |
|
| 555 | - ); |
|
| 556 | - // if the remaining spaces for this datetime is already set, |
|
| 557 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 558 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 559 | - self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
| 560 | - self::$_available_spaces['datetimes'][$datetime->ID()] |
|
| 561 | - ) |
|
| 562 | - ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
| 563 | - : $spaces_remaining; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param \EE_Ticket $ticket |
|
| 573 | - * @param int $qty |
|
| 574 | - * @return void |
|
| 575 | - */ |
|
| 576 | - private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
| 577 | - { |
|
| 578 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 579 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 580 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 581 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 582 | - self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 22 | + /** |
|
| 23 | + * array of datetimes and the spaces available for them |
|
| 24 | + * |
|
| 25 | + * @access private |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private static $_available_spaces = array(); |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * cancelTicketSelections |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function cancelTicketSelections() |
|
| 38 | + { |
|
| 39 | + // check nonce |
|
| 40 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 44 | + if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
| 45 | + wp_safe_redirect( |
|
| 46 | + \EEH_Event_View::event_link_url( |
|
| 47 | + \EE_Registry::instance()->REQ->get('event_id') |
|
| 48 | + ) |
|
| 49 | + ); |
|
| 50 | + } else { |
|
| 51 | + wp_safe_redirect( |
|
| 52 | + site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | + exit(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * processTicketSelectorNonce |
|
| 62 | + * |
|
| 63 | + * @param string $nonce_name |
|
| 64 | + * @param string $id |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 68 | + { |
|
| 69 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 70 | + if ( |
|
| 71 | + ! is_admin() |
|
| 72 | + && ( |
|
| 73 | + ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
| 74 | + || ! wp_verify_nonce( |
|
| 75 | + \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
| 76 | + $nonce_name |
|
| 77 | + ) |
|
| 78 | + ) |
|
| 79 | + ) { |
|
| 80 | + \EE_Error::add_error( |
|
| 81 | + sprintf( |
|
| 82 | + __( |
|
| 83 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 84 | + 'event_espresso' |
|
| 85 | + ), |
|
| 86 | + '<br/>' |
|
| 87 | + ), |
|
| 88 | + __FILE__, |
|
| 89 | + __FUNCTION__, |
|
| 90 | + __LINE__ |
|
| 91 | + ); |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * process_ticket_selections |
|
| 101 | + * |
|
| 102 | + * @return array|bool |
|
| 103 | + * @throws \EE_Error |
|
| 104 | + */ |
|
| 105 | + public function processTicketSelections() |
|
| 106 | + { |
|
| 107 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 108 | + // do we have an event id? |
|
| 109 | + if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 110 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 111 | + \EE_Error::add_error( |
|
| 112 | + sprintf( |
|
| 113 | + __( |
|
| 114 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 115 | + 'event_espresso' |
|
| 116 | + ), |
|
| 117 | + '<br/>' |
|
| 118 | + ), |
|
| 119 | + __FILE__, |
|
| 120 | + __FUNCTION__, |
|
| 121 | + __LINE__ |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + //if event id is valid |
|
| 125 | + $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
| 126 | + // d( \EE_Registry::instance()->REQ ); |
|
| 127 | + self::$_available_spaces = array( |
|
| 128 | + 'tickets' => array(), |
|
| 129 | + 'datetimes' => array(), |
|
| 130 | + ); |
|
| 131 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 132 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 133 | + \EE_Registry::instance()->load_core('Session'); |
|
| 134 | + // unless otherwise requested, clear the session |
|
| 135 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 136 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 137 | + } |
|
| 138 | + //d( \EE_Registry::instance()->SSN ); |
|
| 139 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 140 | + // validate/sanitize data |
|
| 141 | + $valid = $this->validatePostData($id); |
|
| 142 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 143 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 144 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 145 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 146 | + //check total tickets ordered vs max number of attendees that can register |
|
| 147 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 148 | + // ordering too many tickets !!! |
|
| 149 | + $total_tickets_string = _n( |
|
| 150 | + 'You have attempted to purchase %s ticket.', |
|
| 151 | + 'You have attempted to purchase %s tickets.', |
|
| 152 | + $valid['total_tickets'], |
|
| 153 | + 'event_espresso' |
|
| 154 | + ); |
|
| 155 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 156 | + // dev only message |
|
| 157 | + $max_atndz_string = _n( |
|
| 158 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 159 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 160 | + $valid['max_atndz'], |
|
| 161 | + 'event_espresso' |
|
| 162 | + ); |
|
| 163 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 164 | + \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + } else { |
|
| 166 | + // all data appears to be valid |
|
| 167 | + $tckts_slctd = false; |
|
| 168 | + $tickets_added = 0; |
|
| 169 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
| 170 | + if ($valid['total_tickets'] > 0) { |
|
| 171 | + // load cart |
|
| 172 | + \EE_Registry::instance()->load_core('Cart'); |
|
| 173 | + // cycle thru the number of data rows sent from the event listing |
|
| 174 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 175 | + // does this row actually contain a ticket quantity? |
|
| 176 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 177 | + // YES we have a ticket quantity |
|
| 178 | + $tckts_slctd = true; |
|
| 179 | + // d( $valid['ticket_obj'][$x] ); |
|
| 180 | + if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
| 181 | + // then add ticket to cart |
|
| 182 | + $tickets_added += $this->addTicketToCart( |
|
| 183 | + $valid['ticket_obj'][$x], |
|
| 184 | + $valid['qty'][$x] |
|
| 185 | + ); |
|
| 186 | + if (\EE_Error::has_error()) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + // nothing added to cart retrieved |
|
| 191 | + \EE_Error::add_error( |
|
| 192 | + sprintf( |
|
| 193 | + __( |
|
| 194 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ), |
|
| 197 | + '<br/>' |
|
| 198 | + ), |
|
| 199 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + do_action( |
|
| 206 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 207 | + \EE_Registry::instance()->CART, |
|
| 208 | + $this |
|
| 209 | + ); |
|
| 210 | + //d( \EE_Registry::instance()->CART ); |
|
| 211 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 212 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
| 213 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 214 | + do_action( |
|
| 215 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 216 | + \EE_Registry::instance()->CART, |
|
| 217 | + $this |
|
| 218 | + ); |
|
| 219 | + \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 220 | + \EE_Registry::instance()->CART->save_cart(false); |
|
| 221 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 222 | + // just return TRUE for registrations being made from admin |
|
| 223 | + if (is_admin()) { |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | + \EE_Error::get_notices(false, true); |
|
| 227 | + wp_safe_redirect( |
|
| 228 | + apply_filters( |
|
| 229 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 230 | + \EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + exit(); |
|
| 234 | + } else { |
|
| 235 | + if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
| 236 | + // nothing added to cart |
|
| 237 | + \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
| 238 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } else { |
|
| 242 | + // no ticket quantities were selected |
|
| 243 | + \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
| 244 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 248 | + // at this point, just return if registration is being made from admin |
|
| 249 | + if (is_admin()) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + if ($valid['return_url']) { |
|
| 253 | + \EE_Error::get_notices(false, true); |
|
| 254 | + wp_safe_redirect($valid['return_url']); |
|
| 255 | + exit(); |
|
| 256 | + } elseif (isset($event_to_add['id'])) { |
|
| 257 | + \EE_Error::get_notices(false, true); |
|
| 258 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
| 259 | + exit(); |
|
| 260 | + } else { |
|
| 261 | + echo \EE_Error::get_notices(); |
|
| 262 | + } |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * validate_post_data |
|
| 270 | + * |
|
| 271 | + * @param int $id |
|
| 272 | + * @return array|FALSE |
|
| 273 | + */ |
|
| 274 | + private function validatePostData($id = 0) |
|
| 275 | + { |
|
| 276 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 277 | + if ( ! $id) { |
|
| 278 | + \EE_Error::add_error( |
|
| 279 | + __('The event id provided was not valid.', 'event_espresso'), |
|
| 280 | + __FILE__, |
|
| 281 | + __FUNCTION__, |
|
| 282 | + __LINE__ |
|
| 283 | + ); |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + // start with an empty array() |
|
| 287 | + $valid_data = array(); |
|
| 288 | + // grab valid id |
|
| 289 | + $valid_data['id'] = $id; |
|
| 290 | + // array of other form names |
|
| 291 | + $inputs_to_clean = array( |
|
| 292 | + 'event_id' => 'tkt-slctr-event-id', |
|
| 293 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 294 | + 'rows' => 'tkt-slctr-rows-', |
|
| 295 | + 'qty' => 'tkt-slctr-qty-', |
|
| 296 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 297 | + 'return_url' => 'tkt-slctr-return-url-', |
|
| 298 | + ); |
|
| 299 | + // let's track the total number of tickets ordered.' |
|
| 300 | + $valid_data['total_tickets'] = 0; |
|
| 301 | + // cycle through $inputs_to_clean array |
|
| 302 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 303 | + // check for POST data |
|
| 304 | + if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
| 305 | + // grab value |
|
| 306 | + $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
| 307 | + switch ($what) { |
|
| 308 | + // integers |
|
| 309 | + case 'event_id': |
|
| 310 | + $valid_data[$what] = absint($input_value); |
|
| 311 | + // get event via the event id we put in the form |
|
| 312 | + $valid_data['event'] = \EE_Registry::instance() |
|
| 313 | + ->load_model('Event') |
|
| 314 | + ->get_one_by_ID($valid_data['event_id']); |
|
| 315 | + break; |
|
| 316 | + case 'rows': |
|
| 317 | + case 'max_atndz': |
|
| 318 | + $valid_data[$what] = absint($input_value); |
|
| 319 | + break; |
|
| 320 | + // arrays of integers |
|
| 321 | + case 'qty': |
|
| 322 | + /** @var array $row_qty */ |
|
| 323 | + $row_qty = $input_value; |
|
| 324 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 325 | + if ( ! is_array($row_qty)) { |
|
| 326 | + // get number of rows |
|
| 327 | + $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
| 328 | + ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
| 329 | + : 1; |
|
| 330 | + // explode ints by the dash |
|
| 331 | + $row_qty = explode('-', $row_qty); |
|
| 332 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 333 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 334 | + $row_qty = array($row => $qty); |
|
| 335 | + for ($x = 1; $x <= $rows; $x++) { |
|
| 336 | + if ( ! isset($row_qty[$x])) { |
|
| 337 | + $row_qty[$x] = 0; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + ksort($row_qty); |
|
| 342 | + // cycle thru values |
|
| 343 | + foreach ($row_qty as $qty) { |
|
| 344 | + $qty = absint($qty); |
|
| 345 | + // sanitize as integers |
|
| 346 | + $valid_data[$what][] = $qty; |
|
| 347 | + $valid_data['total_tickets'] += $qty; |
|
| 348 | + } |
|
| 349 | + break; |
|
| 350 | + // array of integers |
|
| 351 | + case 'ticket_id': |
|
| 352 | + $value_array = array(); |
|
| 353 | + // cycle thru values |
|
| 354 | + foreach ((array)$input_value as $key => $value) { |
|
| 355 | + // allow only numbers, letters, spaces, commas and dashes |
|
| 356 | + $value_array[$key] = wp_strip_all_tags($value); |
|
| 357 | + // get ticket via the ticket id we put in the form |
|
| 358 | + $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
| 359 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
| 360 | + } |
|
| 361 | + $valid_data[$what] = $value_array; |
|
| 362 | + break; |
|
| 363 | + case 'return_url' : |
|
| 364 | + // grab and sanitize return-url |
|
| 365 | + $input_value = esc_url_raw($input_value); |
|
| 366 | + // was the request coming from an iframe ? if so, then: |
|
| 367 | + if (strpos($input_value, 'event_list=iframe')) { |
|
| 368 | + // get anchor fragment |
|
| 369 | + $input_value = explode('#', $input_value); |
|
| 370 | + $input_value = end($input_value); |
|
| 371 | + // use event list url instead, but append anchor |
|
| 372 | + $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 373 | + } |
|
| 374 | + $valid_data[$what] = $input_value; |
|
| 375 | + break; |
|
| 376 | + } // end switch $what |
|
| 377 | + } |
|
| 378 | + } // end foreach $inputs_to_clean |
|
| 379 | + return $valid_data; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * adds a ticket to the cart |
|
| 386 | + * |
|
| 387 | + * @param \EE_Ticket $ticket |
|
| 388 | + * @param int $qty |
|
| 389 | + * @return TRUE on success, FALSE on fail |
|
| 390 | + * @throws \EE_Error |
|
| 391 | + */ |
|
| 392 | + private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
| 393 | + { |
|
| 394 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 395 | + // get the number of spaces left for this datetime ticket |
|
| 396 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
| 397 | + // compare available spaces against the number of tickets being purchased |
|
| 398 | + if ($available_spaces >= $qty) { |
|
| 399 | + // allow addons to prevent a ticket from being added to cart |
|
| 400 | + if ( |
|
| 401 | + ! apply_filters( |
|
| 402 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 403 | + true, |
|
| 404 | + $ticket, |
|
| 405 | + $qty, |
|
| 406 | + $available_spaces |
|
| 407 | + ) |
|
| 408 | + ) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 412 | + // add event to cart |
|
| 413 | + if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
| 414 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 415 | + return true; |
|
| 416 | + } |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 419 | + // tickets can not be purchased but let's find the exact number left |
|
| 420 | + // for the last ticket selected PRIOR to subtracting tickets |
|
| 421 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
| 422 | + // greedy greedy greedy eh? |
|
| 423 | + if ($available_spaces > 0) { |
|
| 424 | + if ( |
|
| 425 | + apply_filters( |
|
| 426 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
| 427 | + true, |
|
| 428 | + $ticket, |
|
| 429 | + $qty, |
|
| 430 | + $available_spaces |
|
| 431 | + ) |
|
| 432 | + ) { |
|
| 433 | + $this->displayAvailabilityError($available_spaces); |
|
| 434 | + } |
|
| 435 | + } else { |
|
| 436 | + \EE_Error::add_error( |
|
| 437 | + __( |
|
| 438 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 439 | + 'event_espresso' |
|
| 440 | + ), |
|
| 441 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + return false; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param int $available_spaces |
|
| 451 | + * @throws \EE_Error |
|
| 452 | + */ |
|
| 453 | + private function displayAvailabilityError($available_spaces = 1) |
|
| 454 | + { |
|
| 455 | + // add error messaging - we're using the _n function that will generate |
|
| 456 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
| 457 | + if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
| 458 | + $msg = sprintf( |
|
| 459 | + _n( |
|
| 460 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 461 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 462 | + $available_spaces, |
|
| 463 | + 'event_espresso' |
|
| 464 | + ), |
|
| 465 | + $available_spaces, |
|
| 466 | + '<br />' |
|
| 467 | + ); |
|
| 468 | + } else { |
|
| 469 | + $msg = sprintf( |
|
| 470 | + _n( |
|
| 471 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 472 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 473 | + $available_spaces, |
|
| 474 | + 'event_espresso' |
|
| 475 | + ), |
|
| 476 | + $available_spaces, |
|
| 477 | + '<br />' |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * ticketDatetimeAvailability |
|
| 487 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 488 | + * and tracks the spaces remaining for each of those datetimes |
|
| 489 | + * |
|
| 490 | + * @param \EE_Ticket $ticket - selected ticket |
|
| 491 | + * @param bool $get_original_ticket_spaces |
|
| 492 | + * @return int |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | + private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
| 496 | + { |
|
| 497 | + // if the $_available_spaces array has not been set up yet... |
|
| 498 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 499 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
| 500 | + } |
|
| 501 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 502 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 503 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 504 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 505 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 506 | + if ($get_original_ticket_spaces) { |
|
| 507 | + // then grab the available spaces from the "tickets" array |
|
| 508 | + // and compare with the above to get the lowest number |
|
| 509 | + $available_spaces = min( |
|
| 510 | + $available_spaces, |
|
| 511 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
| 512 | + ); |
|
| 513 | + } else { |
|
| 514 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
| 515 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + return $available_spaces; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @param \EE_Ticket $ticket |
|
| 526 | + * @return void |
|
| 527 | + * @throws \EE_Error |
|
| 528 | + */ |
|
| 529 | + private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
| 530 | + { |
|
| 531 | + // first, get all of the datetimes that are available to this ticket |
|
| 532 | + $datetimes = $ticket->get_many_related( |
|
| 533 | + 'Datetime', |
|
| 534 | + array( |
|
| 535 | + array( |
|
| 536 | + 'DTT_EVT_end' => array( |
|
| 537 | + '>=', |
|
| 538 | + \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 539 | + ), |
|
| 540 | + ), |
|
| 541 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 542 | + ) |
|
| 543 | + ); |
|
| 544 | + if ( ! empty($datetimes)) { |
|
| 545 | + // now loop thru all of the datetimes |
|
| 546 | + foreach ($datetimes as $datetime) { |
|
| 547 | + if ($datetime instanceof \EE_Datetime) { |
|
| 548 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 549 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
| 550 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 551 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 552 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
| 553 | + $ticket->qty() - $ticket->sold(), |
|
| 554 | + $spaces_remaining |
|
| 555 | + ); |
|
| 556 | + // if the remaining spaces for this datetime is already set, |
|
| 557 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 558 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 559 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
| 560 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
| 561 | + ) |
|
| 562 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
| 563 | + : $spaces_remaining; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param \EE_Ticket $ticket |
|
| 573 | + * @param int $qty |
|
| 574 | + * @return void |
|
| 575 | + */ |
|
| 576 | + private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
| 577 | + { |
|
| 578 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 579 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 580 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 581 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 582 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | 587 | |
| 588 | 588 | } |
@@ -34,139 +34,139 @@ |
||
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * the actual shortcode tag that gets registered with WordPress |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function getTag() |
|
| 43 | - { |
|
| 44 | - return 'ESPRESSO_EVENTS'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * the time in seconds to cache the results of the processShortcode() method |
|
| 51 | - * 0 means the processShortcode() results will NOT be cached at all |
|
| 52 | - * |
|
| 53 | - * @return int |
|
| 54 | - */ |
|
| 55 | - public function cacheExpiration() |
|
| 56 | - { |
|
| 57 | - return 0; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 64 | - * this may be required for shortcodes that utilize a corresponding module, |
|
| 65 | - * and need to enqueue assets for that module |
|
| 66 | - * |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public function initializeShortcode() |
|
| 70 | - { |
|
| 71 | - EED_Events_Archive::instance()->event_list(); |
|
| 72 | - $this->shortcodeHasBeenInitialized(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * callback that runs when the shortcode is encountered in post content. |
|
| 79 | - * IMPORTANT !!! |
|
| 80 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
| 81 | - * |
|
| 82 | - * @param array $attributes |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function processShortcode($attributes = array()) |
|
| 86 | - { |
|
| 87 | - // grab attributes and merge with defaults |
|
| 88 | - $attributes = $this->getAttributes($attributes); |
|
| 89 | - // make sure we use the_excerpt() |
|
| 90 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
| 91 | - // apply query filters |
|
| 92 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 93 | - // run the query |
|
| 94 | - global $wp_query; |
|
| 95 | - // yes we have to overwrite the main wp query, but it's ok... |
|
| 96 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
| 97 | - $wp_query = new EventListQuery($attributes); |
|
| 98 | - // check what template is loaded and load filters accordingly |
|
| 99 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
| 100 | - // load our template |
|
| 101 | - $event_list = EEH_Template::locate_template( |
|
| 102 | - 'loop-espresso_events.php', |
|
| 103 | - array(), |
|
| 104 | - true, |
|
| 105 | - true |
|
| 106 | - ); |
|
| 107 | - // now reset the query and post data |
|
| 108 | - wp_reset_query(); |
|
| 109 | - wp_reset_postdata(); |
|
| 110 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
| 111 | - // remove query filters |
|
| 112 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 113 | - // pull our content from the output buffer and return it |
|
| 114 | - return $event_list; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * merge incoming attributes with filtered defaults |
|
| 121 | - * |
|
| 122 | - * @param array $attributes |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - private function getAttributes(array $attributes) |
|
| 126 | - { |
|
| 127 | - return array_merge( |
|
| 128 | - (array)apply_filters( |
|
| 129 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
| 130 | - array( |
|
| 131 | - 'title' => '', |
|
| 132 | - 'limit' => 10, |
|
| 133 | - 'css_class' => '', |
|
| 134 | - 'show_expired' => false, |
|
| 135 | - 'month' => '', |
|
| 136 | - 'category_slug' => '', |
|
| 137 | - 'order_by' => 'start_date', |
|
| 138 | - 'sort' => 'ASC', |
|
| 139 | - 'show_title' => true, |
|
| 140 | - ) |
|
| 141 | - ), |
|
| 142 | - $attributes |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * array for defining custom attribute sanitization callbacks, |
|
| 150 | - * where keys match keys in your attributes array, |
|
| 151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | - * So for example, if you had an integer attribute named "event_id" |
|
| 153 | - * that you wanted to be sanitized using absint(), |
|
| 154 | - * then you would pass the following for your $custom_sanitization array: |
|
| 155 | - * array('event_id' => 'absint') |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - protected function customAttributeSanitizationMap() |
|
| 160 | - { |
|
| 161 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 162 | - return array( |
|
| 163 | - 'category_slug' => 'skip_sanitization', |
|
| 164 | - 'show_expired' => 'skip_sanitization', |
|
| 165 | - 'order_by' => 'skip_sanitization', |
|
| 166 | - 'month' => 'skip_sanitization', |
|
| 167 | - 'sort' => 'skip_sanitization', |
|
| 168 | - ); |
|
| 169 | - } |
|
| 37 | + /** |
|
| 38 | + * the actual shortcode tag that gets registered with WordPress |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function getTag() |
|
| 43 | + { |
|
| 44 | + return 'ESPRESSO_EVENTS'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * the time in seconds to cache the results of the processShortcode() method |
|
| 51 | + * 0 means the processShortcode() results will NOT be cached at all |
|
| 52 | + * |
|
| 53 | + * @return int |
|
| 54 | + */ |
|
| 55 | + public function cacheExpiration() |
|
| 56 | + { |
|
| 57 | + return 0; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 64 | + * this may be required for shortcodes that utilize a corresponding module, |
|
| 65 | + * and need to enqueue assets for that module |
|
| 66 | + * |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public function initializeShortcode() |
|
| 70 | + { |
|
| 71 | + EED_Events_Archive::instance()->event_list(); |
|
| 72 | + $this->shortcodeHasBeenInitialized(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * callback that runs when the shortcode is encountered in post content. |
|
| 79 | + * IMPORTANT !!! |
|
| 80 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
| 81 | + * |
|
| 82 | + * @param array $attributes |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function processShortcode($attributes = array()) |
|
| 86 | + { |
|
| 87 | + // grab attributes and merge with defaults |
|
| 88 | + $attributes = $this->getAttributes($attributes); |
|
| 89 | + // make sure we use the_excerpt() |
|
| 90 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
| 91 | + // apply query filters |
|
| 92 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 93 | + // run the query |
|
| 94 | + global $wp_query; |
|
| 95 | + // yes we have to overwrite the main wp query, but it's ok... |
|
| 96 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
| 97 | + $wp_query = new EventListQuery($attributes); |
|
| 98 | + // check what template is loaded and load filters accordingly |
|
| 99 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
| 100 | + // load our template |
|
| 101 | + $event_list = EEH_Template::locate_template( |
|
| 102 | + 'loop-espresso_events.php', |
|
| 103 | + array(), |
|
| 104 | + true, |
|
| 105 | + true |
|
| 106 | + ); |
|
| 107 | + // now reset the query and post data |
|
| 108 | + wp_reset_query(); |
|
| 109 | + wp_reset_postdata(); |
|
| 110 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
| 111 | + // remove query filters |
|
| 112 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 113 | + // pull our content from the output buffer and return it |
|
| 114 | + return $event_list; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * merge incoming attributes with filtered defaults |
|
| 121 | + * |
|
| 122 | + * @param array $attributes |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + private function getAttributes(array $attributes) |
|
| 126 | + { |
|
| 127 | + return array_merge( |
|
| 128 | + (array)apply_filters( |
|
| 129 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
| 130 | + array( |
|
| 131 | + 'title' => '', |
|
| 132 | + 'limit' => 10, |
|
| 133 | + 'css_class' => '', |
|
| 134 | + 'show_expired' => false, |
|
| 135 | + 'month' => '', |
|
| 136 | + 'category_slug' => '', |
|
| 137 | + 'order_by' => 'start_date', |
|
| 138 | + 'sort' => 'ASC', |
|
| 139 | + 'show_title' => true, |
|
| 140 | + ) |
|
| 141 | + ), |
|
| 142 | + $attributes |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * array for defining custom attribute sanitization callbacks, |
|
| 150 | + * where keys match keys in your attributes array, |
|
| 151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | + * So for example, if you had an integer attribute named "event_id" |
|
| 153 | + * that you wanted to be sanitized using absint(), |
|
| 154 | + * then you would pass the following for your $custom_sanitization array: |
|
| 155 | + * array('event_id' => 'absint') |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + protected function customAttributeSanitizationMap() |
|
| 160 | + { |
|
| 161 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 162 | + return array( |
|
| 163 | + 'category_slug' => 'skip_sanitization', |
|
| 164 | + 'show_expired' => 'skip_sanitization', |
|
| 165 | + 'order_by' => 'skip_sanitization', |
|
| 166 | + 'month' => 'skip_sanitization', |
|
| 167 | + 'sort' => 'skip_sanitization', |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | |
@@ -14,115 +14,115 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * EE_Message_Template_Group_Collection constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() |
|
| 21 | - { |
|
| 22 | - $this->interface = 'EE_Message_Template_Group'; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * EE_Message_Template_Group_Collection constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() |
|
| 21 | + { |
|
| 22 | + $this->interface = 'EE_Message_Template_Group'; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Adds the Message Template Group object to the repository. |
|
| 28 | - * |
|
| 29 | - * @param $message_template_group |
|
| 30 | - * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
| 31 | - * indexing the template by key. If this template is shared among multiple events then |
|
| 32 | - * include the events as an array. |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function add($message_template_group, $EVT_ID = array()) |
|
| 36 | - { |
|
| 37 | - $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
| 38 | - if ($message_template_group instanceof $this->interface) { |
|
| 39 | - $data['key'] = $this->getKey( |
|
| 40 | - $message_template_group->messenger(), |
|
| 41 | - $message_template_group->message_type(), |
|
| 42 | - $EVT_ID |
|
| 43 | - ); |
|
| 44 | - return parent::add($message_template_group, $data); |
|
| 45 | - } |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 26 | + /** |
|
| 27 | + * Adds the Message Template Group object to the repository. |
|
| 28 | + * |
|
| 29 | + * @param $message_template_group |
|
| 30 | + * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
| 31 | + * indexing the template by key. If this template is shared among multiple events then |
|
| 32 | + * include the events as an array. |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function add($message_template_group, $EVT_ID = array()) |
|
| 36 | + { |
|
| 37 | + $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
| 38 | + if ($message_template_group instanceof $this->interface) { |
|
| 39 | + $data['key'] = $this->getKey( |
|
| 40 | + $message_template_group->messenger(), |
|
| 41 | + $message_template_group->message_type(), |
|
| 42 | + $EVT_ID |
|
| 43 | + ); |
|
| 44 | + return parent::add($message_template_group, $data); |
|
| 45 | + } |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
| 52 | - * |
|
| 53 | - * @param $GRP_ID |
|
| 54 | - * @return EE_Message_Template_Group | null |
|
| 55 | - */ |
|
| 56 | - public function get_by_ID($GRP_ID) |
|
| 57 | - { |
|
| 58 | - $this->rewind(); |
|
| 59 | - while ($this->valid()) { |
|
| 60 | - if ($this->current()->ID() === $GRP_ID) { |
|
| 61 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
| 62 | - $message_template_group = $this->current(); |
|
| 63 | - $this->rewind(); |
|
| 64 | - return $message_template_group; |
|
| 65 | - } |
|
| 66 | - $this->next(); |
|
| 67 | - } |
|
| 68 | - return null; |
|
| 69 | - } |
|
| 50 | + /** |
|
| 51 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
| 52 | + * |
|
| 53 | + * @param $GRP_ID |
|
| 54 | + * @return EE_Message_Template_Group | null |
|
| 55 | + */ |
|
| 56 | + public function get_by_ID($GRP_ID) |
|
| 57 | + { |
|
| 58 | + $this->rewind(); |
|
| 59 | + while ($this->valid()) { |
|
| 60 | + if ($this->current()->ID() === $GRP_ID) { |
|
| 61 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
| 62 | + $message_template_group = $this->current(); |
|
| 63 | + $this->rewind(); |
|
| 64 | + return $message_template_group; |
|
| 65 | + } |
|
| 66 | + $this->next(); |
|
| 67 | + } |
|
| 68 | + return null; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Generates a hash used to identify a given Message Template Group. |
|
| 74 | - * |
|
| 75 | - * @param string $messenger The EE_messenger->name |
|
| 76 | - * @param string $message_type The EE_message_type->name |
|
| 77 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
| 78 | - * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
| 82 | - { |
|
| 83 | - $EVT_ID = (array) $EVT_ID; |
|
| 84 | - return $this->getKey($messenger, $message_type, $EVT_ID); |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * Generates a hash used to identify a given Message Template Group. |
|
| 74 | + * |
|
| 75 | + * @param string $messenger The EE_messenger->name |
|
| 76 | + * @param string $message_type The EE_message_type->name |
|
| 77 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
| 78 | + * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
| 82 | + { |
|
| 83 | + $EVT_ID = (array) $EVT_ID; |
|
| 84 | + return $this->getKey($messenger, $message_type, $EVT_ID); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Generates a hash used to identify a given Message Template Group |
|
| 90 | - * @param string $messenger The EE_messenger->name |
|
| 91 | - * @param string $message_type The EE_message_type->name |
|
| 92 | - * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
| 93 | - * be included. |
|
| 94 | - * @since 4.9.40.rc.017 |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
| 98 | - { |
|
| 99 | - sort($EVT_ID); |
|
| 100 | - $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
| 101 | - return md5($messenger . $message_type . $EVT_ID); |
|
| 102 | - } |
|
| 88 | + /** |
|
| 89 | + * Generates a hash used to identify a given Message Template Group |
|
| 90 | + * @param string $messenger The EE_messenger->name |
|
| 91 | + * @param string $message_type The EE_message_type->name |
|
| 92 | + * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
| 93 | + * be included. |
|
| 94 | + * @since 4.9.40.rc.017 |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
| 98 | + { |
|
| 99 | + sort($EVT_ID); |
|
| 100 | + $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
| 101 | + return md5($messenger . $message_type . $EVT_ID); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
| 107 | - * the given string. |
|
| 108 | - * |
|
| 109 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
| 110 | - * @return null|EE_Message_Template_Group |
|
| 111 | - */ |
|
| 112 | - public function get_by_key($key) |
|
| 113 | - { |
|
| 114 | - $this->rewind(); |
|
| 115 | - while ($this->valid()) { |
|
| 116 | - $data = $this->getInfo(); |
|
| 117 | - if (isset($data['key']) && $data['key'] === $key) { |
|
| 118 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
| 119 | - $message_template_group = $this->current(); |
|
| 120 | - $this->rewind(); |
|
| 121 | - return $message_template_group; |
|
| 122 | - } |
|
| 123 | - $this->next(); |
|
| 124 | - } |
|
| 125 | - return null; |
|
| 126 | - } |
|
| 105 | + /** |
|
| 106 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
| 107 | + * the given string. |
|
| 108 | + * |
|
| 109 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
| 110 | + * @return null|EE_Message_Template_Group |
|
| 111 | + */ |
|
| 112 | + public function get_by_key($key) |
|
| 113 | + { |
|
| 114 | + $this->rewind(); |
|
| 115 | + while ($this->valid()) { |
|
| 116 | + $data = $this->getInfo(); |
|
| 117 | + if (isset($data['key']) && $data['key'] === $key) { |
|
| 118 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
| 119 | + $message_template_group = $this->current(); |
|
| 120 | + $this->rewind(); |
|
| 121 | + return $message_template_group; |
|
| 122 | + } |
|
| 123 | + $this->next(); |
|
| 124 | + } |
|
| 125 | + return null; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | } |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | { |
| 99 | 99 | sort($EVT_ID); |
| 100 | 100 | $EVT_ID = implode(',', array_unique($EVT_ID)); |
| 101 | - return md5($messenger . $message_type . $EVT_ID); |
|
| 101 | + return md5($messenger.$message_type.$EVT_ID); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | |
@@ -17,2634 +17,2634 @@ discard block |
||
| 17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This will hold the event object for event_details screen. |
|
| 22 | - * |
|
| 23 | - * @access protected |
|
| 24 | - * @var EE_Event $_event |
|
| 25 | - */ |
|
| 26 | - protected $_event; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This will hold the category object for category_details screen. |
|
| 31 | - * |
|
| 32 | - * @var stdClass $_category |
|
| 33 | - */ |
|
| 34 | - protected $_category; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * This will hold the event model instance |
|
| 39 | - * |
|
| 40 | - * @var EEM_Event $_event_model |
|
| 41 | - */ |
|
| 42 | - protected $_event_model; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Event |
|
| 48 | - */ |
|
| 49 | - protected $_cpt_model_obj = false; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - protected function _init_page_props() |
|
| 54 | - { |
|
| 55 | - $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | - $this->page_label = EVENTS_LABEL; |
|
| 57 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | - $this->_cpt_model_names = array( |
|
| 60 | - 'create_new' => 'EEM_Event', |
|
| 61 | - 'edit' => 'EEM_Event', |
|
| 62 | - ); |
|
| 63 | - $this->_cpt_edit_routes = array( |
|
| 64 | - 'espresso_events' => 'edit', |
|
| 65 | - ); |
|
| 66 | - add_action( |
|
| 67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | - array($this, 'verify_event_edit') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - protected function _ajax_hooks() |
|
| 75 | - { |
|
| 76 | - //todo: all hooks for events ajax goes in here. |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - protected function _define_page_props() |
|
| 82 | - { |
|
| 83 | - $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | - $this->_labels = array( |
|
| 85 | - 'buttons' => array( |
|
| 86 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | - ), |
|
| 93 | - 'editor_title' => array( |
|
| 94 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | - ), |
|
| 96 | - 'publishbox' => array( |
|
| 97 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | - ), |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - protected function _set_page_routes() |
|
| 109 | - { |
|
| 110 | - //load formatter helper |
|
| 111 | - //load field generator helper |
|
| 112 | - //is there a evt_id in the request? |
|
| 113 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | - ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | - $this->_page_routes = array( |
|
| 117 | - 'default' => array( |
|
| 118 | - 'func' => '_events_overview_list_table', |
|
| 119 | - 'capability' => 'ee_read_events', |
|
| 120 | - ), |
|
| 121 | - 'create_new' => array( |
|
| 122 | - 'func' => '_create_new_cpt_item', |
|
| 123 | - 'capability' => 'ee_edit_events', |
|
| 124 | - ), |
|
| 125 | - 'edit' => array( |
|
| 126 | - 'func' => '_edit_cpt_item', |
|
| 127 | - 'capability' => 'ee_edit_event', |
|
| 128 | - 'obj_id' => $evt_id, |
|
| 129 | - ), |
|
| 130 | - 'copy_event' => array( |
|
| 131 | - 'func' => '_copy_events', |
|
| 132 | - 'capability' => 'ee_edit_event', |
|
| 133 | - 'obj_id' => $evt_id, |
|
| 134 | - 'noheader' => true, |
|
| 135 | - ), |
|
| 136 | - 'trash_event' => array( |
|
| 137 | - 'func' => '_trash_or_restore_event', |
|
| 138 | - 'args' => array('event_status' => 'trash'), |
|
| 139 | - 'capability' => 'ee_delete_event', |
|
| 140 | - 'obj_id' => $evt_id, |
|
| 141 | - 'noheader' => true, |
|
| 142 | - ), |
|
| 143 | - 'trash_events' => array( |
|
| 144 | - 'func' => '_trash_or_restore_events', |
|
| 145 | - 'args' => array('event_status' => 'trash'), |
|
| 146 | - 'capability' => 'ee_delete_events', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - ), |
|
| 149 | - 'restore_event' => array( |
|
| 150 | - 'func' => '_trash_or_restore_event', |
|
| 151 | - 'args' => array('event_status' => 'draft'), |
|
| 152 | - 'capability' => 'ee_delete_event', |
|
| 153 | - 'obj_id' => $evt_id, |
|
| 154 | - 'noheader' => true, |
|
| 155 | - ), |
|
| 156 | - 'restore_events' => array( |
|
| 157 | - 'func' => '_trash_or_restore_events', |
|
| 158 | - 'args' => array('event_status' => 'draft'), |
|
| 159 | - 'capability' => 'ee_delete_events', |
|
| 160 | - 'noheader' => true, |
|
| 161 | - ), |
|
| 162 | - 'delete_event' => array( |
|
| 163 | - 'func' => '_delete_event', |
|
| 164 | - 'capability' => 'ee_delete_event', |
|
| 165 | - 'obj_id' => $evt_id, |
|
| 166 | - 'noheader' => true, |
|
| 167 | - ), |
|
| 168 | - 'delete_events' => array( |
|
| 169 | - 'func' => '_delete_events', |
|
| 170 | - 'capability' => 'ee_delete_events', |
|
| 171 | - 'noheader' => true, |
|
| 172 | - ), |
|
| 173 | - 'view_report' => array( |
|
| 174 | - 'func' => '_view_report', |
|
| 175 | - 'capablity' => 'ee_edit_events', |
|
| 176 | - ), |
|
| 177 | - 'default_event_settings' => array( |
|
| 178 | - 'func' => '_default_event_settings', |
|
| 179 | - 'capability' => 'manage_options', |
|
| 180 | - ), |
|
| 181 | - 'update_default_event_settings' => array( |
|
| 182 | - 'func' => '_update_default_event_settings', |
|
| 183 | - 'capability' => 'manage_options', |
|
| 184 | - 'noheader' => true, |
|
| 185 | - ), |
|
| 186 | - 'template_settings' => array( |
|
| 187 | - 'func' => '_template_settings', |
|
| 188 | - 'capability' => 'manage_options', |
|
| 189 | - ), |
|
| 190 | - //event category tab related |
|
| 191 | - 'add_category' => array( |
|
| 192 | - 'func' => '_category_details', |
|
| 193 | - 'capability' => 'ee_edit_event_category', |
|
| 194 | - 'args' => array('add'), |
|
| 195 | - ), |
|
| 196 | - 'edit_category' => array( |
|
| 197 | - 'func' => '_category_details', |
|
| 198 | - 'capability' => 'ee_edit_event_category', |
|
| 199 | - 'args' => array('edit'), |
|
| 200 | - ), |
|
| 201 | - 'delete_categories' => array( |
|
| 202 | - 'func' => '_delete_categories', |
|
| 203 | - 'capability' => 'ee_delete_event_category', |
|
| 204 | - 'noheader' => true, |
|
| 205 | - ), |
|
| 206 | - 'delete_category' => array( |
|
| 207 | - 'func' => '_delete_categories', |
|
| 208 | - 'capability' => 'ee_delete_event_category', |
|
| 209 | - 'noheader' => true, |
|
| 210 | - ), |
|
| 211 | - 'insert_category' => array( |
|
| 212 | - 'func' => '_insert_or_update_category', |
|
| 213 | - 'args' => array('new_category' => true), |
|
| 214 | - 'capability' => 'ee_edit_event_category', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - ), |
|
| 217 | - 'update_category' => array( |
|
| 218 | - 'func' => '_insert_or_update_category', |
|
| 219 | - 'args' => array('new_category' => false), |
|
| 220 | - 'capability' => 'ee_edit_event_category', |
|
| 221 | - 'noheader' => true, |
|
| 222 | - ), |
|
| 223 | - 'category_list' => array( |
|
| 224 | - 'func' => '_category_list_table', |
|
| 225 | - 'capability' => 'ee_manage_event_categories', |
|
| 226 | - ), |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - protected function _set_page_config() |
|
| 233 | - { |
|
| 234 | - $this->_page_config = array( |
|
| 235 | - 'default' => array( |
|
| 236 | - 'nav' => array( |
|
| 237 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | - 'order' => 10, |
|
| 239 | - ), |
|
| 240 | - 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | - 'help_tabs' => array( |
|
| 242 | - 'events_overview_help_tab' => array( |
|
| 243 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | - 'filename' => 'events_overview', |
|
| 245 | - ), |
|
| 246 | - 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | - 'filename' => 'events_overview_table_column_headings', |
|
| 249 | - ), |
|
| 250 | - 'events_overview_filters_help_tab' => array( |
|
| 251 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | - 'filename' => 'events_overview_filters', |
|
| 253 | - ), |
|
| 254 | - 'events_overview_view_help_tab' => array( |
|
| 255 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | - 'filename' => 'events_overview_views', |
|
| 257 | - ), |
|
| 258 | - 'events_overview_other_help_tab' => array( |
|
| 259 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | - 'filename' => 'events_overview_other', |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - 'help_tour' => array( |
|
| 264 | - 'Event_Overview_Help_Tour', |
|
| 265 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | - ), |
|
| 267 | - 'qtips' => array( |
|
| 268 | - 'EE_Event_List_Table_Tips', |
|
| 269 | - ), |
|
| 270 | - 'require_nonce' => false, |
|
| 271 | - ), |
|
| 272 | - 'create_new' => array( |
|
| 273 | - 'nav' => array( |
|
| 274 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | - 'order' => 5, |
|
| 276 | - 'persistent' => false, |
|
| 277 | - ), |
|
| 278 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | - 'help_tabs' => array( |
|
| 280 | - 'event_editor_help_tab' => array( |
|
| 281 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | - 'filename' => 'event_editor', |
|
| 283 | - ), |
|
| 284 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | - ), |
|
| 288 | - 'event_editor_venue_details_help_tab' => array( |
|
| 289 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | - 'filename' => 'event_editor_venue_details', |
|
| 291 | - ), |
|
| 292 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | - 'filename' => 'event_editor_event_datetimes', |
|
| 295 | - ), |
|
| 296 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | - 'filename' => 'event_editor_event_tickets', |
|
| 299 | - ), |
|
| 300 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | - 'filename' => 'event_editor_event_registration_options', |
|
| 303 | - ), |
|
| 304 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | - 'filename' => 'event_editor_tags_categories', |
|
| 307 | - ), |
|
| 308 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | - 'filename' => 'event_editor_questions_registrants', |
|
| 311 | - ), |
|
| 312 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | - 'filename' => 'event_editor_save_new_event', |
|
| 315 | - ), |
|
| 316 | - 'event_editor_other_help_tab' => array( |
|
| 317 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | - 'filename' => 'event_editor_other', |
|
| 319 | - ), |
|
| 320 | - ), |
|
| 321 | - 'help_tour' => array( |
|
| 322 | - 'Event_Editor_Help_Tour', |
|
| 323 | - ), |
|
| 324 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | - 'require_nonce' => false, |
|
| 326 | - ), |
|
| 327 | - 'edit' => array( |
|
| 328 | - 'nav' => array( |
|
| 329 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | - 'order' => 5, |
|
| 331 | - 'persistent' => false, |
|
| 332 | - 'url' => isset($this->_req_data['post']) |
|
| 333 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | - $this->_current_page_view_url |
|
| 336 | - ) |
|
| 337 | - : $this->_admin_base_url, |
|
| 338 | - ), |
|
| 339 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | - 'help_tabs' => array( |
|
| 341 | - 'event_editor_help_tab' => array( |
|
| 342 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | - 'filename' => 'event_editor', |
|
| 344 | - ), |
|
| 345 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | - 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | - ), |
|
| 349 | - 'event_editor_venue_details_help_tab' => array( |
|
| 350 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | - 'filename' => 'event_editor_venue_details', |
|
| 352 | - ), |
|
| 353 | - 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | - 'filename' => 'event_editor_event_datetimes', |
|
| 356 | - ), |
|
| 357 | - 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | - 'filename' => 'event_editor_event_tickets', |
|
| 360 | - ), |
|
| 361 | - 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | - 'filename' => 'event_editor_event_registration_options', |
|
| 364 | - ), |
|
| 365 | - 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | - 'filename' => 'event_editor_tags_categories', |
|
| 368 | - ), |
|
| 369 | - 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | - 'filename' => 'event_editor_questions_registrants', |
|
| 372 | - ), |
|
| 373 | - 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | - 'filename' => 'event_editor_save_new_event', |
|
| 376 | - ), |
|
| 377 | - 'event_editor_other_help_tab' => array( |
|
| 378 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | - 'filename' => 'event_editor_other', |
|
| 380 | - ), |
|
| 381 | - ), |
|
| 382 | - /*'help_tour' => array( |
|
| 20 | + /** |
|
| 21 | + * This will hold the event object for event_details screen. |
|
| 22 | + * |
|
| 23 | + * @access protected |
|
| 24 | + * @var EE_Event $_event |
|
| 25 | + */ |
|
| 26 | + protected $_event; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This will hold the category object for category_details screen. |
|
| 31 | + * |
|
| 32 | + * @var stdClass $_category |
|
| 33 | + */ |
|
| 34 | + protected $_category; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * This will hold the event model instance |
|
| 39 | + * |
|
| 40 | + * @var EEM_Event $_event_model |
|
| 41 | + */ |
|
| 42 | + protected $_event_model; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Event |
|
| 48 | + */ |
|
| 49 | + protected $_cpt_model_obj = false; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + protected function _init_page_props() |
|
| 54 | + { |
|
| 55 | + $this->page_slug = EVENTS_PG_SLUG; |
|
| 56 | + $this->page_label = EVENTS_LABEL; |
|
| 57 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
| 58 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
| 59 | + $this->_cpt_model_names = array( |
|
| 60 | + 'create_new' => 'EEM_Event', |
|
| 61 | + 'edit' => 'EEM_Event', |
|
| 62 | + ); |
|
| 63 | + $this->_cpt_edit_routes = array( |
|
| 64 | + 'espresso_events' => 'edit', |
|
| 65 | + ); |
|
| 66 | + add_action( |
|
| 67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
| 68 | + array($this, 'verify_event_edit') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + protected function _ajax_hooks() |
|
| 75 | + { |
|
| 76 | + //todo: all hooks for events ajax goes in here. |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + protected function _define_page_props() |
|
| 82 | + { |
|
| 83 | + $this->_admin_page_title = EVENTS_LABEL; |
|
| 84 | + $this->_labels = array( |
|
| 85 | + 'buttons' => array( |
|
| 86 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
| 87 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
| 88 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
| 89 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
| 90 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
| 91 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
| 92 | + ), |
|
| 93 | + 'editor_title' => array( |
|
| 94 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
| 95 | + ), |
|
| 96 | + 'publishbox' => array( |
|
| 97 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
| 98 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
| 99 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
| 100 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
| 101 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
| 102 | + ), |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + protected function _set_page_routes() |
|
| 109 | + { |
|
| 110 | + //load formatter helper |
|
| 111 | + //load field generator helper |
|
| 112 | + //is there a evt_id in the request? |
|
| 113 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
| 114 | + ? $this->_req_data['EVT_ID'] : 0; |
|
| 115 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
| 116 | + $this->_page_routes = array( |
|
| 117 | + 'default' => array( |
|
| 118 | + 'func' => '_events_overview_list_table', |
|
| 119 | + 'capability' => 'ee_read_events', |
|
| 120 | + ), |
|
| 121 | + 'create_new' => array( |
|
| 122 | + 'func' => '_create_new_cpt_item', |
|
| 123 | + 'capability' => 'ee_edit_events', |
|
| 124 | + ), |
|
| 125 | + 'edit' => array( |
|
| 126 | + 'func' => '_edit_cpt_item', |
|
| 127 | + 'capability' => 'ee_edit_event', |
|
| 128 | + 'obj_id' => $evt_id, |
|
| 129 | + ), |
|
| 130 | + 'copy_event' => array( |
|
| 131 | + 'func' => '_copy_events', |
|
| 132 | + 'capability' => 'ee_edit_event', |
|
| 133 | + 'obj_id' => $evt_id, |
|
| 134 | + 'noheader' => true, |
|
| 135 | + ), |
|
| 136 | + 'trash_event' => array( |
|
| 137 | + 'func' => '_trash_or_restore_event', |
|
| 138 | + 'args' => array('event_status' => 'trash'), |
|
| 139 | + 'capability' => 'ee_delete_event', |
|
| 140 | + 'obj_id' => $evt_id, |
|
| 141 | + 'noheader' => true, |
|
| 142 | + ), |
|
| 143 | + 'trash_events' => array( |
|
| 144 | + 'func' => '_trash_or_restore_events', |
|
| 145 | + 'args' => array('event_status' => 'trash'), |
|
| 146 | + 'capability' => 'ee_delete_events', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + ), |
|
| 149 | + 'restore_event' => array( |
|
| 150 | + 'func' => '_trash_or_restore_event', |
|
| 151 | + 'args' => array('event_status' => 'draft'), |
|
| 152 | + 'capability' => 'ee_delete_event', |
|
| 153 | + 'obj_id' => $evt_id, |
|
| 154 | + 'noheader' => true, |
|
| 155 | + ), |
|
| 156 | + 'restore_events' => array( |
|
| 157 | + 'func' => '_trash_or_restore_events', |
|
| 158 | + 'args' => array('event_status' => 'draft'), |
|
| 159 | + 'capability' => 'ee_delete_events', |
|
| 160 | + 'noheader' => true, |
|
| 161 | + ), |
|
| 162 | + 'delete_event' => array( |
|
| 163 | + 'func' => '_delete_event', |
|
| 164 | + 'capability' => 'ee_delete_event', |
|
| 165 | + 'obj_id' => $evt_id, |
|
| 166 | + 'noheader' => true, |
|
| 167 | + ), |
|
| 168 | + 'delete_events' => array( |
|
| 169 | + 'func' => '_delete_events', |
|
| 170 | + 'capability' => 'ee_delete_events', |
|
| 171 | + 'noheader' => true, |
|
| 172 | + ), |
|
| 173 | + 'view_report' => array( |
|
| 174 | + 'func' => '_view_report', |
|
| 175 | + 'capablity' => 'ee_edit_events', |
|
| 176 | + ), |
|
| 177 | + 'default_event_settings' => array( |
|
| 178 | + 'func' => '_default_event_settings', |
|
| 179 | + 'capability' => 'manage_options', |
|
| 180 | + ), |
|
| 181 | + 'update_default_event_settings' => array( |
|
| 182 | + 'func' => '_update_default_event_settings', |
|
| 183 | + 'capability' => 'manage_options', |
|
| 184 | + 'noheader' => true, |
|
| 185 | + ), |
|
| 186 | + 'template_settings' => array( |
|
| 187 | + 'func' => '_template_settings', |
|
| 188 | + 'capability' => 'manage_options', |
|
| 189 | + ), |
|
| 190 | + //event category tab related |
|
| 191 | + 'add_category' => array( |
|
| 192 | + 'func' => '_category_details', |
|
| 193 | + 'capability' => 'ee_edit_event_category', |
|
| 194 | + 'args' => array('add'), |
|
| 195 | + ), |
|
| 196 | + 'edit_category' => array( |
|
| 197 | + 'func' => '_category_details', |
|
| 198 | + 'capability' => 'ee_edit_event_category', |
|
| 199 | + 'args' => array('edit'), |
|
| 200 | + ), |
|
| 201 | + 'delete_categories' => array( |
|
| 202 | + 'func' => '_delete_categories', |
|
| 203 | + 'capability' => 'ee_delete_event_category', |
|
| 204 | + 'noheader' => true, |
|
| 205 | + ), |
|
| 206 | + 'delete_category' => array( |
|
| 207 | + 'func' => '_delete_categories', |
|
| 208 | + 'capability' => 'ee_delete_event_category', |
|
| 209 | + 'noheader' => true, |
|
| 210 | + ), |
|
| 211 | + 'insert_category' => array( |
|
| 212 | + 'func' => '_insert_or_update_category', |
|
| 213 | + 'args' => array('new_category' => true), |
|
| 214 | + 'capability' => 'ee_edit_event_category', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + ), |
|
| 217 | + 'update_category' => array( |
|
| 218 | + 'func' => '_insert_or_update_category', |
|
| 219 | + 'args' => array('new_category' => false), |
|
| 220 | + 'capability' => 'ee_edit_event_category', |
|
| 221 | + 'noheader' => true, |
|
| 222 | + ), |
|
| 223 | + 'category_list' => array( |
|
| 224 | + 'func' => '_category_list_table', |
|
| 225 | + 'capability' => 'ee_manage_event_categories', |
|
| 226 | + ), |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + protected function _set_page_config() |
|
| 233 | + { |
|
| 234 | + $this->_page_config = array( |
|
| 235 | + 'default' => array( |
|
| 236 | + 'nav' => array( |
|
| 237 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 238 | + 'order' => 10, |
|
| 239 | + ), |
|
| 240 | + 'list_table' => 'Events_Admin_List_Table', |
|
| 241 | + 'help_tabs' => array( |
|
| 242 | + 'events_overview_help_tab' => array( |
|
| 243 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
| 244 | + 'filename' => 'events_overview', |
|
| 245 | + ), |
|
| 246 | + 'events_overview_table_column_headings_help_tab' => array( |
|
| 247 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
| 248 | + 'filename' => 'events_overview_table_column_headings', |
|
| 249 | + ), |
|
| 250 | + 'events_overview_filters_help_tab' => array( |
|
| 251 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
| 252 | + 'filename' => 'events_overview_filters', |
|
| 253 | + ), |
|
| 254 | + 'events_overview_view_help_tab' => array( |
|
| 255 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
| 256 | + 'filename' => 'events_overview_views', |
|
| 257 | + ), |
|
| 258 | + 'events_overview_other_help_tab' => array( |
|
| 259 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
| 260 | + 'filename' => 'events_overview_other', |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + 'help_tour' => array( |
|
| 264 | + 'Event_Overview_Help_Tour', |
|
| 265 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
| 266 | + ), |
|
| 267 | + 'qtips' => array( |
|
| 268 | + 'EE_Event_List_Table_Tips', |
|
| 269 | + ), |
|
| 270 | + 'require_nonce' => false, |
|
| 271 | + ), |
|
| 272 | + 'create_new' => array( |
|
| 273 | + 'nav' => array( |
|
| 274 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
| 275 | + 'order' => 5, |
|
| 276 | + 'persistent' => false, |
|
| 277 | + ), |
|
| 278 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 279 | + 'help_tabs' => array( |
|
| 280 | + 'event_editor_help_tab' => array( |
|
| 281 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 282 | + 'filename' => 'event_editor', |
|
| 283 | + ), |
|
| 284 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 285 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 286 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 287 | + ), |
|
| 288 | + 'event_editor_venue_details_help_tab' => array( |
|
| 289 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 290 | + 'filename' => 'event_editor_venue_details', |
|
| 291 | + ), |
|
| 292 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 293 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 294 | + 'filename' => 'event_editor_event_datetimes', |
|
| 295 | + ), |
|
| 296 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 297 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 298 | + 'filename' => 'event_editor_event_tickets', |
|
| 299 | + ), |
|
| 300 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 301 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 302 | + 'filename' => 'event_editor_event_registration_options', |
|
| 303 | + ), |
|
| 304 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 305 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 306 | + 'filename' => 'event_editor_tags_categories', |
|
| 307 | + ), |
|
| 308 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 309 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 310 | + 'filename' => 'event_editor_questions_registrants', |
|
| 311 | + ), |
|
| 312 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 313 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 314 | + 'filename' => 'event_editor_save_new_event', |
|
| 315 | + ), |
|
| 316 | + 'event_editor_other_help_tab' => array( |
|
| 317 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 318 | + 'filename' => 'event_editor_other', |
|
| 319 | + ), |
|
| 320 | + ), |
|
| 321 | + 'help_tour' => array( |
|
| 322 | + 'Event_Editor_Help_Tour', |
|
| 323 | + ), |
|
| 324 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 325 | + 'require_nonce' => false, |
|
| 326 | + ), |
|
| 327 | + 'edit' => array( |
|
| 328 | + 'nav' => array( |
|
| 329 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
| 330 | + 'order' => 5, |
|
| 331 | + 'persistent' => false, |
|
| 332 | + 'url' => isset($this->_req_data['post']) |
|
| 333 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 334 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
| 335 | + $this->_current_page_view_url |
|
| 336 | + ) |
|
| 337 | + : $this->_admin_base_url, |
|
| 338 | + ), |
|
| 339 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
| 340 | + 'help_tabs' => array( |
|
| 341 | + 'event_editor_help_tab' => array( |
|
| 342 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
| 343 | + 'filename' => 'event_editor', |
|
| 344 | + ), |
|
| 345 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
| 346 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
| 347 | + 'filename' => 'event_editor_title_richtexteditor', |
|
| 348 | + ), |
|
| 349 | + 'event_editor_venue_details_help_tab' => array( |
|
| 350 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
| 351 | + 'filename' => 'event_editor_venue_details', |
|
| 352 | + ), |
|
| 353 | + 'event_editor_event_datetimes_help_tab' => array( |
|
| 354 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
| 355 | + 'filename' => 'event_editor_event_datetimes', |
|
| 356 | + ), |
|
| 357 | + 'event_editor_event_tickets_help_tab' => array( |
|
| 358 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
| 359 | + 'filename' => 'event_editor_event_tickets', |
|
| 360 | + ), |
|
| 361 | + 'event_editor_event_registration_options_help_tab' => array( |
|
| 362 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
| 363 | + 'filename' => 'event_editor_event_registration_options', |
|
| 364 | + ), |
|
| 365 | + 'event_editor_tags_categories_help_tab' => array( |
|
| 366 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
| 367 | + 'filename' => 'event_editor_tags_categories', |
|
| 368 | + ), |
|
| 369 | + 'event_editor_questions_registrants_help_tab' => array( |
|
| 370 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
| 371 | + 'filename' => 'event_editor_questions_registrants', |
|
| 372 | + ), |
|
| 373 | + 'event_editor_save_new_event_help_tab' => array( |
|
| 374 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
| 375 | + 'filename' => 'event_editor_save_new_event', |
|
| 376 | + ), |
|
| 377 | + 'event_editor_other_help_tab' => array( |
|
| 378 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
| 379 | + 'filename' => 'event_editor_other', |
|
| 380 | + ), |
|
| 381 | + ), |
|
| 382 | + /*'help_tour' => array( |
|
| 383 | 383 | 'Event_Edit_Help_Tour' |
| 384 | 384 | ),*/ |
| 385 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | - 'require_nonce' => false, |
|
| 387 | - ), |
|
| 388 | - 'default_event_settings' => array( |
|
| 389 | - 'nav' => array( |
|
| 390 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | - 'order' => 40, |
|
| 392 | - ), |
|
| 393 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | - 'labels' => array( |
|
| 395 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | - ), |
|
| 397 | - 'help_tabs' => array( |
|
| 398 | - 'default_settings_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | - 'filename' => 'events_default_settings', |
|
| 401 | - ), |
|
| 402 | - 'default_settings_status_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | - 'filename' => 'events_default_settings_status', |
|
| 405 | - ), |
|
| 406 | - 'default_maximum_tickets_help_tab' => array( |
|
| 407 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 408 | - 'filename' => 'events_default_settings_max_tickets', |
|
| 409 | - ) |
|
| 410 | - ), |
|
| 411 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 412 | - 'require_nonce' => false, |
|
| 413 | - ), |
|
| 414 | - //template settings |
|
| 415 | - 'template_settings' => array( |
|
| 416 | - 'nav' => array( |
|
| 417 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 418 | - 'order' => 30, |
|
| 419 | - ), |
|
| 420 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 421 | - 'help_tabs' => array( |
|
| 422 | - 'general_settings_templates_help_tab' => array( |
|
| 423 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 424 | - 'filename' => 'general_settings_templates', |
|
| 425 | - ), |
|
| 426 | - ), |
|
| 427 | - 'help_tour' => array('Templates_Help_Tour'), |
|
| 428 | - 'require_nonce' => false, |
|
| 429 | - ), |
|
| 430 | - //event category stuff |
|
| 431 | - 'add_category' => array( |
|
| 432 | - 'nav' => array( |
|
| 433 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 434 | - 'order' => 15, |
|
| 435 | - 'persistent' => false, |
|
| 436 | - ), |
|
| 437 | - 'help_tabs' => array( |
|
| 438 | - 'add_category_help_tab' => array( |
|
| 439 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 440 | - 'filename' => 'events_add_category', |
|
| 441 | - ), |
|
| 442 | - ), |
|
| 443 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 444 | - 'metaboxes' => array('_publish_post_box'), |
|
| 445 | - 'require_nonce' => false, |
|
| 446 | - ), |
|
| 447 | - 'edit_category' => array( |
|
| 448 | - 'nav' => array( |
|
| 449 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 450 | - 'order' => 15, |
|
| 451 | - 'persistent' => false, |
|
| 452 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 453 | - ? add_query_arg( |
|
| 454 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 455 | - $this->_current_page_view_url |
|
| 456 | - ) |
|
| 457 | - : $this->_admin_base_url, |
|
| 458 | - ), |
|
| 459 | - 'help_tabs' => array( |
|
| 460 | - 'edit_category_help_tab' => array( |
|
| 461 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 462 | - 'filename' => 'events_edit_category', |
|
| 463 | - ), |
|
| 464 | - ), |
|
| 465 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 466 | - 'metaboxes' => array('_publish_post_box'), |
|
| 467 | - 'require_nonce' => false, |
|
| 468 | - ), |
|
| 469 | - 'category_list' => array( |
|
| 470 | - 'nav' => array( |
|
| 471 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 472 | - 'order' => 20, |
|
| 473 | - ), |
|
| 474 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 475 | - 'help_tabs' => array( |
|
| 476 | - 'events_categories_help_tab' => array( |
|
| 477 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 478 | - 'filename' => 'events_categories', |
|
| 479 | - ), |
|
| 480 | - 'events_categories_table_column_headings_help_tab' => array( |
|
| 481 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 482 | - 'filename' => 'events_categories_table_column_headings', |
|
| 483 | - ), |
|
| 484 | - 'events_categories_view_help_tab' => array( |
|
| 485 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 486 | - 'filename' => 'events_categories_views', |
|
| 487 | - ), |
|
| 488 | - 'events_categories_other_help_tab' => array( |
|
| 489 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 490 | - 'filename' => 'events_categories_other', |
|
| 491 | - ), |
|
| 492 | - ), |
|
| 493 | - 'help_tour' => array( |
|
| 494 | - 'Event_Categories_Help_Tour', |
|
| 495 | - ), |
|
| 496 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 497 | - 'require_nonce' => false, |
|
| 498 | - ), |
|
| 499 | - ); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - protected function _add_screen_options() |
|
| 505 | - { |
|
| 506 | - //todo |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - protected function _add_screen_options_default() |
|
| 512 | - { |
|
| 513 | - $this->_per_page_screen_option(); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - protected function _add_screen_options_category_list() |
|
| 519 | - { |
|
| 520 | - $page_title = $this->_admin_page_title; |
|
| 521 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 522 | - $this->_per_page_screen_option(); |
|
| 523 | - $this->_admin_page_title = $page_title; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - protected function _add_feature_pointers() |
|
| 529 | - { |
|
| 530 | - //todo |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - public function load_scripts_styles() |
|
| 536 | - { |
|
| 537 | - wp_register_style( |
|
| 538 | - 'events-admin-css', |
|
| 539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 540 | - array(), |
|
| 541 | - EVENT_ESPRESSO_VERSION |
|
| 542 | - ); |
|
| 543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | - wp_enqueue_style('events-admin-css'); |
|
| 545 | - wp_enqueue_style('ee-cat-admin'); |
|
| 546 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 547 | - //registers for all views |
|
| 548 | - //scripts |
|
| 549 | - wp_register_script( |
|
| 550 | - 'event_editor_js', |
|
| 551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 552 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 553 | - EVENT_ESPRESSO_VERSION, |
|
| 554 | - true |
|
| 555 | - ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueuing scripts and styles specific to this view |
|
| 562 | - * |
|
| 563 | - * @return void |
|
| 564 | - */ |
|
| 565 | - public function load_scripts_styles_create_new() |
|
| 566 | - { |
|
| 567 | - $this->load_scripts_styles_edit(); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * enqueuing scripts and styles specific to this view |
|
| 574 | - * |
|
| 575 | - * @return void |
|
| 576 | - */ |
|
| 577 | - public function load_scripts_styles_edit() |
|
| 578 | - { |
|
| 579 | - //styles |
|
| 580 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 581 | - wp_register_style( |
|
| 582 | - 'event-editor-css', |
|
| 583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 584 | - array('ee-admin-css'), |
|
| 585 | - EVENT_ESPRESSO_VERSION |
|
| 586 | - ); |
|
| 587 | - wp_enqueue_style('event-editor-css'); |
|
| 588 | - //scripts |
|
| 589 | - wp_register_script( |
|
| 590 | - 'event-datetime-metabox', |
|
| 591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 592 | - array('event_editor_js', 'ee-datepicker'), |
|
| 593 | - EVENT_ESPRESSO_VERSION |
|
| 594 | - ); |
|
| 595 | - wp_enqueue_script('event-datetime-metabox'); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - |
|
| 600 | - public function load_scripts_styles_add_category() |
|
| 601 | - { |
|
| 602 | - $this->load_scripts_styles_edit_category(); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - public function load_scripts_styles_edit_category() |
|
| 608 | - { |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - protected function _set_list_table_views_category_list() |
|
| 614 | - { |
|
| 615 | - $this->_views = array( |
|
| 616 | - 'all' => array( |
|
| 617 | - 'slug' => 'all', |
|
| 618 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 619 | - 'count' => 0, |
|
| 620 | - 'bulk_action' => array( |
|
| 621 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 622 | - ), |
|
| 623 | - ), |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - public function admin_init() |
|
| 630 | - { |
|
| 631 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 632 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 633 | - 'event_espresso' |
|
| 634 | - ); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - //nothing needed for events with these methods. |
|
| 640 | - public function admin_notices() |
|
| 641 | - { |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - public function admin_footer_scripts() |
|
| 647 | - { |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 654 | - * warning (via EE_Error::add_error()); |
|
| 655 | - * |
|
| 656 | - * @param EE_Event $event Event object |
|
| 657 | - * @access public |
|
| 658 | - * @return void |
|
| 659 | - */ |
|
| 660 | - public function verify_event_edit($event = null) |
|
| 661 | - { |
|
| 662 | - // no event? |
|
| 663 | - if (empty($event)) { |
|
| 664 | - // set event |
|
| 665 | - $event = $this->_cpt_model_obj; |
|
| 666 | - } |
|
| 667 | - // STILL no event? |
|
| 668 | - if (! $event instanceof EE_Event) { |
|
| 669 | - return; |
|
| 670 | - } |
|
| 671 | - $orig_status = $event->status(); |
|
| 672 | - // first check if event is active. |
|
| 673 | - if ( |
|
| 674 | - $orig_status === EEM_Event::cancelled |
|
| 675 | - || $orig_status === EEM_Event::postponed |
|
| 676 | - || $event->is_expired() |
|
| 677 | - || $event->is_inactive() |
|
| 678 | - ) { |
|
| 679 | - return; |
|
| 680 | - } |
|
| 681 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
| 682 | - if ($event->is_sold_out(true)) { |
|
| 683 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 684 | - EE_Error::add_attention( |
|
| 685 | - sprintf( |
|
| 686 | - esc_html__( |
|
| 687 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 688 | - 'event_espresso' |
|
| 689 | - ), |
|
| 690 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - } |
|
| 694 | - return; |
|
| 695 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
| 696 | - EE_Error::add_attention( |
|
| 697 | - sprintf( |
|
| 698 | - esc_html__( |
|
| 699 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 700 | - 'event_espresso' |
|
| 701 | - ), |
|
| 702 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 703 | - ) |
|
| 704 | - ); |
|
| 705 | - } |
|
| 706 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 707 | - if ( ! $event->tickets_on_sale()) { |
|
| 708 | - return; |
|
| 709 | - } |
|
| 710 | - //made it here so show warning |
|
| 711 | - $this->_edit_event_warning(); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 718 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
| 719 | - * |
|
| 720 | - * @access protected |
|
| 721 | - * @return void |
|
| 722 | - */ |
|
| 723 | - protected function _edit_event_warning() |
|
| 724 | - { |
|
| 725 | - // we don't want to add warnings during these requests |
|
| 726 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 727 | - return; |
|
| 728 | - } |
|
| 729 | - EE_Error::add_attention( |
|
| 730 | - esc_html__( |
|
| 731 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 732 | - 'event_espresso' |
|
| 733 | - ) |
|
| 734 | - ); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - /** |
|
| 740 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 741 | - * Otherwise, do the normal logic |
|
| 742 | - * |
|
| 743 | - * @return string |
|
| 744 | - * @throws \EE_Error |
|
| 745 | - */ |
|
| 746 | - protected function _create_new_cpt_item() |
|
| 747 | - { |
|
| 748 | - $gmt_offset = get_option('gmt_offset'); |
|
| 749 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 750 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 751 | - EE_Error::add_attention( |
|
| 752 | - sprintf( |
|
| 753 | - __( |
|
| 754 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 755 | - 'event_espresso' |
|
| 756 | - ), |
|
| 757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 758 | - '</a>' |
|
| 759 | - ), |
|
| 760 | - __FILE__, |
|
| 761 | - __FUNCTION__, |
|
| 762 | - __LINE__ |
|
| 763 | - ); |
|
| 764 | - } |
|
| 765 | - return parent::_create_new_cpt_item(); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - protected function _set_list_table_views_default() |
|
| 771 | - { |
|
| 772 | - $this->_views = array( |
|
| 773 | - 'all' => array( |
|
| 774 | - 'slug' => 'all', |
|
| 775 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 776 | - 'count' => 0, |
|
| 777 | - 'bulk_action' => array( |
|
| 778 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 779 | - ), |
|
| 780 | - ), |
|
| 781 | - 'draft' => array( |
|
| 782 | - 'slug' => 'draft', |
|
| 783 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 784 | - 'count' => 0, |
|
| 785 | - 'bulk_action' => array( |
|
| 786 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 787 | - ), |
|
| 788 | - ), |
|
| 789 | - ); |
|
| 790 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 791 | - $this->_views['trash'] = array( |
|
| 792 | - 'slug' => 'trash', |
|
| 793 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 794 | - 'count' => 0, |
|
| 795 | - 'bulk_action' => array( |
|
| 796 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 797 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 798 | - ), |
|
| 799 | - ); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * @return array |
|
| 807 | - */ |
|
| 808 | - protected function _event_legend_items() |
|
| 809 | - { |
|
| 810 | - $items = array( |
|
| 811 | - 'view_details' => array( |
|
| 812 | - 'class' => 'dashicons dashicons-search', |
|
| 813 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 814 | - ), |
|
| 815 | - 'edit_event' => array( |
|
| 816 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 817 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 818 | - ), |
|
| 819 | - 'view_attendees' => array( |
|
| 820 | - 'class' => 'dashicons dashicons-groups', |
|
| 821 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 822 | - ), |
|
| 823 | - ); |
|
| 824 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 825 | - $statuses = array( |
|
| 826 | - 'sold_out_status' => array( |
|
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 828 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 829 | - ), |
|
| 830 | - 'active_status' => array( |
|
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 832 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 833 | - ), |
|
| 834 | - 'upcoming_status' => array( |
|
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 836 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 837 | - ), |
|
| 838 | - 'postponed_status' => array( |
|
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 840 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 841 | - ), |
|
| 842 | - 'cancelled_status' => array( |
|
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 844 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 845 | - ), |
|
| 846 | - 'expired_status' => array( |
|
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 848 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 849 | - ), |
|
| 850 | - 'inactive_status' => array( |
|
| 851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 852 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 853 | - ), |
|
| 854 | - ); |
|
| 855 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 856 | - return array_merge($items, $statuses); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * _event_model |
|
| 863 | - * |
|
| 864 | - * @return EEM_Event |
|
| 865 | - */ |
|
| 866 | - private function _event_model() |
|
| 867 | - { |
|
| 868 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 869 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 870 | - } |
|
| 871 | - return $this->_event_model; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Adds extra buttons to the WP CPT permalink field row. |
|
| 878 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 879 | - * |
|
| 880 | - * @param string $return the current html |
|
| 881 | - * @param int $id the post id for the page |
|
| 882 | - * @param string $new_title What the title is |
|
| 883 | - * @param string $new_slug what the slug is |
|
| 884 | - * @return string The new html string for the permalink area |
|
| 885 | - */ |
|
| 886 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 887 | - { |
|
| 888 | - //make sure this is only when editing |
|
| 889 | - if ( ! empty($id)) { |
|
| 890 | - $post = get_post($id); |
|
| 891 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 892 | - . esc_html__('Shortcode', 'event_espresso') |
|
| 893 | - . '</a> '; |
|
| 894 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 895 | - . $post->ID |
|
| 896 | - . ']">'; |
|
| 897 | - } |
|
| 898 | - return $return; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * _events_overview_list_table |
|
| 905 | - * This contains the logic for showing the events_overview list |
|
| 906 | - * |
|
| 907 | - * @access protected |
|
| 908 | - * @return void |
|
| 909 | - * @throws \EE_Error |
|
| 910 | - */ |
|
| 911 | - protected function _events_overview_list_table() |
|
| 912 | - { |
|
| 913 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 914 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 915 | - ? (array)$this->_template_args['after_list_table'] |
|
| 916 | - : array(); |
|
| 917 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 918 | - . EEH_Template::get_button_or_link( |
|
| 919 | - get_post_type_archive_link('espresso_events'), |
|
| 920 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
| 921 | - 'button' |
|
| 922 | - ); |
|
| 923 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 925 | - 'create_new', |
|
| 926 | - 'add', |
|
| 927 | - array(), |
|
| 928 | - 'add-new-h2' |
|
| 929 | - ); |
|
| 930 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * this allows for extra misc actions in the default WP publish box |
|
| 937 | - * |
|
| 938 | - * @return void |
|
| 939 | - */ |
|
| 940 | - public function extra_misc_actions_publish_box() |
|
| 941 | - { |
|
| 942 | - $this->_generate_publish_box_extra_content(); |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 949 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 950 | - * data. |
|
| 951 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 952 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 953 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 954 | - * you handle this accordingly. |
|
| 955 | - * |
|
| 956 | - * @access protected |
|
| 957 | - * @abstract |
|
| 958 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 959 | - * @param object $post The post object of the cpt that was saved. |
|
| 960 | - * @return void |
|
| 961 | - */ |
|
| 962 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 963 | - { |
|
| 964 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 965 | - //get out we're not processing an event save. |
|
| 966 | - return; |
|
| 967 | - } |
|
| 968 | - $event_values = array( |
|
| 969 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 970 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 971 | - 'EVT_additional_limit' => min( |
|
| 972 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 973 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 974 | - ), |
|
| 975 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 976 | - ? $this->_req_data['EVT_default_registration_status'] |
|
| 977 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 978 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 979 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 980 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 981 | - ? $this->_req_data['timezone_string'] : null, |
|
| 982 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 983 | - ? $this->_req_data['externalURL'] : null, |
|
| 984 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 985 | - ? $this->_req_data['event_phone'] : null, |
|
| 986 | - ); |
|
| 987 | - //update event |
|
| 988 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 989 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 990 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 991 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 992 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 993 | - $event_update_callbacks = apply_filters( |
|
| 994 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 995 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 996 | - ); |
|
| 997 | - $att_success = true; |
|
| 998 | - foreach ($event_update_callbacks as $e_callback) { |
|
| 999 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 1000 | - $att_success = ! $att_success ? $att_success |
|
| 1001 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 1002 | - } |
|
| 1003 | - //any errors? |
|
| 1004 | - if ($success && false === $att_success) { |
|
| 1005 | - EE_Error::add_error( |
|
| 1006 | - esc_html__( |
|
| 1007 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1008 | - 'event_espresso' |
|
| 1009 | - ), |
|
| 1010 | - __FILE__, |
|
| 1011 | - __FUNCTION__, |
|
| 1012 | - __LINE__ |
|
| 1013 | - ); |
|
| 1014 | - } else if ($success === false) { |
|
| 1015 | - EE_Error::add_error( |
|
| 1016 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1017 | - __FILE__, |
|
| 1018 | - __FUNCTION__, |
|
| 1019 | - __LINE__ |
|
| 1020 | - ); |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * @see parent::restore_item() |
|
| 1028 | - * @param int $post_id |
|
| 1029 | - * @param int $revision_id |
|
| 1030 | - */ |
|
| 1031 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1032 | - { |
|
| 1033 | - //copy existing event meta to new post |
|
| 1034 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1035 | - if ($post_evt instanceof EE_Event) { |
|
| 1036 | - //meta revision restore |
|
| 1037 | - $post_evt->restore_revision($revision_id); |
|
| 1038 | - //related objs restore |
|
| 1039 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * Attach the venue to the Event |
|
| 1047 | - * |
|
| 1048 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1049 | - * @param array $data The request data from the form |
|
| 1050 | - * @return bool Success or fail. |
|
| 1051 | - */ |
|
| 1052 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1053 | - { |
|
| 1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1055 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1056 | - $rows_affected = null; |
|
| 1057 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1058 | - // very important. If we don't have a venue name... |
|
| 1059 | - // then we'll get out because not necessary to create empty venue |
|
| 1060 | - if (empty($data['venue_title'])) { |
|
| 1061 | - return false; |
|
| 1062 | - } |
|
| 1063 | - $venue_array = array( |
|
| 1064 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1065 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1066 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1067 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1068 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1069 | - : null, |
|
| 1070 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1071 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1072 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1073 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1074 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1075 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1076 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1077 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1078 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1079 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1080 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1081 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1082 | - 'status' => 'publish', |
|
| 1083 | - ); |
|
| 1084 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1085 | - if ( ! empty($venue_id)) { |
|
| 1086 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1087 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1088 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1089 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | - return $rows_affected > 0 ? true : false; |
|
| 1091 | - } else { |
|
| 1092 | - //we insert the venue |
|
| 1093 | - $venue_id = $venue_model->insert($venue_array); |
|
| 1094 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1095 | - return ! empty($venue_id) ? true : false; |
|
| 1096 | - } |
|
| 1097 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1104 | - * |
|
| 1105 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1106 | - * @param array $data The request data from the form |
|
| 1107 | - * @return array |
|
| 1108 | - */ |
|
| 1109 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1110 | - { |
|
| 1111 | - $success = true; |
|
| 1112 | - $saved_dtt = null; |
|
| 1113 | - $saved_tickets = array(); |
|
| 1114 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1115 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1116 | - //trim all values to ensure any excess whitespace is removed. |
|
| 1117 | - $dtt = array_map('trim', $dtt); |
|
| 1118 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1119 | - : $dtt['DTT_EVT_start']; |
|
| 1120 | - $datetime_values = array( |
|
| 1121 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1122 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1123 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1124 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1125 | - 'DTT_order' => $row, |
|
| 1126 | - ); |
|
| 1127 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1128 | - if ( ! empty($dtt['DTT_ID'])) { |
|
| 1129 | - $DTM = EE_Registry::instance() |
|
| 1130 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1131 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1132 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1133 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1134 | - foreach ($datetime_values as $field => $value) { |
|
| 1135 | - $DTM->set($field, $value); |
|
| 1136 | - } |
|
| 1137 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1138 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1139 | - } else { |
|
| 1140 | - $DTM = EE_Registry::instance()->load_class( |
|
| 1141 | - 'Datetime', |
|
| 1142 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1143 | - false, |
|
| 1144 | - false |
|
| 1145 | - ); |
|
| 1146 | - foreach ($datetime_values as $field => $value) { |
|
| 1147 | - $DTM->set($field, $value); |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - $DTM->save(); |
|
| 1151 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1152 | - //load DTT helper |
|
| 1153 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1154 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1155 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1156 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1157 | - $DTT->save(); |
|
| 1158 | - } |
|
| 1159 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1160 | - $saved_dtt = $DTT; |
|
| 1161 | - $success = ! $success ? $success : $DTT; |
|
| 1162 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1163 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1164 | - } |
|
| 1165 | - //no dtts get deleted so we don't do any of that logic here. |
|
| 1166 | - //update tickets next |
|
| 1167 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1168 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1169 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | - $update_prices = false; |
|
| 1171 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1172 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1173 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 1174 | - $tkt = array_map('trim', $tkt); |
|
| 1175 | - if (empty($tkt['TKT_start_date'])) { |
|
| 1176 | - //let's use now in the set timezone. |
|
| 1177 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1179 | - } |
|
| 1180 | - if (empty($tkt['TKT_end_date'])) { |
|
| 1181 | - //use the start date of the first datetime |
|
| 1182 | - $dtt = $evtobj->first_datetime(); |
|
| 1183 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1184 | - $incoming_date_formats[0], |
|
| 1185 | - $incoming_date_formats[1] |
|
| 1186 | - ); |
|
| 1187 | - } |
|
| 1188 | - $TKT_values = array( |
|
| 1189 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1190 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1191 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1192 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1193 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1194 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1195 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1196 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1197 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1198 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1199 | - 'TKT_row' => $row, |
|
| 1200 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1201 | - 'TKT_price' => $ticket_price, |
|
| 1202 | - ); |
|
| 1203 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1204 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1205 | - $TKT_values['TKT_ID'] = 0; |
|
| 1206 | - $TKT_values['TKT_is_default'] = 0; |
|
| 1207 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1208 | - $update_prices = true; |
|
| 1209 | - } |
|
| 1210 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1211 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1212 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1213 | - if ( ! empty($tkt['TKT_ID'])) { |
|
| 1214 | - $TKT = EE_Registry::instance() |
|
| 1215 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1216 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1217 | - if ($TKT instanceof EE_Ticket) { |
|
| 1218 | - $ticket_sold = $TKT->count_related( |
|
| 1219 | - 'Registration', |
|
| 1220 | - array( |
|
| 1221 | - array( |
|
| 1222 | - 'STS_ID' => array( |
|
| 1223 | - 'NOT IN', |
|
| 1224 | - array(EEM_Registration::status_id_incomplete), |
|
| 1225 | - ), |
|
| 1226 | - ), |
|
| 1227 | - ) |
|
| 1228 | - ) > 0 ? true : false; |
|
| 1229 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1230 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1231 | - && ! $TKT->get( |
|
| 1232 | - 'TKT_deleted' |
|
| 1233 | - ) ? true : false; |
|
| 1234 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1235 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1236 | - //set new values |
|
| 1237 | - foreach ($TKT_values as $field => $value) { |
|
| 1238 | - if ($field == 'TKT_qty') { |
|
| 1239 | - $TKT->set_qty($value); |
|
| 1240 | - } else { |
|
| 1241 | - $TKT->set($field, $value); |
|
| 1242 | - } |
|
| 1243 | - } |
|
| 1244 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1245 | - if ($create_new_TKT) { |
|
| 1246 | - //archive the old ticket first |
|
| 1247 | - $TKT->set('TKT_deleted', 1); |
|
| 1248 | - $TKT->save(); |
|
| 1249 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1250 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1251 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1252 | - $TKT = clone $TKT; |
|
| 1253 | - $TKT->set('TKT_ID', 0); |
|
| 1254 | - $TKT->set('TKT_deleted', 0); |
|
| 1255 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1256 | - $TKT->set('TKT_sold', 0); |
|
| 1257 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1258 | - $update_prices = true; |
|
| 1259 | - } |
|
| 1260 | - //make sure price is set if it hasn't been already |
|
| 1261 | - $TKT->set('TKT_price', $ticket_price); |
|
| 1262 | - } |
|
| 1263 | - } else { |
|
| 1264 | - //no TKT_id so a new TKT |
|
| 1265 | - $TKT_values['TKT_price'] = $ticket_price; |
|
| 1266 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1267 | - if ($TKT instanceof EE_Ticket) { |
|
| 1268 | - //need to reset values to properly account for the date formats |
|
| 1269 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1270 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1271 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1272 | - //set new values |
|
| 1273 | - foreach ($TKT_values as $field => $value) { |
|
| 1274 | - if ($field == 'TKT_qty') { |
|
| 1275 | - $TKT->set_qty($value); |
|
| 1276 | - } else { |
|
| 1277 | - $TKT->set($field, $value); |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - $update_prices = true; |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - // cap ticket qty by datetime reg limits |
|
| 1284 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1285 | - //update ticket. |
|
| 1286 | - $TKT->save(); |
|
| 1287 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1288 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1289 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1290 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1291 | - $TKT->save(); |
|
| 1292 | - } |
|
| 1293 | - //initially let's add the ticket to the dtt |
|
| 1294 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1295 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1296 | - //add prices to ticket |
|
| 1297 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1298 | - } |
|
| 1299 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1300 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1301 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1302 | - foreach ($tickets_removed as $id) { |
|
| 1303 | - $id = absint($id); |
|
| 1304 | - //get the ticket for this id |
|
| 1305 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1306 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1307 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1308 | - foreach ($dtts as $dtt) { |
|
| 1309 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1310 | - } |
|
| 1311 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1312 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1313 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1314 | - $tkt_to_remove->delete_permanently(); |
|
| 1315 | - } |
|
| 1316 | - return array($saved_dtt, $saved_tickets); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * This attaches a list of given prices to a ticket. |
|
| 1323 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1324 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1325 | - * price info and prices are automatically "archived" via the ticket. |
|
| 1326 | - * |
|
| 1327 | - * @access private |
|
| 1328 | - * @param array $prices Array of prices from the form. |
|
| 1329 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1330 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1331 | - * @return void |
|
| 1332 | - */ |
|
| 1333 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1334 | - { |
|
| 1335 | - foreach ($prices as $row => $prc) { |
|
| 1336 | - $PRC_values = array( |
|
| 1337 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1338 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1339 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1340 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1341 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1342 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1343 | - 'PRC_order' => $row, |
|
| 1344 | - ); |
|
| 1345 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1346 | - $PRC_values['PRC_ID'] = 0; |
|
| 1347 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1348 | - } else { |
|
| 1349 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1350 | - //update this price with new values |
|
| 1351 | - foreach ($PRC_values as $field => $newprc) { |
|
| 1352 | - $PRC->set($field, $newprc); |
|
| 1353 | - } |
|
| 1354 | - $PRC->save(); |
|
| 1355 | - } |
|
| 1356 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Add in our autosave ajax handlers |
|
| 1364 | - * |
|
| 1365 | - * @return void |
|
| 1366 | - */ |
|
| 1367 | - protected function _ee_autosave_create_new() |
|
| 1368 | - { |
|
| 1369 | - // $this->_ee_autosave_edit(); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - protected function _ee_autosave_edit() |
|
| 1375 | - { |
|
| 1376 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * _generate_publish_box_extra_content |
|
| 1383 | - * |
|
| 1384 | - * @access private |
|
| 1385 | - * @return void |
|
| 1386 | - */ |
|
| 1387 | - private function _generate_publish_box_extra_content() |
|
| 1388 | - { |
|
| 1389 | - //load formatter helper |
|
| 1390 | - //args for getting related registrations |
|
| 1391 | - $approved_query_args = array( |
|
| 1392 | - array( |
|
| 1393 | - 'REG_deleted' => 0, |
|
| 1394 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1395 | - ), |
|
| 1396 | - ); |
|
| 1397 | - $not_approved_query_args = array( |
|
| 1398 | - array( |
|
| 1399 | - 'REG_deleted' => 0, |
|
| 1400 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1401 | - ), |
|
| 1402 | - ); |
|
| 1403 | - $pending_payment_query_args = array( |
|
| 1404 | - array( |
|
| 1405 | - 'REG_deleted' => 0, |
|
| 1406 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1407 | - ), |
|
| 1408 | - ); |
|
| 1409 | - // publish box |
|
| 1410 | - $publish_box_extra_args = array( |
|
| 1411 | - 'view_approved_reg_url' => add_query_arg( |
|
| 1412 | - array( |
|
| 1413 | - 'action' => 'default', |
|
| 1414 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1415 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1416 | - ), |
|
| 1417 | - REG_ADMIN_URL |
|
| 1418 | - ), |
|
| 1419 | - 'view_not_approved_reg_url' => add_query_arg( |
|
| 1420 | - array( |
|
| 1421 | - 'action' => 'default', |
|
| 1422 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1423 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1424 | - ), |
|
| 1425 | - REG_ADMIN_URL |
|
| 1426 | - ), |
|
| 1427 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1428 | - array( |
|
| 1429 | - 'action' => 'default', |
|
| 1430 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1431 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1432 | - ), |
|
| 1433 | - REG_ADMIN_URL |
|
| 1434 | - ), |
|
| 1435 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | - 'Registration', |
|
| 1437 | - $approved_query_args |
|
| 1438 | - ), |
|
| 1439 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | - 'Registration', |
|
| 1441 | - $not_approved_query_args |
|
| 1442 | - ), |
|
| 1443 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1444 | - 'Registration', |
|
| 1445 | - $pending_payment_query_args |
|
| 1446 | - ), |
|
| 1447 | - 'misc_pub_section_class' => apply_filters( |
|
| 1448 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1449 | - 'misc-pub-section' |
|
| 1450 | - ), |
|
| 1451 | - //'email_attendees_url' => add_query_arg( |
|
| 1452 | - // array( |
|
| 1453 | - // 'event_admin_reports' => 'event_newsletter', |
|
| 1454 | - // 'event_id' => $this->_cpt_model_obj->id |
|
| 1455 | - // ), |
|
| 1456 | - // 'admin.php?page=espresso_registrations' |
|
| 1457 | - //), |
|
| 1458 | - ); |
|
| 1459 | - ob_start(); |
|
| 1460 | - do_action( |
|
| 1461 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1462 | - $this->_cpt_model_obj |
|
| 1463 | - ); |
|
| 1464 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1465 | - // load template |
|
| 1466 | - EEH_Template::display_template( |
|
| 1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1468 | - $publish_box_extra_args |
|
| 1469 | - ); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - |
|
| 1474 | - /** |
|
| 1475 | - * This just returns whatever is set as the _event object property |
|
| 1476 | - * //todo this will become obsolete once the models are in place |
|
| 1477 | - * |
|
| 1478 | - * @return object |
|
| 1479 | - */ |
|
| 1480 | - public function get_event_object() |
|
| 1481 | - { |
|
| 1482 | - return $this->_cpt_model_obj; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - |
|
| 1486 | - |
|
| 1487 | - |
|
| 1488 | - /** METABOXES * */ |
|
| 1489 | - /** |
|
| 1490 | - * _register_event_editor_meta_boxes |
|
| 1491 | - * add all metaboxes related to the event_editor |
|
| 1492 | - * |
|
| 1493 | - * @return void |
|
| 1494 | - */ |
|
| 1495 | - protected function _register_event_editor_meta_boxes() |
|
| 1496 | - { |
|
| 1497 | - $this->verify_cpt_object(); |
|
| 1498 | - add_meta_box( |
|
| 1499 | - 'espresso_event_editor_tickets', |
|
| 1500 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1501 | - array($this, 'ticket_metabox'), |
|
| 1502 | - $this->page_slug, |
|
| 1503 | - 'normal', |
|
| 1504 | - 'high' |
|
| 1505 | - ); |
|
| 1506 | - add_meta_box( |
|
| 1507 | - 'espresso_event_editor_event_options', |
|
| 1508 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1509 | - array($this, 'registration_options_meta_box'), |
|
| 1510 | - $this->page_slug, |
|
| 1511 | - 'side', |
|
| 1512 | - 'default' |
|
| 1513 | - ); |
|
| 1514 | - // NOTE: if you're looking for other metaboxes in here, |
|
| 1515 | - // where a metabox has a related management page in the admin |
|
| 1516 | - // you will find it setup in the related management page's "_Hooks" file. |
|
| 1517 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - |
|
| 1521 | - |
|
| 1522 | - public function ticket_metabox() |
|
| 1523 | - { |
|
| 1524 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1525 | - //defaults for template args |
|
| 1526 | - $template_args = array( |
|
| 1527 | - 'existing_datetime_ids' => '', |
|
| 1528 | - 'event_datetime_help_link' => '', |
|
| 1529 | - 'ticket_options_help_link' => '', |
|
| 1530 | - 'time' => null, |
|
| 1531 | - 'ticket_rows' => '', |
|
| 1532 | - 'existing_ticket_ids' => '', |
|
| 1533 | - 'total_ticket_rows' => 1, |
|
| 1534 | - 'ticket_js_structure' => '', |
|
| 1535 | - 'trash_icon' => 'ee-lock-icon', |
|
| 1536 | - 'disabled' => '', |
|
| 1537 | - ); |
|
| 1538 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1539 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1540 | - /** |
|
| 1541 | - * 1. Start with retrieving Datetimes |
|
| 1542 | - * 2. Fore each datetime get related tickets |
|
| 1543 | - * 3. For each ticket get related prices |
|
| 1544 | - */ |
|
| 1545 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1546 | - /** @type EE_Datetime $first_datetime */ |
|
| 1547 | - $first_datetime = reset($times); |
|
| 1548 | - //do we get related tickets? |
|
| 1549 | - if ($first_datetime instanceof EE_Datetime |
|
| 1550 | - && $first_datetime->ID() !== 0 |
|
| 1551 | - ) { |
|
| 1552 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1553 | - $template_args['time'] = $first_datetime; |
|
| 1554 | - $related_tickets = $first_datetime->tickets( |
|
| 1555 | - array( |
|
| 1556 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1557 | - 'default_where_conditions' => 'none', |
|
| 1558 | - ) |
|
| 1559 | - ); |
|
| 1560 | - if ( ! empty($related_tickets)) { |
|
| 1561 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1562 | - $row = 0; |
|
| 1563 | - foreach ($related_tickets as $ticket) { |
|
| 1564 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1565 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1566 | - $row++; |
|
| 1567 | - } |
|
| 1568 | - } else { |
|
| 1569 | - $template_args['total_ticket_rows'] = 1; |
|
| 1570 | - /** @type EE_Ticket $ticket */ |
|
| 1571 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1572 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1573 | - } |
|
| 1574 | - } else { |
|
| 1575 | - $template_args['time'] = $times[0]; |
|
| 1576 | - /** @type EE_Ticket $ticket */ |
|
| 1577 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1578 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1579 | - // NOTE: we're just sending the first default row |
|
| 1580 | - // (decaf can't manage default tickets so this should be sufficient); |
|
| 1581 | - } |
|
| 1582 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1583 | - 'event_editor_event_datetimes_help_tab' |
|
| 1584 | - ); |
|
| 1585 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1586 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1587 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1588 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1589 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1590 | - true |
|
| 1591 | - ); |
|
| 1592 | - $template = apply_filters( |
|
| 1593 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1595 | - ); |
|
| 1596 | - EEH_Template::display_template($template, $template_args); |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - |
|
| 1600 | - |
|
| 1601 | - /** |
|
| 1602 | - * Setup an individual ticket form for the decaf event editor page |
|
| 1603 | - * |
|
| 1604 | - * @access private |
|
| 1605 | - * @param EE_Ticket $ticket the ticket object |
|
| 1606 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1607 | - * @param int $row |
|
| 1608 | - * @return string generated html for the ticket row. |
|
| 1609 | - */ |
|
| 1610 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1611 | - { |
|
| 1612 | - $template_args = array( |
|
| 1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1614 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1615 | - : '', |
|
| 1616 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1617 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1618 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1619 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1620 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1621 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1622 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1623 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1624 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1625 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1626 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1627 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1628 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1629 | - : ' disabled=disabled', |
|
| 1630 | - ); |
|
| 1631 | - $price = $ticket->ID() !== 0 |
|
| 1632 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1633 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1634 | - $price_args = array( |
|
| 1635 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1636 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1637 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1638 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1639 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1640 | - ); |
|
| 1641 | - //make sure we have default start and end dates if skeleton |
|
| 1642 | - //handle rows that should NOT be empty |
|
| 1643 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1644 | - //if empty then the start date will be now. |
|
| 1645 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1646 | - } |
|
| 1647 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1648 | - //get the earliest datetime (if present); |
|
| 1649 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1650 | - ? $this->_cpt_model_obj->get_first_related( |
|
| 1651 | - 'Datetime', |
|
| 1652 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1653 | - ) |
|
| 1654 | - : null; |
|
| 1655 | - if ( ! empty($earliest_dtt)) { |
|
| 1656 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1657 | - } else { |
|
| 1658 | - $template_args['TKT_end_date'] = date( |
|
| 1659 | - 'Y-m-d h:i a', |
|
| 1660 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1661 | - ); |
|
| 1662 | - } |
|
| 1663 | - } |
|
| 1664 | - $template_args = array_merge($template_args, $price_args); |
|
| 1665 | - $template = apply_filters( |
|
| 1666 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | - $ticket |
|
| 1669 | - ); |
|
| 1670 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - |
|
| 1674 | - |
|
| 1675 | - public function registration_options_meta_box() |
|
| 1676 | - { |
|
| 1677 | - $yes_no_values = array( |
|
| 1678 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1679 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1680 | - ); |
|
| 1681 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1682 | - array( |
|
| 1683 | - EEM_Registration::status_id_cancelled, |
|
| 1684 | - EEM_Registration::status_id_declined, |
|
| 1685 | - EEM_Registration::status_id_incomplete, |
|
| 1686 | - ), |
|
| 1687 | - true |
|
| 1688 | - ); |
|
| 1689 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1690 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1691 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1692 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1693 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1694 | - 'default_reg_status', |
|
| 1695 | - $default_reg_status_values, |
|
| 1696 | - $this->_cpt_model_obj->default_registration_status() |
|
| 1697 | - ); |
|
| 1698 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1699 | - 'display_desc', |
|
| 1700 | - $yes_no_values, |
|
| 1701 | - $this->_cpt_model_obj->display_description() |
|
| 1702 | - ); |
|
| 1703 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1704 | - 'display_ticket_selector', |
|
| 1705 | - $yes_no_values, |
|
| 1706 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1707 | - '', |
|
| 1708 | - '', |
|
| 1709 | - false |
|
| 1710 | - ); |
|
| 1711 | - $template_args['additional_registration_options'] = apply_filters( |
|
| 1712 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1713 | - '', |
|
| 1714 | - $template_args, |
|
| 1715 | - $yes_no_values, |
|
| 1716 | - $default_reg_status_values |
|
| 1717 | - ); |
|
| 1718 | - EEH_Template::display_template( |
|
| 1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1720 | - $template_args |
|
| 1721 | - ); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - |
|
| 1725 | - |
|
| 1726 | - /** |
|
| 1727 | - * _get_events() |
|
| 1728 | - * This method simply returns all the events (for the given _view and paging) |
|
| 1729 | - * |
|
| 1730 | - * @access public |
|
| 1731 | - * @param int $per_page count of items per page (20 default); |
|
| 1732 | - * @param int $current_page what is the current page being viewed. |
|
| 1733 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1734 | - * If FALSE then we return an array of event objects |
|
| 1735 | - * that match the given _view and paging parameters. |
|
| 1736 | - * @return array an array of event objects. |
|
| 1737 | - */ |
|
| 1738 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1739 | - { |
|
| 1740 | - $EEME = $this->_event_model(); |
|
| 1741 | - $offset = ($current_page - 1) * $per_page; |
|
| 1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1743 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1744 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1745 | - if (isset($this->_req_data['month_range'])) { |
|
| 1746 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1747 | - //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1748 | - //where PHP doesn't know what to assume for date. |
|
| 1749 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1750 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1751 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1752 | - } |
|
| 1753 | - $where = array(); |
|
| 1754 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1755 | - //determine what post_status our condition will have for the query. |
|
| 1756 | - switch ($status) { |
|
| 1757 | - case 'month' : |
|
| 1758 | - case 'today' : |
|
| 1759 | - case null : |
|
| 1760 | - case 'all' : |
|
| 1761 | - break; |
|
| 1762 | - case 'draft' : |
|
| 1763 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1764 | - break; |
|
| 1765 | - default : |
|
| 1766 | - $where['status'] = $status; |
|
| 1767 | - } |
|
| 1768 | - //categories? |
|
| 1769 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1770 | - ? $this->_req_data['EVT_CAT'] : null; |
|
| 1771 | - if ( ! empty ($category)) { |
|
| 1772 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1773 | - $where['Term_Taxonomy.term_id'] = $category; |
|
| 1774 | - } |
|
| 1775 | - //date where conditions |
|
| 1776 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1777 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1778 | - $DateTime = new DateTime( |
|
| 1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1780 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1781 | - ); |
|
| 1782 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1783 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1784 | - ->format('t'))->setTime(23, 59, 59) |
|
| 1785 | - ->format(implode(' ', $start_formats)); |
|
| 1786 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1787 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1788 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1789 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1790 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1791 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1793 | - $now = date('Y-m-01'); |
|
| 1794 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1795 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1796 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1797 | - ->setTime(23, 59, 59) |
|
| 1798 | - ->format(implode(' ', $start_formats)); |
|
| 1799 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1800 | - } |
|
| 1801 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1802 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1803 | - } else { |
|
| 1804 | - if ( ! isset($where['status'])) { |
|
| 1805 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1806 | - $where['OR'] = array( |
|
| 1807 | - 'status*restrict_private' => array('!=', 'private'), |
|
| 1808 | - 'AND' => array( |
|
| 1809 | - 'status*inclusive' => array('=', 'private'), |
|
| 1810 | - 'EVT_wp_user' => get_current_user_id(), |
|
| 1811 | - ), |
|
| 1812 | - ); |
|
| 1813 | - } |
|
| 1814 | - } |
|
| 1815 | - } |
|
| 1816 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1817 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1818 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1819 | - ) { |
|
| 1820 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1821 | - } |
|
| 1822 | - } |
|
| 1823 | - //search query handling |
|
| 1824 | - if (isset($this->_req_data['s'])) { |
|
| 1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1826 | - $where['OR'] = array( |
|
| 1827 | - 'EVT_name' => array('LIKE', $search_string), |
|
| 1828 | - 'EVT_desc' => array('LIKE', $search_string), |
|
| 1829 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1830 | - ); |
|
| 1831 | - } |
|
| 1832 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1833 | - $query_params = apply_filters( |
|
| 1834 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1835 | - array( |
|
| 1836 | - $where, |
|
| 1837 | - 'limit' => $limit, |
|
| 1838 | - 'order_by' => $orderby, |
|
| 1839 | - 'order' => $order, |
|
| 1840 | - 'group_by' => 'EVT_ID', |
|
| 1841 | - ), |
|
| 1842 | - $this->_req_data |
|
| 1843 | - ); |
|
| 1844 | - //let's first check if we have special requests coming in. |
|
| 1845 | - if (isset($this->_req_data['active_status'])) { |
|
| 1846 | - switch ($this->_req_data['active_status']) { |
|
| 1847 | - case 'upcoming' : |
|
| 1848 | - return $EEME->get_upcoming_events($query_params, $count); |
|
| 1849 | - break; |
|
| 1850 | - case 'expired' : |
|
| 1851 | - return $EEME->get_expired_events($query_params, $count); |
|
| 1852 | - break; |
|
| 1853 | - case 'active' : |
|
| 1854 | - return $EEME->get_active_events($query_params, $count); |
|
| 1855 | - break; |
|
| 1856 | - case 'inactive' : |
|
| 1857 | - return $EEME->get_inactive_events($query_params, $count); |
|
| 1858 | - break; |
|
| 1859 | - } |
|
| 1860 | - } |
|
| 1861 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1862 | - return $events; |
|
| 1863 | - } |
|
| 1864 | - |
|
| 1865 | - |
|
| 1866 | - |
|
| 1867 | - /** |
|
| 1868 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1869 | - * |
|
| 1870 | - * @param string $post_id |
|
| 1871 | - */ |
|
| 1872 | - public function trash_cpt_item($post_id) |
|
| 1873 | - { |
|
| 1874 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1875 | - $this->_trash_or_restore_event('trash', false); |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * @param string $post_id |
|
| 1882 | - */ |
|
| 1883 | - public function restore_cpt_item($post_id) |
|
| 1884 | - { |
|
| 1885 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1886 | - $this->_trash_or_restore_event('draft', false); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - |
|
| 1890 | - |
|
| 1891 | - /** |
|
| 1892 | - * @param string $post_id |
|
| 1893 | - */ |
|
| 1894 | - public function delete_cpt_item($post_id) |
|
| 1895 | - { |
|
| 1896 | - $this->_req_data['EVT_ID'] = $post_id; |
|
| 1897 | - $this->_delete_event(false); |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * _trash_or_restore_event |
|
| 1904 | - * |
|
| 1905 | - * @access protected |
|
| 1906 | - * @param string $event_status |
|
| 1907 | - * @param bool $redirect_after |
|
| 1908 | - */ |
|
| 1909 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1910 | - { |
|
| 1911 | - //determine the event id and set to array. |
|
| 1912 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1913 | - // loop thru events |
|
| 1914 | - if ($EVT_ID) { |
|
| 1915 | - // clean status |
|
| 1916 | - $event_status = sanitize_key($event_status); |
|
| 1917 | - // grab status |
|
| 1918 | - if ( ! empty($event_status)) { |
|
| 1919 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1920 | - } else { |
|
| 1921 | - $success = false; |
|
| 1922 | - $msg = esc_html__( |
|
| 1923 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1924 | - 'event_espresso' |
|
| 1925 | - ); |
|
| 1926 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | - } |
|
| 1928 | - } else { |
|
| 1929 | - $success = false; |
|
| 1930 | - $msg = esc_html__( |
|
| 1931 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1932 | - 'event_espresso' |
|
| 1933 | - ); |
|
| 1934 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1935 | - } |
|
| 1936 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1937 | - if ($redirect_after) { |
|
| 1938 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1939 | - } |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * _trash_or_restore_events |
|
| 1946 | - * |
|
| 1947 | - * @access protected |
|
| 1948 | - * @param string $event_status |
|
| 1949 | - * @return void |
|
| 1950 | - */ |
|
| 1951 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1952 | - { |
|
| 1953 | - // clean status |
|
| 1954 | - $event_status = sanitize_key($event_status); |
|
| 1955 | - // grab status |
|
| 1956 | - if ( ! empty($event_status)) { |
|
| 1957 | - $success = true; |
|
| 1958 | - //determine the event id and set to array. |
|
| 1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | - // loop thru events |
|
| 1961 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 1962 | - if ($EVT_ID = absint($EVT_ID)) { |
|
| 1963 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1964 | - $success = $results !== false ? $success : false; |
|
| 1965 | - } else { |
|
| 1966 | - $msg = sprintf( |
|
| 1967 | - esc_html__( |
|
| 1968 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1969 | - 'event_espresso' |
|
| 1970 | - ), |
|
| 1971 | - $EVT_ID |
|
| 1972 | - ); |
|
| 1973 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1974 | - $success = false; |
|
| 1975 | - } |
|
| 1976 | - } |
|
| 1977 | - } else { |
|
| 1978 | - $success = false; |
|
| 1979 | - $msg = esc_html__( |
|
| 1980 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1981 | - 'event_espresso' |
|
| 1982 | - ); |
|
| 1983 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1984 | - } |
|
| 1985 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1986 | - $success = $success ? 2 : false; |
|
| 1987 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1988 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * _trash_or_restore_events |
|
| 1995 | - * |
|
| 1996 | - * @access private |
|
| 1997 | - * @param int $EVT_ID |
|
| 1998 | - * @param string $event_status |
|
| 1999 | - * @return bool |
|
| 2000 | - */ |
|
| 2001 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2002 | - { |
|
| 2003 | - // grab event id |
|
| 2004 | - if ( ! $EVT_ID) { |
|
| 2005 | - $msg = esc_html__( |
|
| 2006 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2007 | - 'event_espresso' |
|
| 2008 | - ); |
|
| 2009 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2010 | - return false; |
|
| 2011 | - } |
|
| 2012 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2013 | - // clean status |
|
| 2014 | - $event_status = sanitize_key($event_status); |
|
| 2015 | - // grab status |
|
| 2016 | - if (empty($event_status)) { |
|
| 2017 | - $msg = esc_html__( |
|
| 2018 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2019 | - 'event_espresso' |
|
| 2020 | - ); |
|
| 2021 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2022 | - return false; |
|
| 2023 | - } |
|
| 2024 | - // was event trashed or restored ? |
|
| 2025 | - switch ($event_status) { |
|
| 2026 | - case 'draft' : |
|
| 2027 | - $action = 'restored from the trash'; |
|
| 2028 | - $hook = 'AHEE_event_restored_from_trash'; |
|
| 2029 | - break; |
|
| 2030 | - case 'trash' : |
|
| 2031 | - $action = 'moved to the trash'; |
|
| 2032 | - $hook = 'AHEE_event_moved_to_trash'; |
|
| 2033 | - break; |
|
| 2034 | - default : |
|
| 2035 | - $action = 'updated'; |
|
| 2036 | - $hook = false; |
|
| 2037 | - } |
|
| 2038 | - //use class to change status |
|
| 2039 | - $this->_cpt_model_obj->set_status($event_status); |
|
| 2040 | - $success = $this->_cpt_model_obj->save(); |
|
| 2041 | - if ($success === false) { |
|
| 2042 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2043 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2044 | - return false; |
|
| 2045 | - } |
|
| 2046 | - if ($hook) { |
|
| 2047 | - do_action($hook); |
|
| 2048 | - } |
|
| 2049 | - return true; |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * _delete_event |
|
| 2056 | - * |
|
| 2057 | - * @access protected |
|
| 2058 | - * @param bool $redirect_after |
|
| 2059 | - */ |
|
| 2060 | - protected function _delete_event($redirect_after = true) |
|
| 2061 | - { |
|
| 2062 | - //determine the event id and set to array. |
|
| 2063 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2064 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2065 | - // loop thru events |
|
| 2066 | - if ($EVT_ID) { |
|
| 2067 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2068 | - // get list of events with no prices |
|
| 2069 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2070 | - // remove this event from the list of events with no prices |
|
| 2071 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2072 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2073 | - } |
|
| 2074 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2075 | - } else { |
|
| 2076 | - $success = false; |
|
| 2077 | - $msg = esc_html__( |
|
| 2078 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2079 | - 'event_espresso' |
|
| 2080 | - ); |
|
| 2081 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2082 | - } |
|
| 2083 | - if ($redirect_after) { |
|
| 2084 | - $this->_redirect_after_action( |
|
| 2085 | - $success, |
|
| 2086 | - 'Event', |
|
| 2087 | - 'deleted', |
|
| 2088 | - array('action' => 'default', 'status' => 'trash') |
|
| 2089 | - ); |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - |
|
| 2093 | - |
|
| 2094 | - |
|
| 2095 | - /** |
|
| 2096 | - * _delete_events |
|
| 2097 | - * |
|
| 2098 | - * @access protected |
|
| 2099 | - * @return void |
|
| 2100 | - */ |
|
| 2101 | - protected function _delete_events() |
|
| 2102 | - { |
|
| 2103 | - $success = true; |
|
| 2104 | - // get list of events with no prices |
|
| 2105 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2106 | - //determine the event id and set to array. |
|
| 2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | - // loop thru events |
|
| 2109 | - foreach ($EVT_IDs as $EVT_ID) { |
|
| 2110 | - $EVT_ID = absint($EVT_ID); |
|
| 2111 | - if ($EVT_ID) { |
|
| 2112 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2113 | - $success = $results !== false ? $success : false; |
|
| 2114 | - // remove this event from the list of events with no prices |
|
| 2115 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2116 | - } else { |
|
| 2117 | - $success = false; |
|
| 2118 | - $msg = esc_html__( |
|
| 2119 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2120 | - 'event_espresso' |
|
| 2121 | - ); |
|
| 2122 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | - } |
|
| 2124 | - } |
|
| 2125 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2126 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2127 | - $success = $success ? 2 : false; |
|
| 2128 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - |
|
| 2132 | - |
|
| 2133 | - /** |
|
| 2134 | - * _permanently_delete_event |
|
| 2135 | - * |
|
| 2136 | - * @access private |
|
| 2137 | - * @param int $EVT_ID |
|
| 2138 | - * @return bool |
|
| 2139 | - */ |
|
| 2140 | - private function _permanently_delete_event($EVT_ID = 0) |
|
| 2141 | - { |
|
| 2142 | - // grab event id |
|
| 2143 | - if ( ! $EVT_ID) { |
|
| 2144 | - $msg = esc_html__( |
|
| 2145 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2146 | - 'event_espresso' |
|
| 2147 | - ); |
|
| 2148 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2149 | - return false; |
|
| 2150 | - } |
|
| 2151 | - if ( |
|
| 2152 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2153 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2154 | - ) { |
|
| 2155 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2156 | - } |
|
| 2157 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2158 | - return false; |
|
| 2159 | - } |
|
| 2160 | - //need to delete related tickets and prices first. |
|
| 2161 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2162 | - foreach ($datetimes as $datetime) { |
|
| 2163 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2164 | - $tickets = $datetime->get_many_related('Ticket'); |
|
| 2165 | - foreach ($tickets as $ticket) { |
|
| 2166 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2167 | - $ticket->delete_related_permanently('Price'); |
|
| 2168 | - $ticket->delete_permanently(); |
|
| 2169 | - } |
|
| 2170 | - $datetime->delete(); |
|
| 2171 | - } |
|
| 2172 | - //what about related venues or terms? |
|
| 2173 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2174 | - foreach ($venues as $venue) { |
|
| 2175 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2176 | - } |
|
| 2177 | - //any attached question groups? |
|
| 2178 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2179 | - if ( ! empty($question_groups)) { |
|
| 2180 | - foreach ($question_groups as $question_group) { |
|
| 2181 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2182 | - } |
|
| 2183 | - } |
|
| 2184 | - //Message Template Groups |
|
| 2185 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2186 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2187 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2188 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2189 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2190 | - } |
|
| 2191 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2192 | - // did it all go as planned ? |
|
| 2193 | - if ($success) { |
|
| 2194 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2195 | - EE_Error::add_success($msg); |
|
| 2196 | - } else { |
|
| 2197 | - $msg = sprintf( |
|
| 2198 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2199 | - $EVT_ID |
|
| 2200 | - ); |
|
| 2201 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2202 | - return false; |
|
| 2203 | - } |
|
| 2204 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2205 | - return true; |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - |
|
| 2209 | - |
|
| 2210 | - /** |
|
| 2211 | - * get total number of events |
|
| 2212 | - * |
|
| 2213 | - * @access public |
|
| 2214 | - * @return int |
|
| 2215 | - */ |
|
| 2216 | - public function total_events() |
|
| 2217 | - { |
|
| 2218 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2219 | - return $count; |
|
| 2220 | - } |
|
| 2221 | - |
|
| 2222 | - |
|
| 2223 | - |
|
| 2224 | - /** |
|
| 2225 | - * get total number of draft events |
|
| 2226 | - * |
|
| 2227 | - * @access public |
|
| 2228 | - * @return int |
|
| 2229 | - */ |
|
| 2230 | - public function total_events_draft() |
|
| 2231 | - { |
|
| 2232 | - $where = array( |
|
| 2233 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2234 | - ); |
|
| 2235 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2236 | - return $count; |
|
| 2237 | - } |
|
| 2238 | - |
|
| 2239 | - |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * get total number of trashed events |
|
| 2243 | - * |
|
| 2244 | - * @access public |
|
| 2245 | - * @return int |
|
| 2246 | - */ |
|
| 2247 | - public function total_trashed_events() |
|
| 2248 | - { |
|
| 2249 | - $where = array( |
|
| 2250 | - 'status' => 'trash', |
|
| 2251 | - ); |
|
| 2252 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2253 | - return $count; |
|
| 2254 | - } |
|
| 2255 | - |
|
| 2256 | - |
|
| 2257 | - /** |
|
| 2258 | - * _default_event_settings |
|
| 2259 | - * This generates the Default Settings Tab |
|
| 2260 | - * |
|
| 2261 | - * @return void |
|
| 2262 | - * @throws \EE_Error |
|
| 2263 | - */ |
|
| 2264 | - protected function _default_event_settings() |
|
| 2265 | - { |
|
| 2266 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2267 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2268 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2269 | - $this->display_admin_page_with_sidebar(); |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - |
|
| 2273 | - /** |
|
| 2274 | - * Return the form for event settings. |
|
| 2275 | - * @return \EE_Form_Section_Proper |
|
| 2276 | - */ |
|
| 2277 | - protected function _default_event_settings_form() |
|
| 2278 | - { |
|
| 2279 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2280 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2281 | - //exclude |
|
| 2282 | - array( |
|
| 2283 | - EEM_Registration::status_id_cancelled, |
|
| 2284 | - EEM_Registration::status_id_declined, |
|
| 2285 | - EEM_Registration::status_id_incomplete, |
|
| 2286 | - EEM_Registration::status_id_wait_list, |
|
| 2287 | - ), |
|
| 2288 | - true |
|
| 2289 | - ); |
|
| 2290 | - return new EE_Form_Section_Proper( |
|
| 2291 | - array( |
|
| 2292 | - 'name' => 'update_default_event_settings', |
|
| 2293 | - 'html_id' => 'update_default_event_settings', |
|
| 2294 | - 'html_class' => 'form-table', |
|
| 2295 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2296 | - 'subsections' => apply_filters( |
|
| 2297 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2298 | - array( |
|
| 2299 | - 'default_reg_status' => new EE_Select_Input( |
|
| 2300 | - $registration_stati_for_selection, |
|
| 2301 | - array( |
|
| 2302 | - 'default' => isset($registration_config->default_STS_ID) |
|
| 2303 | - && array_key_exists( |
|
| 2304 | - $registration_config->default_STS_ID, |
|
| 2305 | - $registration_stati_for_selection |
|
| 2306 | - ) |
|
| 2307 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2308 | - : EEM_Registration::status_id_pending_payment, |
|
| 2309 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2310 | - . EEH_Template::get_help_tab_link( |
|
| 2311 | - 'default_settings_status_help_tab' |
|
| 2312 | - ), |
|
| 2313 | - 'html_help_text' => esc_html__( |
|
| 2314 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2315 | - 'event_espresso' |
|
| 2316 | - ) |
|
| 2317 | - ) |
|
| 2318 | - ), |
|
| 2319 | - 'default_max_tickets' => new EE_Integer_Input( |
|
| 2320 | - array( |
|
| 2321 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2322 | - ? $registration_config->default_maximum_number_of_tickets |
|
| 2323 | - : EEM_Event::get_default_additional_limit(), |
|
| 2324 | - 'html_label_text' => esc_html__( |
|
| 2325 | - 'Default Maximum Tickets Allowed Per Order:', |
|
| 2326 | - 'event_espresso' |
|
| 2327 | - ) . EEH_Template::get_help_tab_link( |
|
| 2328 | - 'default_maximum_tickets_help_tab"' |
|
| 2329 | - ), |
|
| 2330 | - 'html_help_text' => esc_html__( |
|
| 2331 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2332 | - 'event_espresso' |
|
| 2333 | - ) |
|
| 2334 | - ) |
|
| 2335 | - ) |
|
| 2336 | - ) |
|
| 2337 | - ) |
|
| 2338 | - ) |
|
| 2339 | - ); |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - |
|
| 2343 | - /** |
|
| 2344 | - * _update_default_event_settings |
|
| 2345 | - * |
|
| 2346 | - * @access protected |
|
| 2347 | - * @return void |
|
| 2348 | - * @throws \EE_Error |
|
| 2349 | - */ |
|
| 2350 | - protected function _update_default_event_settings() |
|
| 2351 | - { |
|
| 2352 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2353 | - $form = $this->_default_event_settings_form(); |
|
| 2354 | - if ($form->was_submitted()) { |
|
| 2355 | - $form->receive_form_submission(); |
|
| 2356 | - if ($form->is_valid()) { |
|
| 2357 | - $valid_data = $form->valid_data(); |
|
| 2358 | - if (isset($valid_data['default_reg_status'])) { |
|
| 2359 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2360 | - } |
|
| 2361 | - if (isset($valid_data['default_max_tickets'])) { |
|
| 2362 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2363 | - } |
|
| 2364 | - //update because data was valid! |
|
| 2365 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2366 | - EE_Error::overwrite_success(); |
|
| 2367 | - EE_Error::add_success( |
|
| 2368 | - __('Default Event Settings were updated', 'event_espresso') |
|
| 2369 | - ); |
|
| 2370 | - } |
|
| 2371 | - } |
|
| 2372 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - |
|
| 2377 | - /************* Templates *************/ |
|
| 2378 | - protected function _template_settings() |
|
| 2379 | - { |
|
| 2380 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2381 | - $this->_template_args['preview_img'] = '<img src="' |
|
| 2382 | - . EVENTS_ASSETS_URL |
|
| 2383 | - . DS |
|
| 2384 | - . 'images' |
|
| 2385 | - . DS |
|
| 2386 | - . 'caffeinated_template_features.jpg" alt="' |
|
| 2387 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2388 | - . '" />'; |
|
| 2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2390 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2391 | - 'event_espresso' |
|
| 2392 | - ) . '</strong>'; |
|
| 2393 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2394 | - } |
|
| 2395 | - |
|
| 2396 | - |
|
| 2397 | - /** Event Category Stuff **/ |
|
| 2398 | - /** |
|
| 2399 | - * set the _category property with the category object for the loaded page. |
|
| 2400 | - * |
|
| 2401 | - * @access private |
|
| 2402 | - * @return void |
|
| 2403 | - */ |
|
| 2404 | - private function _set_category_object() |
|
| 2405 | - { |
|
| 2406 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2407 | - return; |
|
| 2408 | - } //already have the category object so get out. |
|
| 2409 | - //set default category object |
|
| 2410 | - $this->_set_empty_category_object(); |
|
| 2411 | - //only set if we've got an id |
|
| 2412 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2413 | - return; |
|
| 2414 | - } |
|
| 2415 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2416 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2417 | - if ( ! empty($term)) { |
|
| 2418 | - $this->_category->category_name = $term->name; |
|
| 2419 | - $this->_category->category_identifier = $term->slug; |
|
| 2420 | - $this->_category->category_desc = $term->description; |
|
| 2421 | - $this->_category->id = $term->term_id; |
|
| 2422 | - $this->_category->parent = $term->parent; |
|
| 2423 | - } |
|
| 2424 | - } |
|
| 2425 | - |
|
| 2426 | - |
|
| 2427 | - |
|
| 2428 | - private function _set_empty_category_object() |
|
| 2429 | - { |
|
| 2430 | - $this->_category = new stdClass(); |
|
| 2431 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2432 | - $this->_category->id = $this->_category->parent = 0; |
|
| 2433 | - } |
|
| 2434 | - |
|
| 2435 | - |
|
| 2436 | - |
|
| 2437 | - protected function _category_list_table() |
|
| 2438 | - { |
|
| 2439 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2440 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2442 | - 'add_category', |
|
| 2443 | - 'add_category', |
|
| 2444 | - array(), |
|
| 2445 | - 'add-new-h2' |
|
| 2446 | - ); |
|
| 2447 | - $this->display_admin_list_table_page_with_sidebar(); |
|
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * @param $view |
|
| 2454 | - */ |
|
| 2455 | - protected function _category_details($view) |
|
| 2456 | - { |
|
| 2457 | - //load formatter helper |
|
| 2458 | - //load field generator helper |
|
| 2459 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2460 | - $this->_set_add_edit_form_tags($route); |
|
| 2461 | - $this->_set_category_object(); |
|
| 2462 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2463 | - $delete_action = 'delete_category'; |
|
| 2464 | - //custom redirect |
|
| 2465 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2466 | - array('action' => 'category_list'), |
|
| 2467 | - $this->_admin_base_url |
|
| 2468 | - ); |
|
| 2469 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2470 | - //take care of contents |
|
| 2471 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2472 | - $this->display_admin_page_with_sidebar(); |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - |
|
| 2476 | - |
|
| 2477 | - /** |
|
| 2478 | - * @return mixed |
|
| 2479 | - */ |
|
| 2480 | - protected function _category_details_content() |
|
| 2481 | - { |
|
| 2482 | - $editor_args['category_desc'] = array( |
|
| 2483 | - 'type' => 'wp_editor', |
|
| 2484 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2485 | - 'class' => 'my_editor_custom', |
|
| 2486 | - 'wpeditor_args' => array('media_buttons' => false), |
|
| 2487 | - ); |
|
| 2488 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2489 | - $all_terms = get_terms( |
|
| 2490 | - array('espresso_event_categories'), |
|
| 2491 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2492 | - ); |
|
| 2493 | - //setup category select for term parents. |
|
| 2494 | - $category_select_values[] = array( |
|
| 2495 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2496 | - 'id' => 0, |
|
| 2497 | - ); |
|
| 2498 | - foreach ($all_terms as $term) { |
|
| 2499 | - $category_select_values[] = array( |
|
| 2500 | - 'text' => $term->name, |
|
| 2501 | - 'id' => $term->term_id, |
|
| 2502 | - ); |
|
| 2503 | - } |
|
| 2504 | - $category_select = EEH_Form_Fields::select_input( |
|
| 2505 | - 'category_parent', |
|
| 2506 | - $category_select_values, |
|
| 2507 | - $this->_category->parent |
|
| 2508 | - ); |
|
| 2509 | - $template_args = array( |
|
| 2510 | - 'category' => $this->_category, |
|
| 2511 | - 'category_select' => $category_select, |
|
| 2512 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2513 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2514 | - 'disable' => '', |
|
| 2515 | - 'disabled_message' => false, |
|
| 2516 | - ); |
|
| 2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2518 | - return EEH_Template::display_template($template, $template_args, true); |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - |
|
| 2522 | - |
|
| 2523 | - protected function _delete_categories() |
|
| 2524 | - { |
|
| 2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | - : (array)$this->_req_data['category_id']; |
|
| 2527 | - foreach ($cat_ids as $cat_id) { |
|
| 2528 | - $this->_delete_category($cat_id); |
|
| 2529 | - } |
|
| 2530 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2531 | - $query_args = array( |
|
| 2532 | - 'action' => 'category_list', |
|
| 2533 | - ); |
|
| 2534 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - /** |
|
| 2540 | - * @param $cat_id |
|
| 2541 | - */ |
|
| 2542 | - protected function _delete_category($cat_id) |
|
| 2543 | - { |
|
| 2544 | - $cat_id = absint($cat_id); |
|
| 2545 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - |
|
| 2549 | - |
|
| 2550 | - /** |
|
| 2551 | - * @param $new_category |
|
| 2552 | - */ |
|
| 2553 | - protected function _insert_or_update_category($new_category) |
|
| 2554 | - { |
|
| 2555 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2556 | - $success = 0; //we already have a success message so lets not send another. |
|
| 2557 | - if ($cat_id) { |
|
| 2558 | - $query_args = array( |
|
| 2559 | - 'action' => 'edit_category', |
|
| 2560 | - 'EVT_CAT_ID' => $cat_id, |
|
| 2561 | - ); |
|
| 2562 | - } else { |
|
| 2563 | - $query_args = array('action' => 'add_category'); |
|
| 2564 | - } |
|
| 2565 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * @param bool $update |
|
| 2572 | - * @return bool|mixed|string |
|
| 2573 | - */ |
|
| 2574 | - private function _insert_category($update = false) |
|
| 2575 | - { |
|
| 2576 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2577 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2578 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2579 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2580 | - if (empty($category_name)) { |
|
| 2581 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2582 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2583 | - return false; |
|
| 2584 | - } |
|
| 2585 | - $term_args = array( |
|
| 2586 | - 'name' => $category_name, |
|
| 2587 | - 'description' => $category_desc, |
|
| 2588 | - 'parent' => $category_parent, |
|
| 2589 | - ); |
|
| 2590 | - //was the category_identifier input disabled? |
|
| 2591 | - if (isset($this->_req_data['category_identifier'])) { |
|
| 2592 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2593 | - } |
|
| 2594 | - $insert_ids = $update |
|
| 2595 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2596 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2597 | - if ( ! is_array($insert_ids)) { |
|
| 2598 | - $msg = esc_html__( |
|
| 2599 | - 'An error occurred and the category has not been saved to the database.', |
|
| 2600 | - 'event_espresso' |
|
| 2601 | - ); |
|
| 2602 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2603 | - } else { |
|
| 2604 | - $cat_id = $insert_ids['term_id']; |
|
| 2605 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2606 | - EE_Error::add_success($msg); |
|
| 2607 | - } |
|
| 2608 | - return $cat_id; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - |
|
| 2612 | - |
|
| 2613 | - /** |
|
| 2614 | - * @param int $per_page |
|
| 2615 | - * @param int $current_page |
|
| 2616 | - * @param bool $count |
|
| 2617 | - * @return \EE_Base_Class[]|int |
|
| 2618 | - */ |
|
| 2619 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2620 | - { |
|
| 2621 | - //testing term stuff |
|
| 2622 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2623 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2624 | - $limit = ($current_page - 1) * $per_page; |
|
| 2625 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2626 | - if (isset($this->_req_data['s'])) { |
|
| 2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2628 | - $where['OR'] = array( |
|
| 2629 | - 'Term.name' => array('LIKE', $sstr), |
|
| 2630 | - 'description' => array('LIKE', $sstr), |
|
| 2631 | - ); |
|
| 2632 | - } |
|
| 2633 | - $query_params = array( |
|
| 2634 | - $where, |
|
| 2635 | - 'order_by' => array($orderby => $order), |
|
| 2636 | - 'limit' => $limit . ',' . $per_page, |
|
| 2637 | - 'force_join' => array('Term'), |
|
| 2638 | - ); |
|
| 2639 | - $categories = $count |
|
| 2640 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2641 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2642 | - return $categories; |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - |
|
| 2646 | - |
|
| 2647 | - /* end category stuff */ |
|
| 2648 | - /**************/ |
|
| 385 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
| 386 | + 'require_nonce' => false, |
|
| 387 | + ), |
|
| 388 | + 'default_event_settings' => array( |
|
| 389 | + 'nav' => array( |
|
| 390 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
| 391 | + 'order' => 40, |
|
| 392 | + ), |
|
| 393 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 394 | + 'labels' => array( |
|
| 395 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
| 396 | + ), |
|
| 397 | + 'help_tabs' => array( |
|
| 398 | + 'default_settings_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
| 400 | + 'filename' => 'events_default_settings', |
|
| 401 | + ), |
|
| 402 | + 'default_settings_status_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
| 404 | + 'filename' => 'events_default_settings_status', |
|
| 405 | + ), |
|
| 406 | + 'default_maximum_tickets_help_tab' => array( |
|
| 407 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
| 408 | + 'filename' => 'events_default_settings_max_tickets', |
|
| 409 | + ) |
|
| 410 | + ), |
|
| 411 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
| 412 | + 'require_nonce' => false, |
|
| 413 | + ), |
|
| 414 | + //template settings |
|
| 415 | + 'template_settings' => array( |
|
| 416 | + 'nav' => array( |
|
| 417 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
| 418 | + 'order' => 30, |
|
| 419 | + ), |
|
| 420 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 421 | + 'help_tabs' => array( |
|
| 422 | + 'general_settings_templates_help_tab' => array( |
|
| 423 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
| 424 | + 'filename' => 'general_settings_templates', |
|
| 425 | + ), |
|
| 426 | + ), |
|
| 427 | + 'help_tour' => array('Templates_Help_Tour'), |
|
| 428 | + 'require_nonce' => false, |
|
| 429 | + ), |
|
| 430 | + //event category stuff |
|
| 431 | + 'add_category' => array( |
|
| 432 | + 'nav' => array( |
|
| 433 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
| 434 | + 'order' => 15, |
|
| 435 | + 'persistent' => false, |
|
| 436 | + ), |
|
| 437 | + 'help_tabs' => array( |
|
| 438 | + 'add_category_help_tab' => array( |
|
| 439 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
| 440 | + 'filename' => 'events_add_category', |
|
| 441 | + ), |
|
| 442 | + ), |
|
| 443 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
| 444 | + 'metaboxes' => array('_publish_post_box'), |
|
| 445 | + 'require_nonce' => false, |
|
| 446 | + ), |
|
| 447 | + 'edit_category' => array( |
|
| 448 | + 'nav' => array( |
|
| 449 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
| 450 | + 'order' => 15, |
|
| 451 | + 'persistent' => false, |
|
| 452 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
| 453 | + ? add_query_arg( |
|
| 454 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
| 455 | + $this->_current_page_view_url |
|
| 456 | + ) |
|
| 457 | + : $this->_admin_base_url, |
|
| 458 | + ), |
|
| 459 | + 'help_tabs' => array( |
|
| 460 | + 'edit_category_help_tab' => array( |
|
| 461 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
| 462 | + 'filename' => 'events_edit_category', |
|
| 463 | + ), |
|
| 464 | + ), |
|
| 465 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
| 466 | + 'metaboxes' => array('_publish_post_box'), |
|
| 467 | + 'require_nonce' => false, |
|
| 468 | + ), |
|
| 469 | + 'category_list' => array( |
|
| 470 | + 'nav' => array( |
|
| 471 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
| 472 | + 'order' => 20, |
|
| 473 | + ), |
|
| 474 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
| 475 | + 'help_tabs' => array( |
|
| 476 | + 'events_categories_help_tab' => array( |
|
| 477 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
| 478 | + 'filename' => 'events_categories', |
|
| 479 | + ), |
|
| 480 | + 'events_categories_table_column_headings_help_tab' => array( |
|
| 481 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
| 482 | + 'filename' => 'events_categories_table_column_headings', |
|
| 483 | + ), |
|
| 484 | + 'events_categories_view_help_tab' => array( |
|
| 485 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
| 486 | + 'filename' => 'events_categories_views', |
|
| 487 | + ), |
|
| 488 | + 'events_categories_other_help_tab' => array( |
|
| 489 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
| 490 | + 'filename' => 'events_categories_other', |
|
| 491 | + ), |
|
| 492 | + ), |
|
| 493 | + 'help_tour' => array( |
|
| 494 | + 'Event_Categories_Help_Tour', |
|
| 495 | + ), |
|
| 496 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 497 | + 'require_nonce' => false, |
|
| 498 | + ), |
|
| 499 | + ); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + protected function _add_screen_options() |
|
| 505 | + { |
|
| 506 | + //todo |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + protected function _add_screen_options_default() |
|
| 512 | + { |
|
| 513 | + $this->_per_page_screen_option(); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + protected function _add_screen_options_category_list() |
|
| 519 | + { |
|
| 520 | + $page_title = $this->_admin_page_title; |
|
| 521 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
| 522 | + $this->_per_page_screen_option(); |
|
| 523 | + $this->_admin_page_title = $page_title; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + protected function _add_feature_pointers() |
|
| 529 | + { |
|
| 530 | + //todo |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + public function load_scripts_styles() |
|
| 536 | + { |
|
| 537 | + wp_register_style( |
|
| 538 | + 'events-admin-css', |
|
| 539 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 540 | + array(), |
|
| 541 | + EVENT_ESPRESSO_VERSION |
|
| 542 | + ); |
|
| 543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | + wp_enqueue_style('events-admin-css'); |
|
| 545 | + wp_enqueue_style('ee-cat-admin'); |
|
| 546 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
| 547 | + //registers for all views |
|
| 548 | + //scripts |
|
| 549 | + wp_register_script( |
|
| 550 | + 'event_editor_js', |
|
| 551 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 552 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
| 553 | + EVENT_ESPRESSO_VERSION, |
|
| 554 | + true |
|
| 555 | + ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueuing scripts and styles specific to this view |
|
| 562 | + * |
|
| 563 | + * @return void |
|
| 564 | + */ |
|
| 565 | + public function load_scripts_styles_create_new() |
|
| 566 | + { |
|
| 567 | + $this->load_scripts_styles_edit(); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * enqueuing scripts and styles specific to this view |
|
| 574 | + * |
|
| 575 | + * @return void |
|
| 576 | + */ |
|
| 577 | + public function load_scripts_styles_edit() |
|
| 578 | + { |
|
| 579 | + //styles |
|
| 580 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 581 | + wp_register_style( |
|
| 582 | + 'event-editor-css', |
|
| 583 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 584 | + array('ee-admin-css'), |
|
| 585 | + EVENT_ESPRESSO_VERSION |
|
| 586 | + ); |
|
| 587 | + wp_enqueue_style('event-editor-css'); |
|
| 588 | + //scripts |
|
| 589 | + wp_register_script( |
|
| 590 | + 'event-datetime-metabox', |
|
| 591 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 592 | + array('event_editor_js', 'ee-datepicker'), |
|
| 593 | + EVENT_ESPRESSO_VERSION |
|
| 594 | + ); |
|
| 595 | + wp_enqueue_script('event-datetime-metabox'); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + |
|
| 600 | + public function load_scripts_styles_add_category() |
|
| 601 | + { |
|
| 602 | + $this->load_scripts_styles_edit_category(); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + public function load_scripts_styles_edit_category() |
|
| 608 | + { |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + protected function _set_list_table_views_category_list() |
|
| 614 | + { |
|
| 615 | + $this->_views = array( |
|
| 616 | + 'all' => array( |
|
| 617 | + 'slug' => 'all', |
|
| 618 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 619 | + 'count' => 0, |
|
| 620 | + 'bulk_action' => array( |
|
| 621 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 622 | + ), |
|
| 623 | + ), |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + public function admin_init() |
|
| 630 | + { |
|
| 631 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
| 632 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
| 633 | + 'event_espresso' |
|
| 634 | + ); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + //nothing needed for events with these methods. |
|
| 640 | + public function admin_notices() |
|
| 641 | + { |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + public function admin_footer_scripts() |
|
| 647 | + { |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
| 654 | + * warning (via EE_Error::add_error()); |
|
| 655 | + * |
|
| 656 | + * @param EE_Event $event Event object |
|
| 657 | + * @access public |
|
| 658 | + * @return void |
|
| 659 | + */ |
|
| 660 | + public function verify_event_edit($event = null) |
|
| 661 | + { |
|
| 662 | + // no event? |
|
| 663 | + if (empty($event)) { |
|
| 664 | + // set event |
|
| 665 | + $event = $this->_cpt_model_obj; |
|
| 666 | + } |
|
| 667 | + // STILL no event? |
|
| 668 | + if (! $event instanceof EE_Event) { |
|
| 669 | + return; |
|
| 670 | + } |
|
| 671 | + $orig_status = $event->status(); |
|
| 672 | + // first check if event is active. |
|
| 673 | + if ( |
|
| 674 | + $orig_status === EEM_Event::cancelled |
|
| 675 | + || $orig_status === EEM_Event::postponed |
|
| 676 | + || $event->is_expired() |
|
| 677 | + || $event->is_inactive() |
|
| 678 | + ) { |
|
| 679 | + return; |
|
| 680 | + } |
|
| 681 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
| 682 | + if ($event->is_sold_out(true)) { |
|
| 683 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
| 684 | + EE_Error::add_attention( |
|
| 685 | + sprintf( |
|
| 686 | + esc_html__( |
|
| 687 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
| 688 | + 'event_espresso' |
|
| 689 | + ), |
|
| 690 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
| 691 | + ) |
|
| 692 | + ); |
|
| 693 | + } |
|
| 694 | + return; |
|
| 695 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
| 696 | + EE_Error::add_attention( |
|
| 697 | + sprintf( |
|
| 698 | + esc_html__( |
|
| 699 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
| 700 | + 'event_espresso' |
|
| 701 | + ), |
|
| 702 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
| 703 | + ) |
|
| 704 | + ); |
|
| 705 | + } |
|
| 706 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
| 707 | + if ( ! $event->tickets_on_sale()) { |
|
| 708 | + return; |
|
| 709 | + } |
|
| 710 | + //made it here so show warning |
|
| 711 | + $this->_edit_event_warning(); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
| 718 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
| 719 | + * |
|
| 720 | + * @access protected |
|
| 721 | + * @return void |
|
| 722 | + */ |
|
| 723 | + protected function _edit_event_warning() |
|
| 724 | + { |
|
| 725 | + // we don't want to add warnings during these requests |
|
| 726 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
| 727 | + return; |
|
| 728 | + } |
|
| 729 | + EE_Error::add_attention( |
|
| 730 | + esc_html__( |
|
| 731 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
| 732 | + 'event_espresso' |
|
| 733 | + ) |
|
| 734 | + ); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + /** |
|
| 740 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
| 741 | + * Otherwise, do the normal logic |
|
| 742 | + * |
|
| 743 | + * @return string |
|
| 744 | + * @throws \EE_Error |
|
| 745 | + */ |
|
| 746 | + protected function _create_new_cpt_item() |
|
| 747 | + { |
|
| 748 | + $gmt_offset = get_option('gmt_offset'); |
|
| 749 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
| 750 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
| 751 | + EE_Error::add_attention( |
|
| 752 | + sprintf( |
|
| 753 | + __( |
|
| 754 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
| 755 | + 'event_espresso' |
|
| 756 | + ), |
|
| 757 | + '<a href="' . admin_url('options-general.php') . '">', |
|
| 758 | + '</a>' |
|
| 759 | + ), |
|
| 760 | + __FILE__, |
|
| 761 | + __FUNCTION__, |
|
| 762 | + __LINE__ |
|
| 763 | + ); |
|
| 764 | + } |
|
| 765 | + return parent::_create_new_cpt_item(); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + protected function _set_list_table_views_default() |
|
| 771 | + { |
|
| 772 | + $this->_views = array( |
|
| 773 | + 'all' => array( |
|
| 774 | + 'slug' => 'all', |
|
| 775 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
| 776 | + 'count' => 0, |
|
| 777 | + 'bulk_action' => array( |
|
| 778 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 779 | + ), |
|
| 780 | + ), |
|
| 781 | + 'draft' => array( |
|
| 782 | + 'slug' => 'draft', |
|
| 783 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
| 784 | + 'count' => 0, |
|
| 785 | + 'bulk_action' => array( |
|
| 786 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 787 | + ), |
|
| 788 | + ), |
|
| 789 | + ); |
|
| 790 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
| 791 | + $this->_views['trash'] = array( |
|
| 792 | + 'slug' => 'trash', |
|
| 793 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 794 | + 'count' => 0, |
|
| 795 | + 'bulk_action' => array( |
|
| 796 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
| 797 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
| 798 | + ), |
|
| 799 | + ); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * @return array |
|
| 807 | + */ |
|
| 808 | + protected function _event_legend_items() |
|
| 809 | + { |
|
| 810 | + $items = array( |
|
| 811 | + 'view_details' => array( |
|
| 812 | + 'class' => 'dashicons dashicons-search', |
|
| 813 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
| 814 | + ), |
|
| 815 | + 'edit_event' => array( |
|
| 816 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
| 817 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
| 818 | + ), |
|
| 819 | + 'view_attendees' => array( |
|
| 820 | + 'class' => 'dashicons dashicons-groups', |
|
| 821 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
| 822 | + ), |
|
| 823 | + ); |
|
| 824 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
| 825 | + $statuses = array( |
|
| 826 | + 'sold_out_status' => array( |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 828 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
| 829 | + ), |
|
| 830 | + 'active_status' => array( |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 832 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
| 833 | + ), |
|
| 834 | + 'upcoming_status' => array( |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 836 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
| 837 | + ), |
|
| 838 | + 'postponed_status' => array( |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 840 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
| 841 | + ), |
|
| 842 | + 'cancelled_status' => array( |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 844 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
| 845 | + ), |
|
| 846 | + 'expired_status' => array( |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 848 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
| 849 | + ), |
|
| 850 | + 'inactive_status' => array( |
|
| 851 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 852 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
| 853 | + ), |
|
| 854 | + ); |
|
| 855 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
| 856 | + return array_merge($items, $statuses); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * _event_model |
|
| 863 | + * |
|
| 864 | + * @return EEM_Event |
|
| 865 | + */ |
|
| 866 | + private function _event_model() |
|
| 867 | + { |
|
| 868 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
| 869 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
| 870 | + } |
|
| 871 | + return $this->_event_model; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Adds extra buttons to the WP CPT permalink field row. |
|
| 878 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 879 | + * |
|
| 880 | + * @param string $return the current html |
|
| 881 | + * @param int $id the post id for the page |
|
| 882 | + * @param string $new_title What the title is |
|
| 883 | + * @param string $new_slug what the slug is |
|
| 884 | + * @return string The new html string for the permalink area |
|
| 885 | + */ |
|
| 886 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
| 887 | + { |
|
| 888 | + //make sure this is only when editing |
|
| 889 | + if ( ! empty($id)) { |
|
| 890 | + $post = get_post($id); |
|
| 891 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
| 892 | + . esc_html__('Shortcode', 'event_espresso') |
|
| 893 | + . '</a> '; |
|
| 894 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
| 895 | + . $post->ID |
|
| 896 | + . ']">'; |
|
| 897 | + } |
|
| 898 | + return $return; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * _events_overview_list_table |
|
| 905 | + * This contains the logic for showing the events_overview list |
|
| 906 | + * |
|
| 907 | + * @access protected |
|
| 908 | + * @return void |
|
| 909 | + * @throws \EE_Error |
|
| 910 | + */ |
|
| 911 | + protected function _events_overview_list_table() |
|
| 912 | + { |
|
| 913 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 914 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
| 915 | + ? (array)$this->_template_args['after_list_table'] |
|
| 916 | + : array(); |
|
| 917 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
| 918 | + . EEH_Template::get_button_or_link( |
|
| 919 | + get_post_type_archive_link('espresso_events'), |
|
| 920 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
| 921 | + 'button' |
|
| 922 | + ); |
|
| 923 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
| 924 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 925 | + 'create_new', |
|
| 926 | + 'add', |
|
| 927 | + array(), |
|
| 928 | + 'add-new-h2' |
|
| 929 | + ); |
|
| 930 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * this allows for extra misc actions in the default WP publish box |
|
| 937 | + * |
|
| 938 | + * @return void |
|
| 939 | + */ |
|
| 940 | + public function extra_misc_actions_publish_box() |
|
| 941 | + { |
|
| 942 | + $this->_generate_publish_box_extra_content(); |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 949 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 950 | + * data. |
|
| 951 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
| 952 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
| 953 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
| 954 | + * you handle this accordingly. |
|
| 955 | + * |
|
| 956 | + * @access protected |
|
| 957 | + * @abstract |
|
| 958 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 959 | + * @param object $post The post object of the cpt that was saved. |
|
| 960 | + * @return void |
|
| 961 | + */ |
|
| 962 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 963 | + { |
|
| 964 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
| 965 | + //get out we're not processing an event save. |
|
| 966 | + return; |
|
| 967 | + } |
|
| 968 | + $event_values = array( |
|
| 969 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
| 970 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
| 971 | + 'EVT_additional_limit' => min( |
|
| 972 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
| 973 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
| 974 | + ), |
|
| 975 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
| 976 | + ? $this->_req_data['EVT_default_registration_status'] |
|
| 977 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
| 978 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
| 979 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
| 980 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
| 981 | + ? $this->_req_data['timezone_string'] : null, |
|
| 982 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
| 983 | + ? $this->_req_data['externalURL'] : null, |
|
| 984 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
| 985 | + ? $this->_req_data['event_phone'] : null, |
|
| 986 | + ); |
|
| 987 | + //update event |
|
| 988 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
| 989 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
| 990 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
| 991 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
| 992 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
| 993 | + $event_update_callbacks = apply_filters( |
|
| 994 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 995 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
| 996 | + ); |
|
| 997 | + $att_success = true; |
|
| 998 | + foreach ($event_update_callbacks as $e_callback) { |
|
| 999 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
| 1000 | + $att_success = ! $att_success ? $att_success |
|
| 1001 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
| 1002 | + } |
|
| 1003 | + //any errors? |
|
| 1004 | + if ($success && false === $att_success) { |
|
| 1005 | + EE_Error::add_error( |
|
| 1006 | + esc_html__( |
|
| 1007 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
| 1008 | + 'event_espresso' |
|
| 1009 | + ), |
|
| 1010 | + __FILE__, |
|
| 1011 | + __FUNCTION__, |
|
| 1012 | + __LINE__ |
|
| 1013 | + ); |
|
| 1014 | + } else if ($success === false) { |
|
| 1015 | + EE_Error::add_error( |
|
| 1016 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
| 1017 | + __FILE__, |
|
| 1018 | + __FUNCTION__, |
|
| 1019 | + __LINE__ |
|
| 1020 | + ); |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * @see parent::restore_item() |
|
| 1028 | + * @param int $post_id |
|
| 1029 | + * @param int $revision_id |
|
| 1030 | + */ |
|
| 1031 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 1032 | + { |
|
| 1033 | + //copy existing event meta to new post |
|
| 1034 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
| 1035 | + if ($post_evt instanceof EE_Event) { |
|
| 1036 | + //meta revision restore |
|
| 1037 | + $post_evt->restore_revision($revision_id); |
|
| 1038 | + //related objs restore |
|
| 1039 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Attach the venue to the Event |
|
| 1047 | + * |
|
| 1048 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
| 1049 | + * @param array $data The request data from the form |
|
| 1050 | + * @return bool Success or fail. |
|
| 1051 | + */ |
|
| 1052 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
| 1053 | + { |
|
| 1054 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1055 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
| 1056 | + $rows_affected = null; |
|
| 1057 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
| 1058 | + // very important. If we don't have a venue name... |
|
| 1059 | + // then we'll get out because not necessary to create empty venue |
|
| 1060 | + if (empty($data['venue_title'])) { |
|
| 1061 | + return false; |
|
| 1062 | + } |
|
| 1063 | + $venue_array = array( |
|
| 1064 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
| 1065 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
| 1066 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
| 1067 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
| 1068 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
| 1069 | + : null, |
|
| 1070 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
| 1071 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
| 1072 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
| 1073 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
| 1074 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
| 1075 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
| 1076 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
| 1077 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
| 1078 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
| 1079 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
| 1080 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
| 1081 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
| 1082 | + 'status' => 'publish', |
|
| 1083 | + ); |
|
| 1084 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
| 1085 | + if ( ! empty($venue_id)) { |
|
| 1086 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
| 1087 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
| 1088 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
| 1089 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1090 | + return $rows_affected > 0 ? true : false; |
|
| 1091 | + } else { |
|
| 1092 | + //we insert the venue |
|
| 1093 | + $venue_id = $venue_model->insert($venue_array); |
|
| 1094 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
| 1095 | + return ! empty($venue_id) ? true : false; |
|
| 1096 | + } |
|
| 1097 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 1104 | + * |
|
| 1105 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
| 1106 | + * @param array $data The request data from the form |
|
| 1107 | + * @return array |
|
| 1108 | + */ |
|
| 1109 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
| 1110 | + { |
|
| 1111 | + $success = true; |
|
| 1112 | + $saved_dtt = null; |
|
| 1113 | + $saved_tickets = array(); |
|
| 1114 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1115 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
| 1116 | + //trim all values to ensure any excess whitespace is removed. |
|
| 1117 | + $dtt = array_map('trim', $dtt); |
|
| 1118 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
| 1119 | + : $dtt['DTT_EVT_start']; |
|
| 1120 | + $datetime_values = array( |
|
| 1121 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
| 1122 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
| 1123 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
| 1124 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
| 1125 | + 'DTT_order' => $row, |
|
| 1126 | + ); |
|
| 1127 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
| 1128 | + if ( ! empty($dtt['DTT_ID'])) { |
|
| 1129 | + $DTM = EE_Registry::instance() |
|
| 1130 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
| 1131 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
| 1132 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
| 1133 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
| 1134 | + foreach ($datetime_values as $field => $value) { |
|
| 1135 | + $DTM->set($field, $value); |
|
| 1136 | + } |
|
| 1137 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
| 1138 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
| 1139 | + } else { |
|
| 1140 | + $DTM = EE_Registry::instance()->load_class( |
|
| 1141 | + 'Datetime', |
|
| 1142 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
| 1143 | + false, |
|
| 1144 | + false |
|
| 1145 | + ); |
|
| 1146 | + foreach ($datetime_values as $field => $value) { |
|
| 1147 | + $DTM->set($field, $value); |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + $DTM->save(); |
|
| 1151 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
| 1152 | + //load DTT helper |
|
| 1153 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1154 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
| 1155 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
| 1156 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
| 1157 | + $DTT->save(); |
|
| 1158 | + } |
|
| 1159 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
| 1160 | + $saved_dtt = $DTT; |
|
| 1161 | + $success = ! $success ? $success : $DTT; |
|
| 1162 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
| 1163 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
| 1164 | + } |
|
| 1165 | + //no dtts get deleted so we don't do any of that logic here. |
|
| 1166 | + //update tickets next |
|
| 1167 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 1168 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 1169 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
| 1170 | + $update_prices = false; |
|
| 1171 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
| 1172 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
| 1173 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 1174 | + $tkt = array_map('trim', $tkt); |
|
| 1175 | + if (empty($tkt['TKT_start_date'])) { |
|
| 1176 | + //let's use now in the set timezone. |
|
| 1177 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
| 1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1179 | + } |
|
| 1180 | + if (empty($tkt['TKT_end_date'])) { |
|
| 1181 | + //use the start date of the first datetime |
|
| 1182 | + $dtt = $evtobj->first_datetime(); |
|
| 1183 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
| 1184 | + $incoming_date_formats[0], |
|
| 1185 | + $incoming_date_formats[1] |
|
| 1186 | + ); |
|
| 1187 | + } |
|
| 1188 | + $TKT_values = array( |
|
| 1189 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 1190 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 1191 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 1192 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
| 1193 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 1194 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 1195 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
| 1196 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
| 1197 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 1198 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 1199 | + 'TKT_row' => $row, |
|
| 1200 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
| 1201 | + 'TKT_price' => $ticket_price, |
|
| 1202 | + ); |
|
| 1203 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
| 1204 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 1205 | + $TKT_values['TKT_ID'] = 0; |
|
| 1206 | + $TKT_values['TKT_is_default'] = 0; |
|
| 1207 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1208 | + $update_prices = true; |
|
| 1209 | + } |
|
| 1210 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 1211 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
| 1212 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 1213 | + if ( ! empty($tkt['TKT_ID'])) { |
|
| 1214 | + $TKT = EE_Registry::instance() |
|
| 1215 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
| 1216 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 1217 | + if ($TKT instanceof EE_Ticket) { |
|
| 1218 | + $ticket_sold = $TKT->count_related( |
|
| 1219 | + 'Registration', |
|
| 1220 | + array( |
|
| 1221 | + array( |
|
| 1222 | + 'STS_ID' => array( |
|
| 1223 | + 'NOT IN', |
|
| 1224 | + array(EEM_Registration::status_id_incomplete), |
|
| 1225 | + ), |
|
| 1226 | + ), |
|
| 1227 | + ) |
|
| 1228 | + ) > 0 ? true : false; |
|
| 1229 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
| 1230 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
| 1231 | + && ! $TKT->get( |
|
| 1232 | + 'TKT_deleted' |
|
| 1233 | + ) ? true : false; |
|
| 1234 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1235 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1236 | + //set new values |
|
| 1237 | + foreach ($TKT_values as $field => $value) { |
|
| 1238 | + if ($field == 'TKT_qty') { |
|
| 1239 | + $TKT->set_qty($value); |
|
| 1240 | + } else { |
|
| 1241 | + $TKT->set($field, $value); |
|
| 1242 | + } |
|
| 1243 | + } |
|
| 1244 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
| 1245 | + if ($create_new_TKT) { |
|
| 1246 | + //archive the old ticket first |
|
| 1247 | + $TKT->set('TKT_deleted', 1); |
|
| 1248 | + $TKT->save(); |
|
| 1249 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
| 1250 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1251 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
| 1252 | + $TKT = clone $TKT; |
|
| 1253 | + $TKT->set('TKT_ID', 0); |
|
| 1254 | + $TKT->set('TKT_deleted', 0); |
|
| 1255 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1256 | + $TKT->set('TKT_sold', 0); |
|
| 1257 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
| 1258 | + $update_prices = true; |
|
| 1259 | + } |
|
| 1260 | + //make sure price is set if it hasn't been already |
|
| 1261 | + $TKT->set('TKT_price', $ticket_price); |
|
| 1262 | + } |
|
| 1263 | + } else { |
|
| 1264 | + //no TKT_id so a new TKT |
|
| 1265 | + $TKT_values['TKT_price'] = $ticket_price; |
|
| 1266 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
| 1267 | + if ($TKT instanceof EE_Ticket) { |
|
| 1268 | + //need to reset values to properly account for the date formats |
|
| 1269 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
| 1270 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
| 1271 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
| 1272 | + //set new values |
|
| 1273 | + foreach ($TKT_values as $field => $value) { |
|
| 1274 | + if ($field == 'TKT_qty') { |
|
| 1275 | + $TKT->set_qty($value); |
|
| 1276 | + } else { |
|
| 1277 | + $TKT->set($field, $value); |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + $update_prices = true; |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + // cap ticket qty by datetime reg limits |
|
| 1284 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
| 1285 | + //update ticket. |
|
| 1286 | + $TKT->save(); |
|
| 1287 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
| 1288 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
| 1289 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
| 1290 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
| 1291 | + $TKT->save(); |
|
| 1292 | + } |
|
| 1293 | + //initially let's add the ticket to the dtt |
|
| 1294 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
| 1295 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
| 1296 | + //add prices to ticket |
|
| 1297 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
| 1298 | + } |
|
| 1299 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
| 1300 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
| 1301 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 1302 | + foreach ($tickets_removed as $id) { |
|
| 1303 | + $id = absint($id); |
|
| 1304 | + //get the ticket for this id |
|
| 1305 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 1306 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 1307 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
| 1308 | + foreach ($dtts as $dtt) { |
|
| 1309 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
| 1310 | + } |
|
| 1311 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 1312 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 1313 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 1314 | + $tkt_to_remove->delete_permanently(); |
|
| 1315 | + } |
|
| 1316 | + return array($saved_dtt, $saved_tickets); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * This attaches a list of given prices to a ticket. |
|
| 1323 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 1324 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 1325 | + * price info and prices are automatically "archived" via the ticket. |
|
| 1326 | + * |
|
| 1327 | + * @access private |
|
| 1328 | + * @param array $prices Array of prices from the form. |
|
| 1329 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 1330 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 1331 | + * @return void |
|
| 1332 | + */ |
|
| 1333 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
| 1334 | + { |
|
| 1335 | + foreach ($prices as $row => $prc) { |
|
| 1336 | + $PRC_values = array( |
|
| 1337 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 1338 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
| 1339 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 1340 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 1341 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 1342 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
| 1343 | + 'PRC_order' => $row, |
|
| 1344 | + ); |
|
| 1345 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 1346 | + $PRC_values['PRC_ID'] = 0; |
|
| 1347 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
| 1348 | + } else { |
|
| 1349 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 1350 | + //update this price with new values |
|
| 1351 | + foreach ($PRC_values as $field => $newprc) { |
|
| 1352 | + $PRC->set($field, $newprc); |
|
| 1353 | + } |
|
| 1354 | + $PRC->save(); |
|
| 1355 | + } |
|
| 1356 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Add in our autosave ajax handlers |
|
| 1364 | + * |
|
| 1365 | + * @return void |
|
| 1366 | + */ |
|
| 1367 | + protected function _ee_autosave_create_new() |
|
| 1368 | + { |
|
| 1369 | + // $this->_ee_autosave_edit(); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + protected function _ee_autosave_edit() |
|
| 1375 | + { |
|
| 1376 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + |
|
| 1381 | + /** |
|
| 1382 | + * _generate_publish_box_extra_content |
|
| 1383 | + * |
|
| 1384 | + * @access private |
|
| 1385 | + * @return void |
|
| 1386 | + */ |
|
| 1387 | + private function _generate_publish_box_extra_content() |
|
| 1388 | + { |
|
| 1389 | + //load formatter helper |
|
| 1390 | + //args for getting related registrations |
|
| 1391 | + $approved_query_args = array( |
|
| 1392 | + array( |
|
| 1393 | + 'REG_deleted' => 0, |
|
| 1394 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1395 | + ), |
|
| 1396 | + ); |
|
| 1397 | + $not_approved_query_args = array( |
|
| 1398 | + array( |
|
| 1399 | + 'REG_deleted' => 0, |
|
| 1400 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
| 1401 | + ), |
|
| 1402 | + ); |
|
| 1403 | + $pending_payment_query_args = array( |
|
| 1404 | + array( |
|
| 1405 | + 'REG_deleted' => 0, |
|
| 1406 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
| 1407 | + ), |
|
| 1408 | + ); |
|
| 1409 | + // publish box |
|
| 1410 | + $publish_box_extra_args = array( |
|
| 1411 | + 'view_approved_reg_url' => add_query_arg( |
|
| 1412 | + array( |
|
| 1413 | + 'action' => 'default', |
|
| 1414 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1415 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1416 | + ), |
|
| 1417 | + REG_ADMIN_URL |
|
| 1418 | + ), |
|
| 1419 | + 'view_not_approved_reg_url' => add_query_arg( |
|
| 1420 | + array( |
|
| 1421 | + 'action' => 'default', |
|
| 1422 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1423 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1424 | + ), |
|
| 1425 | + REG_ADMIN_URL |
|
| 1426 | + ), |
|
| 1427 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
| 1428 | + array( |
|
| 1429 | + 'action' => 'default', |
|
| 1430 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
| 1431 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1432 | + ), |
|
| 1433 | + REG_ADMIN_URL |
|
| 1434 | + ), |
|
| 1435 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1436 | + 'Registration', |
|
| 1437 | + $approved_query_args |
|
| 1438 | + ), |
|
| 1439 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
| 1440 | + 'Registration', |
|
| 1441 | + $not_approved_query_args |
|
| 1442 | + ), |
|
| 1443 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
| 1444 | + 'Registration', |
|
| 1445 | + $pending_payment_query_args |
|
| 1446 | + ), |
|
| 1447 | + 'misc_pub_section_class' => apply_filters( |
|
| 1448 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
| 1449 | + 'misc-pub-section' |
|
| 1450 | + ), |
|
| 1451 | + //'email_attendees_url' => add_query_arg( |
|
| 1452 | + // array( |
|
| 1453 | + // 'event_admin_reports' => 'event_newsletter', |
|
| 1454 | + // 'event_id' => $this->_cpt_model_obj->id |
|
| 1455 | + // ), |
|
| 1456 | + // 'admin.php?page=espresso_registrations' |
|
| 1457 | + //), |
|
| 1458 | + ); |
|
| 1459 | + ob_start(); |
|
| 1460 | + do_action( |
|
| 1461 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
| 1462 | + $this->_cpt_model_obj |
|
| 1463 | + ); |
|
| 1464 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
| 1465 | + // load template |
|
| 1466 | + EEH_Template::display_template( |
|
| 1467 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1468 | + $publish_box_extra_args |
|
| 1469 | + ); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + |
|
| 1474 | + /** |
|
| 1475 | + * This just returns whatever is set as the _event object property |
|
| 1476 | + * //todo this will become obsolete once the models are in place |
|
| 1477 | + * |
|
| 1478 | + * @return object |
|
| 1479 | + */ |
|
| 1480 | + public function get_event_object() |
|
| 1481 | + { |
|
| 1482 | + return $this->_cpt_model_obj; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + |
|
| 1486 | + |
|
| 1487 | + |
|
| 1488 | + /** METABOXES * */ |
|
| 1489 | + /** |
|
| 1490 | + * _register_event_editor_meta_boxes |
|
| 1491 | + * add all metaboxes related to the event_editor |
|
| 1492 | + * |
|
| 1493 | + * @return void |
|
| 1494 | + */ |
|
| 1495 | + protected function _register_event_editor_meta_boxes() |
|
| 1496 | + { |
|
| 1497 | + $this->verify_cpt_object(); |
|
| 1498 | + add_meta_box( |
|
| 1499 | + 'espresso_event_editor_tickets', |
|
| 1500 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
| 1501 | + array($this, 'ticket_metabox'), |
|
| 1502 | + $this->page_slug, |
|
| 1503 | + 'normal', |
|
| 1504 | + 'high' |
|
| 1505 | + ); |
|
| 1506 | + add_meta_box( |
|
| 1507 | + 'espresso_event_editor_event_options', |
|
| 1508 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
| 1509 | + array($this, 'registration_options_meta_box'), |
|
| 1510 | + $this->page_slug, |
|
| 1511 | + 'side', |
|
| 1512 | + 'default' |
|
| 1513 | + ); |
|
| 1514 | + // NOTE: if you're looking for other metaboxes in here, |
|
| 1515 | + // where a metabox has a related management page in the admin |
|
| 1516 | + // you will find it setup in the related management page's "_Hooks" file. |
|
| 1517 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + |
|
| 1521 | + |
|
| 1522 | + public function ticket_metabox() |
|
| 1523 | + { |
|
| 1524 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
| 1525 | + //defaults for template args |
|
| 1526 | + $template_args = array( |
|
| 1527 | + 'existing_datetime_ids' => '', |
|
| 1528 | + 'event_datetime_help_link' => '', |
|
| 1529 | + 'ticket_options_help_link' => '', |
|
| 1530 | + 'time' => null, |
|
| 1531 | + 'ticket_rows' => '', |
|
| 1532 | + 'existing_ticket_ids' => '', |
|
| 1533 | + 'total_ticket_rows' => 1, |
|
| 1534 | + 'ticket_js_structure' => '', |
|
| 1535 | + 'trash_icon' => 'ee-lock-icon', |
|
| 1536 | + 'disabled' => '', |
|
| 1537 | + ); |
|
| 1538 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
| 1539 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1540 | + /** |
|
| 1541 | + * 1. Start with retrieving Datetimes |
|
| 1542 | + * 2. Fore each datetime get related tickets |
|
| 1543 | + * 3. For each ticket get related prices |
|
| 1544 | + */ |
|
| 1545 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
| 1546 | + /** @type EE_Datetime $first_datetime */ |
|
| 1547 | + $first_datetime = reset($times); |
|
| 1548 | + //do we get related tickets? |
|
| 1549 | + if ($first_datetime instanceof EE_Datetime |
|
| 1550 | + && $first_datetime->ID() !== 0 |
|
| 1551 | + ) { |
|
| 1552 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
| 1553 | + $template_args['time'] = $first_datetime; |
|
| 1554 | + $related_tickets = $first_datetime->tickets( |
|
| 1555 | + array( |
|
| 1556 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
| 1557 | + 'default_where_conditions' => 'none', |
|
| 1558 | + ) |
|
| 1559 | + ); |
|
| 1560 | + if ( ! empty($related_tickets)) { |
|
| 1561 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
| 1562 | + $row = 0; |
|
| 1563 | + foreach ($related_tickets as $ticket) { |
|
| 1564 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
| 1565 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
| 1566 | + $row++; |
|
| 1567 | + } |
|
| 1568 | + } else { |
|
| 1569 | + $template_args['total_ticket_rows'] = 1; |
|
| 1570 | + /** @type EE_Ticket $ticket */ |
|
| 1571 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
| 1572 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
| 1573 | + } |
|
| 1574 | + } else { |
|
| 1575 | + $template_args['time'] = $times[0]; |
|
| 1576 | + /** @type EE_Ticket $ticket */ |
|
| 1577 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
| 1578 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
| 1579 | + // NOTE: we're just sending the first default row |
|
| 1580 | + // (decaf can't manage default tickets so this should be sufficient); |
|
| 1581 | + } |
|
| 1582 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
| 1583 | + 'event_editor_event_datetimes_help_tab' |
|
| 1584 | + ); |
|
| 1585 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
| 1586 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1587 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1588 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
| 1589 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
| 1590 | + true |
|
| 1591 | + ); |
|
| 1592 | + $template = apply_filters( |
|
| 1593 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
| 1594 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1595 | + ); |
|
| 1596 | + EEH_Template::display_template($template, $template_args); |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + |
|
| 1600 | + |
|
| 1601 | + /** |
|
| 1602 | + * Setup an individual ticket form for the decaf event editor page |
|
| 1603 | + * |
|
| 1604 | + * @access private |
|
| 1605 | + * @param EE_Ticket $ticket the ticket object |
|
| 1606 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
| 1607 | + * @param int $row |
|
| 1608 | + * @return string generated html for the ticket row. |
|
| 1609 | + */ |
|
| 1610 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
| 1611 | + { |
|
| 1612 | + $template_args = array( |
|
| 1613 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1614 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
| 1615 | + : '', |
|
| 1616 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
| 1617 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
| 1618 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
| 1619 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
| 1620 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
| 1621 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
| 1622 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1623 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1624 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
| 1625 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
| 1626 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
| 1627 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
| 1628 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
| 1629 | + : ' disabled=disabled', |
|
| 1630 | + ); |
|
| 1631 | + $price = $ticket->ID() !== 0 |
|
| 1632 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
| 1633 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
| 1634 | + $price_args = array( |
|
| 1635 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1636 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
| 1637 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
| 1638 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
| 1639 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
| 1640 | + ); |
|
| 1641 | + //make sure we have default start and end dates if skeleton |
|
| 1642 | + //handle rows that should NOT be empty |
|
| 1643 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1644 | + //if empty then the start date will be now. |
|
| 1645 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
| 1646 | + } |
|
| 1647 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1648 | + //get the earliest datetime (if present); |
|
| 1649 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
| 1650 | + ? $this->_cpt_model_obj->get_first_related( |
|
| 1651 | + 'Datetime', |
|
| 1652 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1653 | + ) |
|
| 1654 | + : null; |
|
| 1655 | + if ( ! empty($earliest_dtt)) { |
|
| 1656 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
| 1657 | + } else { |
|
| 1658 | + $template_args['TKT_end_date'] = date( |
|
| 1659 | + 'Y-m-d h:i a', |
|
| 1660 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
| 1661 | + ); |
|
| 1662 | + } |
|
| 1663 | + } |
|
| 1664 | + $template_args = array_merge($template_args, $price_args); |
|
| 1665 | + $template = apply_filters( |
|
| 1666 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
| 1667 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | + $ticket |
|
| 1669 | + ); |
|
| 1670 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + |
|
| 1674 | + |
|
| 1675 | + public function registration_options_meta_box() |
|
| 1676 | + { |
|
| 1677 | + $yes_no_values = array( |
|
| 1678 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
| 1679 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
| 1680 | + ); |
|
| 1681 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
| 1682 | + array( |
|
| 1683 | + EEM_Registration::status_id_cancelled, |
|
| 1684 | + EEM_Registration::status_id_declined, |
|
| 1685 | + EEM_Registration::status_id_incomplete, |
|
| 1686 | + ), |
|
| 1687 | + true |
|
| 1688 | + ); |
|
| 1689 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
| 1690 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
| 1691 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
| 1692 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
| 1693 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
| 1694 | + 'default_reg_status', |
|
| 1695 | + $default_reg_status_values, |
|
| 1696 | + $this->_cpt_model_obj->default_registration_status() |
|
| 1697 | + ); |
|
| 1698 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
| 1699 | + 'display_desc', |
|
| 1700 | + $yes_no_values, |
|
| 1701 | + $this->_cpt_model_obj->display_description() |
|
| 1702 | + ); |
|
| 1703 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
| 1704 | + 'display_ticket_selector', |
|
| 1705 | + $yes_no_values, |
|
| 1706 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
| 1707 | + '', |
|
| 1708 | + '', |
|
| 1709 | + false |
|
| 1710 | + ); |
|
| 1711 | + $template_args['additional_registration_options'] = apply_filters( |
|
| 1712 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
| 1713 | + '', |
|
| 1714 | + $template_args, |
|
| 1715 | + $yes_no_values, |
|
| 1716 | + $default_reg_status_values |
|
| 1717 | + ); |
|
| 1718 | + EEH_Template::display_template( |
|
| 1719 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1720 | + $template_args |
|
| 1721 | + ); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + |
|
| 1725 | + |
|
| 1726 | + /** |
|
| 1727 | + * _get_events() |
|
| 1728 | + * This method simply returns all the events (for the given _view and paging) |
|
| 1729 | + * |
|
| 1730 | + * @access public |
|
| 1731 | + * @param int $per_page count of items per page (20 default); |
|
| 1732 | + * @param int $current_page what is the current page being viewed. |
|
| 1733 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
| 1734 | + * If FALSE then we return an array of event objects |
|
| 1735 | + * that match the given _view and paging parameters. |
|
| 1736 | + * @return array an array of event objects. |
|
| 1737 | + */ |
|
| 1738 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
| 1739 | + { |
|
| 1740 | + $EEME = $this->_event_model(); |
|
| 1741 | + $offset = ($current_page - 1) * $per_page; |
|
| 1742 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1743 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
| 1744 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
| 1745 | + if (isset($this->_req_data['month_range'])) { |
|
| 1746 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
| 1747 | + //simulate the FIRST day of the month, that fixes issues for months like February |
|
| 1748 | + //where PHP doesn't know what to assume for date. |
|
| 1749 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
| 1750 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
| 1751 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
| 1752 | + } |
|
| 1753 | + $where = array(); |
|
| 1754 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
| 1755 | + //determine what post_status our condition will have for the query. |
|
| 1756 | + switch ($status) { |
|
| 1757 | + case 'month' : |
|
| 1758 | + case 'today' : |
|
| 1759 | + case null : |
|
| 1760 | + case 'all' : |
|
| 1761 | + break; |
|
| 1762 | + case 'draft' : |
|
| 1763 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
| 1764 | + break; |
|
| 1765 | + default : |
|
| 1766 | + $where['status'] = $status; |
|
| 1767 | + } |
|
| 1768 | + //categories? |
|
| 1769 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
| 1770 | + ? $this->_req_data['EVT_CAT'] : null; |
|
| 1771 | + if ( ! empty ($category)) { |
|
| 1772 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1773 | + $where['Term_Taxonomy.term_id'] = $category; |
|
| 1774 | + } |
|
| 1775 | + //date where conditions |
|
| 1776 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
| 1777 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
| 1778 | + $DateTime = new DateTime( |
|
| 1779 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1780 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
| 1781 | + ); |
|
| 1782 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
| 1783 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
| 1784 | + ->format('t'))->setTime(23, 59, 59) |
|
| 1785 | + ->format(implode(' ', $start_formats)); |
|
| 1786 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1787 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
| 1788 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1789 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1790 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
| 1791 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1792 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
| 1793 | + $now = date('Y-m-01'); |
|
| 1794 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
| 1795 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
| 1796 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
| 1797 | + ->setTime(23, 59, 59) |
|
| 1798 | + ->format(implode(' ', $start_formats)); |
|
| 1799 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
| 1800 | + } |
|
| 1801 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
| 1802 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
| 1803 | + } else { |
|
| 1804 | + if ( ! isset($where['status'])) { |
|
| 1805 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
| 1806 | + $where['OR'] = array( |
|
| 1807 | + 'status*restrict_private' => array('!=', 'private'), |
|
| 1808 | + 'AND' => array( |
|
| 1809 | + 'status*inclusive' => array('=', 'private'), |
|
| 1810 | + 'EVT_wp_user' => get_current_user_id(), |
|
| 1811 | + ), |
|
| 1812 | + ); |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1815 | + } |
|
| 1816 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
| 1817 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
| 1818 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
| 1819 | + ) { |
|
| 1820 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
| 1821 | + } |
|
| 1822 | + } |
|
| 1823 | + //search query handling |
|
| 1824 | + if (isset($this->_req_data['s'])) { |
|
| 1825 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1826 | + $where['OR'] = array( |
|
| 1827 | + 'EVT_name' => array('LIKE', $search_string), |
|
| 1828 | + 'EVT_desc' => array('LIKE', $search_string), |
|
| 1829 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
| 1830 | + ); |
|
| 1831 | + } |
|
| 1832 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
| 1833 | + $query_params = apply_filters( |
|
| 1834 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
| 1835 | + array( |
|
| 1836 | + $where, |
|
| 1837 | + 'limit' => $limit, |
|
| 1838 | + 'order_by' => $orderby, |
|
| 1839 | + 'order' => $order, |
|
| 1840 | + 'group_by' => 'EVT_ID', |
|
| 1841 | + ), |
|
| 1842 | + $this->_req_data |
|
| 1843 | + ); |
|
| 1844 | + //let's first check if we have special requests coming in. |
|
| 1845 | + if (isset($this->_req_data['active_status'])) { |
|
| 1846 | + switch ($this->_req_data['active_status']) { |
|
| 1847 | + case 'upcoming' : |
|
| 1848 | + return $EEME->get_upcoming_events($query_params, $count); |
|
| 1849 | + break; |
|
| 1850 | + case 'expired' : |
|
| 1851 | + return $EEME->get_expired_events($query_params, $count); |
|
| 1852 | + break; |
|
| 1853 | + case 'active' : |
|
| 1854 | + return $EEME->get_active_events($query_params, $count); |
|
| 1855 | + break; |
|
| 1856 | + case 'inactive' : |
|
| 1857 | + return $EEME->get_inactive_events($query_params, $count); |
|
| 1858 | + break; |
|
| 1859 | + } |
|
| 1860 | + } |
|
| 1861 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
| 1862 | + return $events; |
|
| 1863 | + } |
|
| 1864 | + |
|
| 1865 | + |
|
| 1866 | + |
|
| 1867 | + /** |
|
| 1868 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
| 1869 | + * |
|
| 1870 | + * @param string $post_id |
|
| 1871 | + */ |
|
| 1872 | + public function trash_cpt_item($post_id) |
|
| 1873 | + { |
|
| 1874 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1875 | + $this->_trash_or_restore_event('trash', false); |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * @param string $post_id |
|
| 1882 | + */ |
|
| 1883 | + public function restore_cpt_item($post_id) |
|
| 1884 | + { |
|
| 1885 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1886 | + $this->_trash_or_restore_event('draft', false); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + |
|
| 1890 | + |
|
| 1891 | + /** |
|
| 1892 | + * @param string $post_id |
|
| 1893 | + */ |
|
| 1894 | + public function delete_cpt_item($post_id) |
|
| 1895 | + { |
|
| 1896 | + $this->_req_data['EVT_ID'] = $post_id; |
|
| 1897 | + $this->_delete_event(false); |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * _trash_or_restore_event |
|
| 1904 | + * |
|
| 1905 | + * @access protected |
|
| 1906 | + * @param string $event_status |
|
| 1907 | + * @param bool $redirect_after |
|
| 1908 | + */ |
|
| 1909 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
| 1910 | + { |
|
| 1911 | + //determine the event id and set to array. |
|
| 1912 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
| 1913 | + // loop thru events |
|
| 1914 | + if ($EVT_ID) { |
|
| 1915 | + // clean status |
|
| 1916 | + $event_status = sanitize_key($event_status); |
|
| 1917 | + // grab status |
|
| 1918 | + if ( ! empty($event_status)) { |
|
| 1919 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1920 | + } else { |
|
| 1921 | + $success = false; |
|
| 1922 | + $msg = esc_html__( |
|
| 1923 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1924 | + 'event_espresso' |
|
| 1925 | + ); |
|
| 1926 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1927 | + } |
|
| 1928 | + } else { |
|
| 1929 | + $success = false; |
|
| 1930 | + $msg = esc_html__( |
|
| 1931 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1932 | + 'event_espresso' |
|
| 1933 | + ); |
|
| 1934 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1935 | + } |
|
| 1936 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1937 | + if ($redirect_after) { |
|
| 1938 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
| 1939 | + } |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * _trash_or_restore_events |
|
| 1946 | + * |
|
| 1947 | + * @access protected |
|
| 1948 | + * @param string $event_status |
|
| 1949 | + * @return void |
|
| 1950 | + */ |
|
| 1951 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
| 1952 | + { |
|
| 1953 | + // clean status |
|
| 1954 | + $event_status = sanitize_key($event_status); |
|
| 1955 | + // grab status |
|
| 1956 | + if ( ! empty($event_status)) { |
|
| 1957 | + $success = true; |
|
| 1958 | + //determine the event id and set to array. |
|
| 1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | + // loop thru events |
|
| 1961 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 1962 | + if ($EVT_ID = absint($EVT_ID)) { |
|
| 1963 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
| 1964 | + $success = $results !== false ? $success : false; |
|
| 1965 | + } else { |
|
| 1966 | + $msg = sprintf( |
|
| 1967 | + esc_html__( |
|
| 1968 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
| 1969 | + 'event_espresso' |
|
| 1970 | + ), |
|
| 1971 | + $EVT_ID |
|
| 1972 | + ); |
|
| 1973 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1974 | + $success = false; |
|
| 1975 | + } |
|
| 1976 | + } |
|
| 1977 | + } else { |
|
| 1978 | + $success = false; |
|
| 1979 | + $msg = esc_html__( |
|
| 1980 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
| 1981 | + 'event_espresso' |
|
| 1982 | + ); |
|
| 1983 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1984 | + } |
|
| 1985 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 1986 | + $success = $success ? 2 : false; |
|
| 1987 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
| 1988 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * _trash_or_restore_events |
|
| 1995 | + * |
|
| 1996 | + * @access private |
|
| 1997 | + * @param int $EVT_ID |
|
| 1998 | + * @param string $event_status |
|
| 1999 | + * @return bool |
|
| 2000 | + */ |
|
| 2001 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
| 2002 | + { |
|
| 2003 | + // grab event id |
|
| 2004 | + if ( ! $EVT_ID) { |
|
| 2005 | + $msg = esc_html__( |
|
| 2006 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2007 | + 'event_espresso' |
|
| 2008 | + ); |
|
| 2009 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2010 | + return false; |
|
| 2011 | + } |
|
| 2012 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2013 | + // clean status |
|
| 2014 | + $event_status = sanitize_key($event_status); |
|
| 2015 | + // grab status |
|
| 2016 | + if (empty($event_status)) { |
|
| 2017 | + $msg = esc_html__( |
|
| 2018 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
| 2019 | + 'event_espresso' |
|
| 2020 | + ); |
|
| 2021 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2022 | + return false; |
|
| 2023 | + } |
|
| 2024 | + // was event trashed or restored ? |
|
| 2025 | + switch ($event_status) { |
|
| 2026 | + case 'draft' : |
|
| 2027 | + $action = 'restored from the trash'; |
|
| 2028 | + $hook = 'AHEE_event_restored_from_trash'; |
|
| 2029 | + break; |
|
| 2030 | + case 'trash' : |
|
| 2031 | + $action = 'moved to the trash'; |
|
| 2032 | + $hook = 'AHEE_event_moved_to_trash'; |
|
| 2033 | + break; |
|
| 2034 | + default : |
|
| 2035 | + $action = 'updated'; |
|
| 2036 | + $hook = false; |
|
| 2037 | + } |
|
| 2038 | + //use class to change status |
|
| 2039 | + $this->_cpt_model_obj->set_status($event_status); |
|
| 2040 | + $success = $this->_cpt_model_obj->save(); |
|
| 2041 | + if ($success === false) { |
|
| 2042 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
| 2043 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2044 | + return false; |
|
| 2045 | + } |
|
| 2046 | + if ($hook) { |
|
| 2047 | + do_action($hook); |
|
| 2048 | + } |
|
| 2049 | + return true; |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + |
|
| 2054 | + /** |
|
| 2055 | + * _delete_event |
|
| 2056 | + * |
|
| 2057 | + * @access protected |
|
| 2058 | + * @param bool $redirect_after |
|
| 2059 | + */ |
|
| 2060 | + protected function _delete_event($redirect_after = true) |
|
| 2061 | + { |
|
| 2062 | + //determine the event id and set to array. |
|
| 2063 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
| 2064 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
| 2065 | + // loop thru events |
|
| 2066 | + if ($EVT_ID) { |
|
| 2067 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
| 2068 | + // get list of events with no prices |
|
| 2069 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2070 | + // remove this event from the list of events with no prices |
|
| 2071 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
| 2072 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2073 | + } |
|
| 2074 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2075 | + } else { |
|
| 2076 | + $success = false; |
|
| 2077 | + $msg = esc_html__( |
|
| 2078 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2079 | + 'event_espresso' |
|
| 2080 | + ); |
|
| 2081 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2082 | + } |
|
| 2083 | + if ($redirect_after) { |
|
| 2084 | + $this->_redirect_after_action( |
|
| 2085 | + $success, |
|
| 2086 | + 'Event', |
|
| 2087 | + 'deleted', |
|
| 2088 | + array('action' => 'default', 'status' => 'trash') |
|
| 2089 | + ); |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + |
|
| 2093 | + |
|
| 2094 | + |
|
| 2095 | + /** |
|
| 2096 | + * _delete_events |
|
| 2097 | + * |
|
| 2098 | + * @access protected |
|
| 2099 | + * @return void |
|
| 2100 | + */ |
|
| 2101 | + protected function _delete_events() |
|
| 2102 | + { |
|
| 2103 | + $success = true; |
|
| 2104 | + // get list of events with no prices |
|
| 2105 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
| 2106 | + //determine the event id and set to array. |
|
| 2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | + // loop thru events |
|
| 2109 | + foreach ($EVT_IDs as $EVT_ID) { |
|
| 2110 | + $EVT_ID = absint($EVT_ID); |
|
| 2111 | + if ($EVT_ID) { |
|
| 2112 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
| 2113 | + $success = $results !== false ? $success : false; |
|
| 2114 | + // remove this event from the list of events with no prices |
|
| 2115 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
| 2116 | + } else { |
|
| 2117 | + $success = false; |
|
| 2118 | + $msg = esc_html__( |
|
| 2119 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
| 2120 | + 'event_espresso' |
|
| 2121 | + ); |
|
| 2122 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2123 | + } |
|
| 2124 | + } |
|
| 2125 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
| 2126 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
| 2127 | + $success = $success ? 2 : false; |
|
| 2128 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + |
|
| 2132 | + |
|
| 2133 | + /** |
|
| 2134 | + * _permanently_delete_event |
|
| 2135 | + * |
|
| 2136 | + * @access private |
|
| 2137 | + * @param int $EVT_ID |
|
| 2138 | + * @return bool |
|
| 2139 | + */ |
|
| 2140 | + private function _permanently_delete_event($EVT_ID = 0) |
|
| 2141 | + { |
|
| 2142 | + // grab event id |
|
| 2143 | + if ( ! $EVT_ID) { |
|
| 2144 | + $msg = esc_html__( |
|
| 2145 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
| 2146 | + 'event_espresso' |
|
| 2147 | + ); |
|
| 2148 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2149 | + return false; |
|
| 2150 | + } |
|
| 2151 | + if ( |
|
| 2152 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
| 2153 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
| 2154 | + ) { |
|
| 2155 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2156 | + } |
|
| 2157 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
| 2158 | + return false; |
|
| 2159 | + } |
|
| 2160 | + //need to delete related tickets and prices first. |
|
| 2161 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
| 2162 | + foreach ($datetimes as $datetime) { |
|
| 2163 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
| 2164 | + $tickets = $datetime->get_many_related('Ticket'); |
|
| 2165 | + foreach ($tickets as $ticket) { |
|
| 2166 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
| 2167 | + $ticket->delete_related_permanently('Price'); |
|
| 2168 | + $ticket->delete_permanently(); |
|
| 2169 | + } |
|
| 2170 | + $datetime->delete(); |
|
| 2171 | + } |
|
| 2172 | + //what about related venues or terms? |
|
| 2173 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
| 2174 | + foreach ($venues as $venue) { |
|
| 2175 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
| 2176 | + } |
|
| 2177 | + //any attached question groups? |
|
| 2178 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
| 2179 | + if ( ! empty($question_groups)) { |
|
| 2180 | + foreach ($question_groups as $question_group) { |
|
| 2181 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + //Message Template Groups |
|
| 2185 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
| 2186 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
| 2187 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
| 2188 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
| 2189 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
| 2190 | + } |
|
| 2191 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
| 2192 | + // did it all go as planned ? |
|
| 2193 | + if ($success) { |
|
| 2194 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
| 2195 | + EE_Error::add_success($msg); |
|
| 2196 | + } else { |
|
| 2197 | + $msg = sprintf( |
|
| 2198 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
| 2199 | + $EVT_ID |
|
| 2200 | + ); |
|
| 2201 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2202 | + return false; |
|
| 2203 | + } |
|
| 2204 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
| 2205 | + return true; |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + |
|
| 2209 | + |
|
| 2210 | + /** |
|
| 2211 | + * get total number of events |
|
| 2212 | + * |
|
| 2213 | + * @access public |
|
| 2214 | + * @return int |
|
| 2215 | + */ |
|
| 2216 | + public function total_events() |
|
| 2217 | + { |
|
| 2218 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2219 | + return $count; |
|
| 2220 | + } |
|
| 2221 | + |
|
| 2222 | + |
|
| 2223 | + |
|
| 2224 | + /** |
|
| 2225 | + * get total number of draft events |
|
| 2226 | + * |
|
| 2227 | + * @access public |
|
| 2228 | + * @return int |
|
| 2229 | + */ |
|
| 2230 | + public function total_events_draft() |
|
| 2231 | + { |
|
| 2232 | + $where = array( |
|
| 2233 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
| 2234 | + ); |
|
| 2235 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2236 | + return $count; |
|
| 2237 | + } |
|
| 2238 | + |
|
| 2239 | + |
|
| 2240 | + |
|
| 2241 | + /** |
|
| 2242 | + * get total number of trashed events |
|
| 2243 | + * |
|
| 2244 | + * @access public |
|
| 2245 | + * @return int |
|
| 2246 | + */ |
|
| 2247 | + public function total_trashed_events() |
|
| 2248 | + { |
|
| 2249 | + $where = array( |
|
| 2250 | + 'status' => 'trash', |
|
| 2251 | + ); |
|
| 2252 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
| 2253 | + return $count; |
|
| 2254 | + } |
|
| 2255 | + |
|
| 2256 | + |
|
| 2257 | + /** |
|
| 2258 | + * _default_event_settings |
|
| 2259 | + * This generates the Default Settings Tab |
|
| 2260 | + * |
|
| 2261 | + * @return void |
|
| 2262 | + * @throws \EE_Error |
|
| 2263 | + */ |
|
| 2264 | + protected function _default_event_settings() |
|
| 2265 | + { |
|
| 2266 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
| 2267 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 2268 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
| 2269 | + $this->display_admin_page_with_sidebar(); |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + |
|
| 2273 | + /** |
|
| 2274 | + * Return the form for event settings. |
|
| 2275 | + * @return \EE_Form_Section_Proper |
|
| 2276 | + */ |
|
| 2277 | + protected function _default_event_settings_form() |
|
| 2278 | + { |
|
| 2279 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2280 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
| 2281 | + //exclude |
|
| 2282 | + array( |
|
| 2283 | + EEM_Registration::status_id_cancelled, |
|
| 2284 | + EEM_Registration::status_id_declined, |
|
| 2285 | + EEM_Registration::status_id_incomplete, |
|
| 2286 | + EEM_Registration::status_id_wait_list, |
|
| 2287 | + ), |
|
| 2288 | + true |
|
| 2289 | + ); |
|
| 2290 | + return new EE_Form_Section_Proper( |
|
| 2291 | + array( |
|
| 2292 | + 'name' => 'update_default_event_settings', |
|
| 2293 | + 'html_id' => 'update_default_event_settings', |
|
| 2294 | + 'html_class' => 'form-table', |
|
| 2295 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 2296 | + 'subsections' => apply_filters( |
|
| 2297 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
| 2298 | + array( |
|
| 2299 | + 'default_reg_status' => new EE_Select_Input( |
|
| 2300 | + $registration_stati_for_selection, |
|
| 2301 | + array( |
|
| 2302 | + 'default' => isset($registration_config->default_STS_ID) |
|
| 2303 | + && array_key_exists( |
|
| 2304 | + $registration_config->default_STS_ID, |
|
| 2305 | + $registration_stati_for_selection |
|
| 2306 | + ) |
|
| 2307 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
| 2308 | + : EEM_Registration::status_id_pending_payment, |
|
| 2309 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
| 2310 | + . EEH_Template::get_help_tab_link( |
|
| 2311 | + 'default_settings_status_help_tab' |
|
| 2312 | + ), |
|
| 2313 | + 'html_help_text' => esc_html__( |
|
| 2314 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
| 2315 | + 'event_espresso' |
|
| 2316 | + ) |
|
| 2317 | + ) |
|
| 2318 | + ), |
|
| 2319 | + 'default_max_tickets' => new EE_Integer_Input( |
|
| 2320 | + array( |
|
| 2321 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
| 2322 | + ? $registration_config->default_maximum_number_of_tickets |
|
| 2323 | + : EEM_Event::get_default_additional_limit(), |
|
| 2324 | + 'html_label_text' => esc_html__( |
|
| 2325 | + 'Default Maximum Tickets Allowed Per Order:', |
|
| 2326 | + 'event_espresso' |
|
| 2327 | + ) . EEH_Template::get_help_tab_link( |
|
| 2328 | + 'default_maximum_tickets_help_tab"' |
|
| 2329 | + ), |
|
| 2330 | + 'html_help_text' => esc_html__( |
|
| 2331 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
| 2332 | + 'event_espresso' |
|
| 2333 | + ) |
|
| 2334 | + ) |
|
| 2335 | + ) |
|
| 2336 | + ) |
|
| 2337 | + ) |
|
| 2338 | + ) |
|
| 2339 | + ); |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + |
|
| 2343 | + /** |
|
| 2344 | + * _update_default_event_settings |
|
| 2345 | + * |
|
| 2346 | + * @access protected |
|
| 2347 | + * @return void |
|
| 2348 | + * @throws \EE_Error |
|
| 2349 | + */ |
|
| 2350 | + protected function _update_default_event_settings() |
|
| 2351 | + { |
|
| 2352 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
| 2353 | + $form = $this->_default_event_settings_form(); |
|
| 2354 | + if ($form->was_submitted()) { |
|
| 2355 | + $form->receive_form_submission(); |
|
| 2356 | + if ($form->is_valid()) { |
|
| 2357 | + $valid_data = $form->valid_data(); |
|
| 2358 | + if (isset($valid_data['default_reg_status'])) { |
|
| 2359 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
| 2360 | + } |
|
| 2361 | + if (isset($valid_data['default_max_tickets'])) { |
|
| 2362 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
| 2363 | + } |
|
| 2364 | + //update because data was valid! |
|
| 2365 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
| 2366 | + EE_Error::overwrite_success(); |
|
| 2367 | + EE_Error::add_success( |
|
| 2368 | + __('Default Event Settings were updated', 'event_espresso') |
|
| 2369 | + ); |
|
| 2370 | + } |
|
| 2371 | + } |
|
| 2372 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + |
|
| 2377 | + /************* Templates *************/ |
|
| 2378 | + protected function _template_settings() |
|
| 2379 | + { |
|
| 2380 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
| 2381 | + $this->_template_args['preview_img'] = '<img src="' |
|
| 2382 | + . EVENTS_ASSETS_URL |
|
| 2383 | + . DS |
|
| 2384 | + . 'images' |
|
| 2385 | + . DS |
|
| 2386 | + . 'caffeinated_template_features.jpg" alt="' |
|
| 2387 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
| 2388 | + . '" />'; |
|
| 2389 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2390 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
| 2391 | + 'event_espresso' |
|
| 2392 | + ) . '</strong>'; |
|
| 2393 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
| 2394 | + } |
|
| 2395 | + |
|
| 2396 | + |
|
| 2397 | + /** Event Category Stuff **/ |
|
| 2398 | + /** |
|
| 2399 | + * set the _category property with the category object for the loaded page. |
|
| 2400 | + * |
|
| 2401 | + * @access private |
|
| 2402 | + * @return void |
|
| 2403 | + */ |
|
| 2404 | + private function _set_category_object() |
|
| 2405 | + { |
|
| 2406 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
| 2407 | + return; |
|
| 2408 | + } //already have the category object so get out. |
|
| 2409 | + //set default category object |
|
| 2410 | + $this->_set_empty_category_object(); |
|
| 2411 | + //only set if we've got an id |
|
| 2412 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
| 2413 | + return; |
|
| 2414 | + } |
|
| 2415 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
| 2416 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
| 2417 | + if ( ! empty($term)) { |
|
| 2418 | + $this->_category->category_name = $term->name; |
|
| 2419 | + $this->_category->category_identifier = $term->slug; |
|
| 2420 | + $this->_category->category_desc = $term->description; |
|
| 2421 | + $this->_category->id = $term->term_id; |
|
| 2422 | + $this->_category->parent = $term->parent; |
|
| 2423 | + } |
|
| 2424 | + } |
|
| 2425 | + |
|
| 2426 | + |
|
| 2427 | + |
|
| 2428 | + private function _set_empty_category_object() |
|
| 2429 | + { |
|
| 2430 | + $this->_category = new stdClass(); |
|
| 2431 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
| 2432 | + $this->_category->id = $this->_category->parent = 0; |
|
| 2433 | + } |
|
| 2434 | + |
|
| 2435 | + |
|
| 2436 | + |
|
| 2437 | + protected function _category_list_table() |
|
| 2438 | + { |
|
| 2439 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2440 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
| 2441 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2442 | + 'add_category', |
|
| 2443 | + 'add_category', |
|
| 2444 | + array(), |
|
| 2445 | + 'add-new-h2' |
|
| 2446 | + ); |
|
| 2447 | + $this->display_admin_list_table_page_with_sidebar(); |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * @param $view |
|
| 2454 | + */ |
|
| 2455 | + protected function _category_details($view) |
|
| 2456 | + { |
|
| 2457 | + //load formatter helper |
|
| 2458 | + //load field generator helper |
|
| 2459 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
| 2460 | + $this->_set_add_edit_form_tags($route); |
|
| 2461 | + $this->_set_category_object(); |
|
| 2462 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
| 2463 | + $delete_action = 'delete_category'; |
|
| 2464 | + //custom redirect |
|
| 2465 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2466 | + array('action' => 'category_list'), |
|
| 2467 | + $this->_admin_base_url |
|
| 2468 | + ); |
|
| 2469 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
| 2470 | + //take care of contents |
|
| 2471 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
| 2472 | + $this->display_admin_page_with_sidebar(); |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + /** |
|
| 2478 | + * @return mixed |
|
| 2479 | + */ |
|
| 2480 | + protected function _category_details_content() |
|
| 2481 | + { |
|
| 2482 | + $editor_args['category_desc'] = array( |
|
| 2483 | + 'type' => 'wp_editor', |
|
| 2484 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
| 2485 | + 'class' => 'my_editor_custom', |
|
| 2486 | + 'wpeditor_args' => array('media_buttons' => false), |
|
| 2487 | + ); |
|
| 2488 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
| 2489 | + $all_terms = get_terms( |
|
| 2490 | + array('espresso_event_categories'), |
|
| 2491 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
| 2492 | + ); |
|
| 2493 | + //setup category select for term parents. |
|
| 2494 | + $category_select_values[] = array( |
|
| 2495 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
| 2496 | + 'id' => 0, |
|
| 2497 | + ); |
|
| 2498 | + foreach ($all_terms as $term) { |
|
| 2499 | + $category_select_values[] = array( |
|
| 2500 | + 'text' => $term->name, |
|
| 2501 | + 'id' => $term->term_id, |
|
| 2502 | + ); |
|
| 2503 | + } |
|
| 2504 | + $category_select = EEH_Form_Fields::select_input( |
|
| 2505 | + 'category_parent', |
|
| 2506 | + $category_select_values, |
|
| 2507 | + $this->_category->parent |
|
| 2508 | + ); |
|
| 2509 | + $template_args = array( |
|
| 2510 | + 'category' => $this->_category, |
|
| 2511 | + 'category_select' => $category_select, |
|
| 2512 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
| 2513 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
| 2514 | + 'disable' => '', |
|
| 2515 | + 'disabled_message' => false, |
|
| 2516 | + ); |
|
| 2517 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2518 | + return EEH_Template::display_template($template, $template_args, true); |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + |
|
| 2522 | + |
|
| 2523 | + protected function _delete_categories() |
|
| 2524 | + { |
|
| 2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | + : (array)$this->_req_data['category_id']; |
|
| 2527 | + foreach ($cat_ids as $cat_id) { |
|
| 2528 | + $this->_delete_category($cat_id); |
|
| 2529 | + } |
|
| 2530 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
| 2531 | + $query_args = array( |
|
| 2532 | + 'action' => 'category_list', |
|
| 2533 | + ); |
|
| 2534 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + /** |
|
| 2540 | + * @param $cat_id |
|
| 2541 | + */ |
|
| 2542 | + protected function _delete_category($cat_id) |
|
| 2543 | + { |
|
| 2544 | + $cat_id = absint($cat_id); |
|
| 2545 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
| 2546 | + } |
|
| 2547 | + |
|
| 2548 | + |
|
| 2549 | + |
|
| 2550 | + /** |
|
| 2551 | + * @param $new_category |
|
| 2552 | + */ |
|
| 2553 | + protected function _insert_or_update_category($new_category) |
|
| 2554 | + { |
|
| 2555 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
| 2556 | + $success = 0; //we already have a success message so lets not send another. |
|
| 2557 | + if ($cat_id) { |
|
| 2558 | + $query_args = array( |
|
| 2559 | + 'action' => 'edit_category', |
|
| 2560 | + 'EVT_CAT_ID' => $cat_id, |
|
| 2561 | + ); |
|
| 2562 | + } else { |
|
| 2563 | + $query_args = array('action' => 'add_category'); |
|
| 2564 | + } |
|
| 2565 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
| 2566 | + } |
|
| 2567 | + |
|
| 2568 | + |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * @param bool $update |
|
| 2572 | + * @return bool|mixed|string |
|
| 2573 | + */ |
|
| 2574 | + private function _insert_category($update = false) |
|
| 2575 | + { |
|
| 2576 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
| 2577 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
| 2578 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
| 2579 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
| 2580 | + if (empty($category_name)) { |
|
| 2581 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
| 2582 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2583 | + return false; |
|
| 2584 | + } |
|
| 2585 | + $term_args = array( |
|
| 2586 | + 'name' => $category_name, |
|
| 2587 | + 'description' => $category_desc, |
|
| 2588 | + 'parent' => $category_parent, |
|
| 2589 | + ); |
|
| 2590 | + //was the category_identifier input disabled? |
|
| 2591 | + if (isset($this->_req_data['category_identifier'])) { |
|
| 2592 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
| 2593 | + } |
|
| 2594 | + $insert_ids = $update |
|
| 2595 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
| 2596 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
| 2597 | + if ( ! is_array($insert_ids)) { |
|
| 2598 | + $msg = esc_html__( |
|
| 2599 | + 'An error occurred and the category has not been saved to the database.', |
|
| 2600 | + 'event_espresso' |
|
| 2601 | + ); |
|
| 2602 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2603 | + } else { |
|
| 2604 | + $cat_id = $insert_ids['term_id']; |
|
| 2605 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
| 2606 | + EE_Error::add_success($msg); |
|
| 2607 | + } |
|
| 2608 | + return $cat_id; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + |
|
| 2612 | + |
|
| 2613 | + /** |
|
| 2614 | + * @param int $per_page |
|
| 2615 | + * @param int $current_page |
|
| 2616 | + * @param bool $count |
|
| 2617 | + * @return \EE_Base_Class[]|int |
|
| 2618 | + */ |
|
| 2619 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
| 2620 | + { |
|
| 2621 | + //testing term stuff |
|
| 2622 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
| 2623 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2624 | + $limit = ($current_page - 1) * $per_page; |
|
| 2625 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
| 2626 | + if (isset($this->_req_data['s'])) { |
|
| 2627 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2628 | + $where['OR'] = array( |
|
| 2629 | + 'Term.name' => array('LIKE', $sstr), |
|
| 2630 | + 'description' => array('LIKE', $sstr), |
|
| 2631 | + ); |
|
| 2632 | + } |
|
| 2633 | + $query_params = array( |
|
| 2634 | + $where, |
|
| 2635 | + 'order_by' => array($orderby => $order), |
|
| 2636 | + 'limit' => $limit . ',' . $per_page, |
|
| 2637 | + 'force_join' => array('Term'), |
|
| 2638 | + ); |
|
| 2639 | + $categories = $count |
|
| 2640 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
| 2641 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
| 2642 | + return $categories; |
|
| 2643 | + } |
|
| 2644 | + |
|
| 2645 | + |
|
| 2646 | + |
|
| 2647 | + /* end category stuff */ |
|
| 2648 | + /**************/ |
|
| 2649 | 2649 | } |
| 2650 | 2650 | //end class Events_Admin_Page |
@@ -536,11 +536,11 @@ discard block |
||
| 536 | 536 | { |
| 537 | 537 | wp_register_style( |
| 538 | 538 | 'events-admin-css', |
| 539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
| 539 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
| 540 | 540 | array(), |
| 541 | 541 | EVENT_ESPRESSO_VERSION |
| 542 | 542 | ); |
| 543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
| 544 | 544 | wp_enqueue_style('events-admin-css'); |
| 545 | 545 | wp_enqueue_style('ee-cat-admin'); |
| 546 | 546 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -548,7 +548,7 @@ discard block |
||
| 548 | 548 | //scripts |
| 549 | 549 | wp_register_script( |
| 550 | 550 | 'event_editor_js', |
| 551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
| 551 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
| 552 | 552 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
| 553 | 553 | EVENT_ESPRESSO_VERSION, |
| 554 | 554 | true |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | wp_enqueue_style('espresso-ui-theme'); |
| 581 | 581 | wp_register_style( |
| 582 | 582 | 'event-editor-css', |
| 583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
| 583 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
| 584 | 584 | array('ee-admin-css'), |
| 585 | 585 | EVENT_ESPRESSO_VERSION |
| 586 | 586 | ); |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | //scripts |
| 589 | 589 | wp_register_script( |
| 590 | 590 | 'event-datetime-metabox', |
| 591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
| 591 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
| 592 | 592 | array('event_editor_js', 'ee-datepicker'), |
| 593 | 593 | EVENT_ESPRESSO_VERSION |
| 594 | 594 | ); |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | $event = $this->_cpt_model_obj; |
| 666 | 666 | } |
| 667 | 667 | // STILL no event? |
| 668 | - if (! $event instanceof EE_Event) { |
|
| 668 | + if ( ! $event instanceof EE_Event) { |
|
| 669 | 669 | return; |
| 670 | 670 | } |
| 671 | 671 | $orig_status = $event->status(); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
| 755 | 755 | 'event_espresso' |
| 756 | 756 | ), |
| 757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
| 757 | + '<a href="'.admin_url('options-general.php').'">', |
|
| 758 | 758 | '</a>' |
| 759 | 759 | ), |
| 760 | 760 | __FILE__, |
@@ -824,31 +824,31 @@ discard block |
||
| 824 | 824 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
| 825 | 825 | $statuses = array( |
| 826 | 826 | 'sold_out_status' => array( |
| 827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
| 827 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
| 828 | 828 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
| 829 | 829 | ), |
| 830 | 830 | 'active_status' => array( |
| 831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
| 831 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
| 832 | 832 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
| 833 | 833 | ), |
| 834 | 834 | 'upcoming_status' => array( |
| 835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
| 835 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
| 836 | 836 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
| 837 | 837 | ), |
| 838 | 838 | 'postponed_status' => array( |
| 839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
| 839 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
| 840 | 840 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
| 841 | 841 | ), |
| 842 | 842 | 'cancelled_status' => array( |
| 843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
| 843 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
| 844 | 844 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
| 845 | 845 | ), |
| 846 | 846 | 'expired_status' => array( |
| 847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
| 847 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
| 848 | 848 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
| 849 | 849 | ), |
| 850 | 850 | 'inactive_status' => array( |
| 851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
| 851 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
| 852 | 852 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
| 853 | 853 | ), |
| 854 | 854 | ); |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | { |
| 913 | 913 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 914 | 914 | $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
| 915 | - ? (array)$this->_template_args['after_list_table'] |
|
| 915 | + ? (array) $this->_template_args['after_list_table'] |
|
| 916 | 916 | : array(); |
| 917 | 917 | $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
| 918 | 918 | . EEH_Template::get_button_or_link( |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | 'button' |
| 922 | 922 | ); |
| 923 | 923 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
| 924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 924 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 925 | 925 | 'create_new', |
| 926 | 926 | 'add', |
| 927 | 927 | array(), |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | */ |
| 1052 | 1052 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
| 1053 | 1053 | { |
| 1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
| 1054 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
| 1055 | 1055 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
| 1056 | 1056 | $rows_affected = null; |
| 1057 | 1057 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | if (empty($tkt['TKT_start_date'])) { |
| 1176 | 1176 | //let's use now in the set timezone. |
| 1177 | 1177 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
| 1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
| 1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | if (empty($tkt['TKT_end_date'])) { |
| 1181 | 1181 | //use the start date of the first datetime |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
| 1465 | 1465 | // load template |
| 1466 | 1466 | EEH_Template::display_template( |
| 1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
| 1467 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
| 1468 | 1468 | $publish_box_extra_args |
| 1469 | 1469 | ); |
| 1470 | 1470 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | ); |
| 1592 | 1592 | $template = apply_filters( |
| 1593 | 1593 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
| 1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
| 1594 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
| 1595 | 1595 | ); |
| 1596 | 1596 | EEH_Template::display_template($template, $template_args); |
| 1597 | 1597 | } |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
| 1611 | 1611 | { |
| 1612 | 1612 | $template_args = array( |
| 1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
| 1613 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
| 1614 | 1614 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
| 1615 | 1615 | : '', |
| 1616 | 1616 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1664,7 +1664,7 @@ discard block |
||
| 1664 | 1664 | $template_args = array_merge($template_args, $price_args); |
| 1665 | 1665 | $template = apply_filters( |
| 1666 | 1666 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
| 1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
| 1667 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
| 1668 | 1668 | $ticket |
| 1669 | 1669 | ); |
| 1670 | 1670 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1716,7 +1716,7 @@ discard block |
||
| 1716 | 1716 | $default_reg_status_values |
| 1717 | 1717 | ); |
| 1718 | 1718 | EEH_Template::display_template( |
| 1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
| 1719 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
| 1720 | 1720 | $template_args |
| 1721 | 1721 | ); |
| 1722 | 1722 | } |
@@ -1739,7 +1739,7 @@ discard block |
||
| 1739 | 1739 | { |
| 1740 | 1740 | $EEME = $this->_event_model(); |
| 1741 | 1741 | $offset = ($current_page - 1) * $per_page; |
| 1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
| 1742 | + $limit = $count ? null : $offset.','.$per_page; |
|
| 1743 | 1743 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
| 1744 | 1744 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
| 1745 | 1745 | if (isset($this->_req_data['month_range'])) { |
@@ -1776,7 +1776,7 @@ discard block |
||
| 1776 | 1776 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
| 1777 | 1777 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
| 1778 | 1778 | $DateTime = new DateTime( |
| 1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
| 1779 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
| 1780 | 1780 | new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
| 1781 | 1781 | ); |
| 1782 | 1782 | $start = $DateTime->format(implode(' ', $start_formats)); |
@@ -1822,7 +1822,7 @@ discard block |
||
| 1822 | 1822 | } |
| 1823 | 1823 | //search query handling |
| 1824 | 1824 | if (isset($this->_req_data['s'])) { |
| 1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 1825 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 1826 | 1826 | $where['OR'] = array( |
| 1827 | 1827 | 'EVT_name' => array('LIKE', $search_string), |
| 1828 | 1828 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1956,7 +1956,7 @@ discard block |
||
| 1956 | 1956 | if ( ! empty($event_status)) { |
| 1957 | 1957 | $success = true; |
| 1958 | 1958 | //determine the event id and set to array. |
| 1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 1960 | 1960 | // loop thru events |
| 1961 | 1961 | foreach ($EVT_IDs as $EVT_ID) { |
| 1962 | 1962 | if ($EVT_ID = absint($EVT_ID)) { |
@@ -2104,7 +2104,7 @@ discard block |
||
| 2104 | 2104 | // get list of events with no prices |
| 2105 | 2105 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
| 2106 | 2106 | //determine the event id and set to array. |
| 2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
| 2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
| 2108 | 2108 | // loop thru events |
| 2109 | 2109 | foreach ($EVT_IDs as $EVT_ID) { |
| 2110 | 2110 | $EVT_ID = absint($EVT_ID); |
@@ -2324,7 +2324,7 @@ discard block |
||
| 2324 | 2324 | 'html_label_text' => esc_html__( |
| 2325 | 2325 | 'Default Maximum Tickets Allowed Per Order:', |
| 2326 | 2326 | 'event_espresso' |
| 2327 | - ) . EEH_Template::get_help_tab_link( |
|
| 2327 | + ).EEH_Template::get_help_tab_link( |
|
| 2328 | 2328 | 'default_maximum_tickets_help_tab"' |
| 2329 | 2329 | ), |
| 2330 | 2330 | 'html_help_text' => esc_html__( |
@@ -2386,10 +2386,10 @@ discard block |
||
| 2386 | 2386 | . 'caffeinated_template_features.jpg" alt="' |
| 2387 | 2387 | . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
| 2388 | 2388 | . '" />'; |
| 2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
| 2389 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__( |
|
| 2390 | 2390 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
| 2391 | 2391 | 'event_espresso' |
| 2392 | - ) . '</strong>'; |
|
| 2392 | + ).'</strong>'; |
|
| 2393 | 2393 | $this->display_admin_caf_preview_page('template_settings_tab'); |
| 2394 | 2394 | } |
| 2395 | 2395 | |
@@ -2438,7 +2438,7 @@ discard block |
||
| 2438 | 2438 | { |
| 2439 | 2439 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2440 | 2440 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
| 2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 2441 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 2442 | 2442 | 'add_category', |
| 2443 | 2443 | 'add_category', |
| 2444 | 2444 | array(), |
@@ -2514,7 +2514,7 @@ discard block |
||
| 2514 | 2514 | 'disable' => '', |
| 2515 | 2515 | 'disabled_message' => false, |
| 2516 | 2516 | ); |
| 2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
| 2517 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
| 2518 | 2518 | return EEH_Template::display_template($template, $template_args, true); |
| 2519 | 2519 | } |
| 2520 | 2520 | |
@@ -2522,8 +2522,8 @@ discard block |
||
| 2522 | 2522 | |
| 2523 | 2523 | protected function _delete_categories() |
| 2524 | 2524 | { |
| 2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
| 2526 | - : (array)$this->_req_data['category_id']; |
|
| 2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
| 2526 | + : (array) $this->_req_data['category_id']; |
|
| 2527 | 2527 | foreach ($cat_ids as $cat_id) { |
| 2528 | 2528 | $this->_delete_category($cat_id); |
| 2529 | 2529 | } |
@@ -2624,7 +2624,7 @@ discard block |
||
| 2624 | 2624 | $limit = ($current_page - 1) * $per_page; |
| 2625 | 2625 | $where = array('taxonomy' => 'espresso_event_categories'); |
| 2626 | 2626 | if (isset($this->_req_data['s'])) { |
| 2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2627 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2628 | 2628 | $where['OR'] = array( |
| 2629 | 2629 | 'Term.name' => array('LIKE', $sstr), |
| 2630 | 2630 | 'description' => array('LIKE', $sstr), |
@@ -2633,7 +2633,7 @@ discard block |
||
| 2633 | 2633 | $query_params = array( |
| 2634 | 2634 | $where, |
| 2635 | 2635 | 'order_by' => array($orderby => $order), |
| 2636 | - 'limit' => $limit . ',' . $per_page, |
|
| 2636 | + 'limit' => $limit.','.$per_page, |
|
| 2637 | 2637 | 'force_join' => array('Term'), |
| 2638 | 2638 | ); |
| 2639 | 2639 | $categories = $count |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table { |
| 5 | 5 | |
| 6 | 6 | |
| 7 | - public function __construct( $admin_page ) { |
|
| 7 | + public function __construct($admin_page) { |
|
| 8 | 8 | parent::__construct($admin_page); |
| 9 | 9 | } |
| 10 | 10 | |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | protected function _setup_data() { |
| 15 | - $this->_data = $this->_view != 'trash' ? $this->_admin_page->get_attendees( $this->_per_page ) : $this->_admin_page->get_attendees( $this->_per_page, FALSE, TRUE ); |
|
| 16 | - $this->_all_data_count = $this->_view != 'trash' ? $this->_admin_page->get_attendees( $this->_per_page, TRUE ) : $this->_admin_page->get_attendees( $this->_per_page,TRUE, TRUE ); |
|
| 15 | + $this->_data = $this->_view != 'trash' ? $this->_admin_page->get_attendees($this->_per_page) : $this->_admin_page->get_attendees($this->_per_page, FALSE, TRUE); |
|
| 16 | + $this->_all_data_count = $this->_view != 'trash' ? $this->_admin_page->get_attendees($this->_per_page, TRUE) : $this->_admin_page->get_attendees($this->_per_page, TRUE, TRUE); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | $this->_sortable_columns = array( |
| 44 | - 'ATT_ID' => array( 'ATT_ID' => FALSE ), |
|
| 45 | - 'ATT_lname' => array( 'ATT_lname' => TRUE ), //true means its already sorted |
|
| 46 | - 'ATT_fname' => array( 'ATT_fname' => FALSE ), |
|
| 47 | - 'ATT_email' => array( 'ATT_email' => FALSE ), |
|
| 48 | - 'ATT_city' => array( 'ATT_city' => FALSE ), |
|
| 49 | - 'STA_ID' => array( 'STA_ID' => FALSE ), |
|
| 50 | - 'CNT_ISO' => array( 'CNT_ISO' => FALSE ) |
|
| 44 | + 'ATT_ID' => array('ATT_ID' => FALSE), |
|
| 45 | + 'ATT_lname' => array('ATT_lname' => TRUE), //true means its already sorted |
|
| 46 | + 'ATT_fname' => array('ATT_fname' => FALSE), |
|
| 47 | + 'ATT_email' => array('ATT_email' => FALSE), |
|
| 48 | + 'ATT_city' => array('ATT_city' => FALSE), |
|
| 49 | + 'STA_ID' => array('STA_ID' => FALSE), |
|
| 50 | + 'CNT_ISO' => array('CNT_ISO' => FALSE) |
|
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | $this->_hidden_columns = array(); |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | protected function _add_view_counts() { |
| 67 | - $this->_views['in_use']['count'] = $this->_admin_page->get_attendees( $this->_per_page, TRUE ); |
|
| 68 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_contacts', 'espresso_registrations_delete_registration' ) ) { |
|
| 69 | - $this->_views['trash']['count'] = $this->_admin_page->get_attendees( $this->_per_page,TRUE, TRUE ); |
|
| 67 | + $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, TRUE); |
|
| 68 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', 'espresso_registrations_delete_registration')) { |
|
| 69 | + $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, TRUE, TRUE); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | function column_cb($item) { |
| 92 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', /* $1%s */ $item->ID() ); |
|
| 92 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', /* $1%s */ $item->ID()); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | function column_ATT_ID($item) { |
| 100 | - $content = $item->ID(); |
|
| 100 | + $content = $item->ID(); |
|
| 101 | 101 | $attendee_name = $item instanceof EE_Attendee ? $item->full_name() : ''; |
| 102 | - $content .= ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
| 102 | + $content .= ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
| 103 | 103 | return $content; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
| 110 | 110 | function column_ATT_lname($item) { |
| 111 | 111 | |
| 112 | 112 | // edit attendee link |
| 113 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$item->ID() ), REG_ADMIN_URL ); |
|
| 114 | - $name_link = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_contacts', 'espresso_registrations_edit_attendee' ) ? '<a href="'.$edit_lnk_url.'" title="' . esc_attr__( 'Edit Contact', 'event_espresso' ) . '">' . $item->lname() . '</a>' : $item->lname(); |
|
| 113 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'edit_attendee', 'post'=>$item->ID()), REG_ADMIN_URL); |
|
| 114 | + $name_link = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('Edit Contact', 'event_espresso').'">'.$item->lname().'</a>' : $item->lname(); |
|
| 115 | 115 | return $name_link; |
| 116 | 116 | |
| 117 | 117 | } |
@@ -124,30 +124,30 @@ discard block |
||
| 124 | 124 | //Build row actions |
| 125 | 125 | $actions = array(); |
| 126 | 126 | // edit attendee link |
| 127 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_edit_contacts', 'espresso_registrations_edit_attendee' ) ) { |
|
| 128 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$item->ID() ), REG_ADMIN_URL ); |
|
| 129 | - $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' . esc_attr__( 'Edit Contact', 'event_espresso' ) . '">' . __( 'Edit', 'event_espresso' ) . '</a>'; |
|
| 127 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee')) { |
|
| 128 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'edit_attendee', 'post'=>$item->ID()), REG_ADMIN_URL); |
|
| 129 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('Edit Contact', 'event_espresso').'">'.__('Edit', 'event_espresso').'</a>'; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( $this->_view == 'in_use' ) { |
|
| 132 | + if ($this->_view == 'in_use') { |
|
| 133 | 133 | // trash attendee link |
| 134 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_contacts', 'espresso_registrations_trash_attendees' ) ) { |
|
| 135 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'trash_attendee', 'ATT_ID'=>$item->ID() ), REG_ADMIN_URL ); |
|
| 136 | - $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' . esc_attr__( 'Move Contact to Trash', 'event_espresso' ) . '">' . __( 'Trash', 'event_espresso' ) . '</a>'; |
|
| 134 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', 'espresso_registrations_trash_attendees')) { |
|
| 135 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'trash_attendee', 'ATT_ID'=>$item->ID()), REG_ADMIN_URL); |
|
| 136 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'.esc_attr__('Move Contact to Trash', 'event_espresso').'">'.__('Trash', 'event_espresso').'</a>'; |
|
| 137 | 137 | } |
| 138 | 138 | } else { |
| 139 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_contacts', 'espresso_registrations_restore_attendees' ) ) { |
|
| 139 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', 'espresso_registrations_restore_attendees')) { |
|
| 140 | 140 | // restore attendee link |
| 141 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'restore_attendees', 'ATT_ID'=>$item->ID() ), REG_ADMIN_URL ); |
|
| 142 | - $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' . esc_attr__( 'Restore Contact', 'event_espresso' ) . '">' . __( 'Restore', 'event_espresso' ) . '</a>'; |
|
| 141 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'restore_attendees', 'ATT_ID'=>$item->ID()), REG_ADMIN_URL); |
|
| 142 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'.esc_attr__('Restore Contact', 'event_espresso').'">'.__('Restore', 'event_espresso').'</a>'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action'=>'edit_attendee', 'post'=>$item->ID() ), REG_ADMIN_URL ); |
|
| 147 | - $name_link = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_contacts', 'espresso_registrations_edit_attendee' ) ? '<a href="'.$edit_lnk_url.'" title="' . esc_attr__( 'Edit Contact', 'event_espresso' ) . '">' . $item->fname() . '</a>' : $item->fname(); |
|
| 146 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'edit_attendee', 'post'=>$item->ID()), REG_ADMIN_URL); |
|
| 147 | + $name_link = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('Edit Contact', 'event_espresso').'">'.$item->fname().'</a>' : $item->fname(); |
|
| 148 | 148 | |
| 149 | 149 | //Return the name contents |
| 150 | - return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions) ); |
|
| 150 | + return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions)); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | |
| 157 | 157 | function column_ATT_email($item) { |
| 158 | - return '<a href="mailto:' . $item->email() . '">' . $item->email() . '</a>'; |
|
| 158 | + return '<a href="mailto:'.$item->email().'">'.$item->email().'</a>'; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | function column_STA_ID($item) { |
| 177 | 177 | $states = EEM_State::instance()->get_all_states(); |
| 178 | - $state = isset( $states[ $item->state_ID() ] ) ? $states[ $item->state_ID() ]->get( 'STA_name' ) : $item->state_ID(); |
|
| 179 | - return ! is_numeric( $state ) ? $state : ''; |
|
| 178 | + $state = isset($states[$item->state_ID()]) ? $states[$item->state_ID()]->get('STA_name') : $item->state_ID(); |
|
| 179 | + return ! is_numeric($state) ? $state : ''; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | function column_CNT_ISO($item) { |
| 185 | 185 | $countries = EEM_Country::instance()->get_all_countries(); |
| 186 | 186 | //EEH_Debug_Tools::printr( $countries, '$countries <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
| 187 | - $country = isset( $countries[ $item->country_ID() ] ) ? $countries[ $item->country_ID() ]->get( 'CNT_name' ) : $item->country_ID(); |
|
| 188 | - return ! is_numeric( $country ) ? $country : ''; |
|
| 187 | + $country = isset($countries[$item->country_ID()]) ? $countries[$item->country_ID()]->get('CNT_name') : $item->country_ID(); |
|
| 188 | + return ! is_numeric($country) ? $country : ''; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -23,1844 +23,1844 @@ discard block |
||
| 23 | 23 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registration |
|
| 28 | - */ |
|
| 29 | - private $_registration; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Event |
|
| 33 | - */ |
|
| 34 | - private $_reg_event; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EE_Session |
|
| 38 | - */ |
|
| 39 | - private $_session; |
|
| 40 | - |
|
| 41 | - private static $_reg_status; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Form for displaying the custom questions for this registration. |
|
| 45 | - * This gets used a few times throughout the request so its best to cache it |
|
| 46 | - * |
|
| 47 | - * @var EE_Registration_Custom_Questions_Form |
|
| 48 | - */ |
|
| 49 | - protected $_reg_custom_questions_form = null; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @Constructor |
|
| 56 | - * @access public |
|
| 57 | - * @param bool $routing |
|
| 58 | - * @return Registrations_Admin_Page |
|
| 59 | - */ |
|
| 60 | - public function __construct($routing = true) |
|
| 61 | - { |
|
| 62 | - parent::__construct($routing); |
|
| 63 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - public function wp_loaded() |
|
| 68 | - { |
|
| 69 | - // when adding a new registration... |
|
| 70 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | - EE_System::do_not_cache(); |
|
| 72 | - if ( ! isset($this->_req_data['processing_registration']) |
|
| 73 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | - ) { |
|
| 75 | - // and it's NOT the attendee information reg step |
|
| 76 | - // force cookie expiration by setting time to last week |
|
| 77 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | - // and update the global |
|
| 79 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - protected function _init_page_props() |
|
| 86 | - { |
|
| 87 | - $this->page_slug = REG_PG_SLUG; |
|
| 88 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | - $this->_admin_base_path = REG_ADMIN; |
|
| 90 | - $this->page_label = __('Registrations', 'event_espresso'); |
|
| 91 | - $this->_cpt_routes = array( |
|
| 92 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | - 'edit_attendee' => 'espresso_attendees', |
|
| 94 | - 'insert_attendee' => 'espresso_attendees', |
|
| 95 | - 'update_attendee' => 'espresso_attendees', |
|
| 96 | - ); |
|
| 97 | - $this->_cpt_model_names = array( |
|
| 98 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | - ); |
|
| 101 | - $this->_cpt_edit_routes = array( |
|
| 102 | - 'espresso_attendees' => 'edit_attendee', |
|
| 103 | - ); |
|
| 104 | - $this->_pagenow_map = array( |
|
| 105 | - 'add_new_attendee' => 'post-new.php', |
|
| 106 | - 'edit_attendee' => 'post.php', |
|
| 107 | - 'trash' => 'post.php', |
|
| 108 | - ); |
|
| 109 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | - //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - public function clear_comment_link($link, $comment, $args) |
|
| 116 | - { |
|
| 117 | - //gotta make sure this only happens on this route |
|
| 118 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | - if ($post_type === 'espresso_attendees') { |
|
| 120 | - return '#commentsdiv'; |
|
| 121 | - } |
|
| 122 | - return $link; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - protected function _ajax_hooks() |
|
| 127 | - { |
|
| 128 | - //todo: all hooks for registrations ajax goes in here |
|
| 129 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - protected function _define_page_props() |
|
| 134 | - { |
|
| 135 | - $this->_admin_page_title = $this->page_label; |
|
| 136 | - $this->_labels = array( |
|
| 137 | - 'buttons' => array( |
|
| 138 | - 'add-registrant' => __('Add New Registration', 'event_espresso'), |
|
| 139 | - 'add-attendee' => __('Add Contact', 'event_espresso'), |
|
| 140 | - 'edit' => __('Edit Contact', 'event_espresso'), |
|
| 141 | - 'report' => __("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | - 'report_all' => __('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | - 'report_filtered' => __('Filtered CSV Report', 'event_espresso'), |
|
| 144 | - 'contact_list_report' => __('Contact List Report', 'event_espresso'), |
|
| 145 | - 'contact_list_export' => __("Export Data", "event_espresso"), |
|
| 146 | - ), |
|
| 147 | - 'publishbox' => array( |
|
| 148 | - 'add_new_attendee' => __("Add Contact Record", 'event_espresso'), |
|
| 149 | - 'edit_attendee' => __("Update Contact Record", 'event_espresso'), |
|
| 150 | - ), |
|
| 151 | - 'hide_add_button_on_cpt_route' => array( |
|
| 152 | - 'edit_attendee' => true, |
|
| 153 | - ), |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * grab url requests and route them |
|
| 160 | - * |
|
| 161 | - * @access private |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - public function _set_page_routes() |
|
| 165 | - { |
|
| 166 | - $this->_get_registration_status_array(); |
|
| 167 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | - ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | - ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post'] |
|
| 172 | - : $att_id; |
|
| 173 | - $this->_page_routes = array( |
|
| 174 | - 'default' => array( |
|
| 175 | - 'func' => '_registrations_overview_list_table', |
|
| 176 | - 'capability' => 'ee_read_registrations', |
|
| 177 | - ), |
|
| 178 | - 'view_registration' => array( |
|
| 179 | - 'func' => '_registration_details', |
|
| 180 | - 'capability' => 'ee_read_registration', |
|
| 181 | - 'obj_id' => $reg_id, |
|
| 182 | - ), |
|
| 183 | - 'edit_registration' => array( |
|
| 184 | - 'func' => '_update_attendee_registration_form', |
|
| 185 | - 'noheader' => true, |
|
| 186 | - 'headers_sent_route' => 'view_registration', |
|
| 187 | - 'capability' => 'ee_edit_registration', |
|
| 188 | - 'obj_id' => $reg_id, |
|
| 189 | - '_REG_ID' => $reg_id, |
|
| 190 | - ), |
|
| 191 | - 'trash_registrations' => array( |
|
| 192 | - 'func' => '_trash_or_restore_registrations', |
|
| 193 | - 'args' => array('trash' => true), |
|
| 194 | - 'noheader' => true, |
|
| 195 | - 'capability' => 'ee_delete_registrations', |
|
| 196 | - ), |
|
| 197 | - 'restore_registrations' => array( |
|
| 198 | - 'func' => '_trash_or_restore_registrations', |
|
| 199 | - 'args' => array('trash' => false), |
|
| 200 | - 'noheader' => true, |
|
| 201 | - 'capability' => 'ee_delete_registrations', |
|
| 202 | - ), |
|
| 203 | - 'delete_registrations' => array( |
|
| 204 | - 'func' => '_delete_registrations', |
|
| 205 | - 'noheader' => true, |
|
| 206 | - 'capability' => 'ee_delete_registrations', |
|
| 207 | - ), |
|
| 208 | - 'new_registration' => array( |
|
| 209 | - 'func' => 'new_registration', |
|
| 210 | - 'capability' => 'ee_edit_registrations', |
|
| 211 | - ), |
|
| 212 | - 'process_reg_step' => array( |
|
| 213 | - 'func' => 'process_reg_step', |
|
| 214 | - 'noheader' => true, |
|
| 215 | - 'capability' => 'ee_edit_registrations', |
|
| 216 | - ), |
|
| 217 | - 'redirect_to_txn' => array( |
|
| 218 | - 'func' => 'redirect_to_txn', |
|
| 219 | - 'noheader' => true, |
|
| 220 | - 'capability' => 'ee_edit_registrations', |
|
| 221 | - ), |
|
| 222 | - 'change_reg_status' => array( |
|
| 223 | - 'func' => '_change_reg_status', |
|
| 224 | - 'noheader' => true, |
|
| 225 | - 'capability' => 'ee_edit_registration', |
|
| 226 | - 'obj_id' => $reg_id, |
|
| 227 | - ), |
|
| 228 | - 'approve_registration' => array( |
|
| 229 | - 'func' => 'approve_registration', |
|
| 230 | - 'noheader' => true, |
|
| 231 | - 'capability' => 'ee_edit_registration', |
|
| 232 | - 'obj_id' => $reg_id, |
|
| 233 | - ), |
|
| 234 | - 'approve_and_notify_registration' => array( |
|
| 235 | - 'func' => 'approve_registration', |
|
| 236 | - 'noheader' => true, |
|
| 237 | - 'args' => array(true), |
|
| 238 | - 'capability' => 'ee_edit_registration', |
|
| 239 | - 'obj_id' => $reg_id, |
|
| 240 | - ), |
|
| 241 | - 'decline_registration' => array( |
|
| 242 | - 'func' => 'decline_registration', |
|
| 243 | - 'noheader' => true, |
|
| 244 | - 'capability' => 'ee_edit_registration', |
|
| 245 | - 'obj_id' => $reg_id, |
|
| 246 | - ), |
|
| 247 | - 'decline_and_notify_registration' => array( |
|
| 248 | - 'func' => 'decline_registration', |
|
| 249 | - 'noheader' => true, |
|
| 250 | - 'args' => array(true), |
|
| 251 | - 'capability' => 'ee_edit_registration', |
|
| 252 | - 'obj_id' => $reg_id, |
|
| 253 | - ), |
|
| 254 | - 'pending_registration' => array( |
|
| 255 | - 'func' => 'pending_registration', |
|
| 256 | - 'noheader' => true, |
|
| 257 | - 'capability' => 'ee_edit_registration', |
|
| 258 | - 'obj_id' => $reg_id, |
|
| 259 | - ), |
|
| 260 | - 'pending_and_notify_registration' => array( |
|
| 261 | - 'func' => 'pending_registration', |
|
| 262 | - 'noheader' => true, |
|
| 263 | - 'args' => array(true), |
|
| 264 | - 'capability' => 'ee_edit_registration', |
|
| 265 | - 'obj_id' => $reg_id, |
|
| 266 | - ), |
|
| 267 | - 'no_approve_registration' => array( |
|
| 268 | - 'func' => 'not_approve_registration', |
|
| 269 | - 'noheader' => true, |
|
| 270 | - 'capability' => 'ee_edit_registration', |
|
| 271 | - 'obj_id' => $reg_id, |
|
| 272 | - ), |
|
| 273 | - 'no_approve_and_notify_registration' => array( |
|
| 274 | - 'func' => 'not_approve_registration', |
|
| 275 | - 'noheader' => true, |
|
| 276 | - 'args' => array(true), |
|
| 277 | - 'capability' => 'ee_edit_registration', |
|
| 278 | - 'obj_id' => $reg_id, |
|
| 279 | - ), |
|
| 280 | - 'cancel_registration' => array( |
|
| 281 | - 'func' => 'cancel_registration', |
|
| 282 | - 'noheader' => true, |
|
| 283 | - 'capability' => 'ee_edit_registration', |
|
| 284 | - 'obj_id' => $reg_id, |
|
| 285 | - ), |
|
| 286 | - 'cancel_and_notify_registration' => array( |
|
| 287 | - 'func' => 'cancel_registration', |
|
| 288 | - 'noheader' => true, |
|
| 289 | - 'args' => array(true), |
|
| 290 | - 'capability' => 'ee_edit_registration', |
|
| 291 | - 'obj_id' => $reg_id, |
|
| 292 | - ), |
|
| 293 | - 'contact_list' => array( |
|
| 294 | - 'func' => '_attendee_contact_list_table', |
|
| 295 | - 'capability' => 'ee_read_contacts', |
|
| 296 | - ), |
|
| 297 | - 'add_new_attendee' => array( |
|
| 298 | - 'func' => '_create_new_cpt_item', |
|
| 299 | - 'args' => array( |
|
| 300 | - 'new_attendee' => true, |
|
| 301 | - 'capability' => 'ee_edit_contacts', |
|
| 302 | - ), |
|
| 303 | - ), |
|
| 304 | - 'edit_attendee' => array( |
|
| 305 | - 'func' => '_edit_cpt_item', |
|
| 306 | - 'capability' => 'ee_edit_contacts', |
|
| 307 | - 'obj_id' => $att_id, |
|
| 308 | - ), |
|
| 309 | - 'duplicate_attendee' => array( |
|
| 310 | - 'func' => '_duplicate_attendee', |
|
| 311 | - 'noheader' => true, |
|
| 312 | - 'capability' => 'ee_edit_contacts', |
|
| 313 | - 'obj_id' => $att_id, |
|
| 314 | - ), |
|
| 315 | - 'insert_attendee' => array( |
|
| 316 | - 'func' => '_insert_or_update_attendee', |
|
| 317 | - 'args' => array( |
|
| 318 | - 'new_attendee' => true, |
|
| 319 | - ), |
|
| 320 | - 'noheader' => true, |
|
| 321 | - 'capability' => 'ee_edit_contacts', |
|
| 322 | - ), |
|
| 323 | - 'update_attendee' => array( |
|
| 324 | - 'func' => '_insert_or_update_attendee', |
|
| 325 | - 'args' => array( |
|
| 326 | - 'new_attendee' => false, |
|
| 327 | - ), |
|
| 328 | - 'noheader' => true, |
|
| 329 | - 'capability' => 'ee_edit_contacts', |
|
| 330 | - 'obj_id' => $att_id, |
|
| 331 | - ), |
|
| 332 | - 'trash_attendee' => array( |
|
| 333 | - 'func' => '_trash_or_restore_attendees', |
|
| 334 | - 'args' => array( |
|
| 335 | - 'trash' => true, |
|
| 336 | - ), |
|
| 337 | - 'noheader' => true, |
|
| 338 | - 'capability' => 'ee_delete_contacts', |
|
| 339 | - 'obj_id' => $att_id, |
|
| 340 | - ), |
|
| 341 | - 'restore_attendees' => array( |
|
| 342 | - 'func' => '_trash_or_restore_attendees', |
|
| 343 | - 'args' => array( |
|
| 344 | - 'trash' => false, |
|
| 345 | - ), |
|
| 346 | - 'noheader' => true, |
|
| 347 | - 'capability' => 'ee_delete_contacts', |
|
| 348 | - 'obj_id' => $att_id, |
|
| 349 | - ), |
|
| 350 | - 'resend_registration' => array( |
|
| 351 | - 'func' => '_resend_registration', |
|
| 352 | - 'noheader' => true, |
|
| 353 | - 'capability' => 'ee_send_message', |
|
| 354 | - ), |
|
| 355 | - 'registrations_report' => array( |
|
| 356 | - 'func' => '_registrations_report', |
|
| 357 | - 'noheader' => true, |
|
| 358 | - 'capability' => 'ee_read_registrations', |
|
| 359 | - ), |
|
| 360 | - 'contact_list_export' => array( |
|
| 361 | - 'func' => '_contact_list_export', |
|
| 362 | - 'noheader' => true, |
|
| 363 | - 'capability' => 'export', |
|
| 364 | - ), |
|
| 365 | - 'contact_list_report' => array( |
|
| 366 | - 'func' => '_contact_list_report', |
|
| 367 | - 'noheader' => true, |
|
| 368 | - 'capability' => 'ee_read_contacts', |
|
| 369 | - ), |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - protected function _set_page_config() |
|
| 375 | - { |
|
| 376 | - $this->_page_config = array( |
|
| 377 | - 'default' => array( |
|
| 378 | - 'nav' => array( |
|
| 379 | - 'label' => __('Overview', 'event_espresso'), |
|
| 380 | - 'order' => 5, |
|
| 381 | - ), |
|
| 382 | - 'help_tabs' => array( |
|
| 383 | - 'registrations_overview_help_tab' => array( |
|
| 384 | - 'title' => __('Registrations Overview', 'event_espresso'), |
|
| 385 | - 'filename' => 'registrations_overview', |
|
| 386 | - ), |
|
| 387 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 388 | - 'title' => __('Registrations Table Column Headings', 'event_espresso'), |
|
| 389 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 390 | - ), |
|
| 391 | - 'registrations_overview_filters_help_tab' => array( |
|
| 392 | - 'title' => __('Registration Filters', 'event_espresso'), |
|
| 393 | - 'filename' => 'registrations_overview_filters', |
|
| 394 | - ), |
|
| 395 | - 'registrations_overview_views_help_tab' => array( |
|
| 396 | - 'title' => __('Registration Views', 'event_espresso'), |
|
| 397 | - 'filename' => 'registrations_overview_views', |
|
| 398 | - ), |
|
| 399 | - 'registrations_regoverview_other_help_tab' => array( |
|
| 400 | - 'title' => __('Registrations Other', 'event_espresso'), |
|
| 401 | - 'filename' => 'registrations_overview_other', |
|
| 402 | - ), |
|
| 403 | - ), |
|
| 404 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 405 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 406 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 407 | - 'require_nonce' => false, |
|
| 408 | - ), |
|
| 409 | - 'view_registration' => array( |
|
| 410 | - 'nav' => array( |
|
| 411 | - 'label' => __('REG Details', 'event_espresso'), |
|
| 412 | - 'order' => 15, |
|
| 413 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
| 414 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 415 | - : $this->_admin_base_url, |
|
| 416 | - 'persistent' => false, |
|
| 417 | - ), |
|
| 418 | - 'help_tabs' => array( |
|
| 419 | - 'registrations_details_help_tab' => array( |
|
| 420 | - 'title' => __('Registration Details', 'event_espresso'), |
|
| 421 | - 'filename' => 'registrations_details', |
|
| 422 | - ), |
|
| 423 | - 'registrations_details_table_help_tab' => array( |
|
| 424 | - 'title' => __('Registration Details Table', 'event_espresso'), |
|
| 425 | - 'filename' => 'registrations_details_table', |
|
| 426 | - ), |
|
| 427 | - 'registrations_details_form_answers_help_tab' => array( |
|
| 428 | - 'title' => __('Registration Form Answers', 'event_espresso'), |
|
| 429 | - 'filename' => 'registrations_details_form_answers', |
|
| 430 | - ), |
|
| 431 | - 'registrations_details_registrant_details_help_tab' => array( |
|
| 432 | - 'title' => __('Contact Details', 'event_espresso'), |
|
| 433 | - 'filename' => 'registrations_details_registrant_details', |
|
| 434 | - ), |
|
| 435 | - ), |
|
| 436 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 437 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 438 | - array('_registration_details_metaboxes')), |
|
| 439 | - 'require_nonce' => false, |
|
| 440 | - ), |
|
| 441 | - 'new_registration' => array( |
|
| 442 | - 'nav' => array( |
|
| 443 | - 'label' => __('Add New Registration', 'event_espresso'), |
|
| 444 | - 'url' => '#', |
|
| 445 | - 'order' => 15, |
|
| 446 | - 'persistent' => false, |
|
| 447 | - ), |
|
| 448 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 449 | - 'labels' => array( |
|
| 450 | - 'publishbox' => __('Save Registration', 'event_espresso'), |
|
| 451 | - ), |
|
| 452 | - 'require_nonce' => false, |
|
| 453 | - ), |
|
| 454 | - 'add_new_attendee' => array( |
|
| 455 | - 'nav' => array( |
|
| 456 | - 'label' => __('Add Contact', 'event_espresso'), |
|
| 457 | - 'order' => 15, |
|
| 458 | - 'persistent' => false, |
|
| 459 | - ), |
|
| 460 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 461 | - array('_publish_post_box', 'attendee_editor_metaboxes')), |
|
| 462 | - 'require_nonce' => false, |
|
| 463 | - ), |
|
| 464 | - 'edit_attendee' => array( |
|
| 465 | - 'nav' => array( |
|
| 466 | - 'label' => __('Edit Contact', 'event_espresso'), |
|
| 467 | - 'order' => 15, |
|
| 468 | - 'persistent' => false, |
|
| 469 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
| 470 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 471 | - : $this->_admin_base_url, |
|
| 472 | - ), |
|
| 473 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 474 | - 'require_nonce' => false, |
|
| 475 | - ), |
|
| 476 | - 'contact_list' => array( |
|
| 477 | - 'nav' => array( |
|
| 478 | - 'label' => __('Contact List', 'event_espresso'), |
|
| 479 | - 'order' => 20, |
|
| 480 | - ), |
|
| 481 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 482 | - 'help_tabs' => array( |
|
| 483 | - 'registrations_contact_list_help_tab' => array( |
|
| 484 | - 'title' => __('Registrations Contact List', 'event_espresso'), |
|
| 485 | - 'filename' => 'registrations_contact_list', |
|
| 486 | - ), |
|
| 487 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 488 | - 'title' => __('Contact List Table Column Headings', 'event_espresso'), |
|
| 489 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 490 | - ), |
|
| 491 | - 'registrations_contact_list_views_help_tab' => array( |
|
| 492 | - 'title' => __('Contact List Views', 'event_espresso'), |
|
| 493 | - 'filename' => 'registrations_contact_list_views', |
|
| 494 | - ), |
|
| 495 | - 'registrations_contact_list_other_help_tab' => array( |
|
| 496 | - 'title' => __('Contact List Other', 'event_espresso'), |
|
| 497 | - 'filename' => 'registrations_contact_list_other', |
|
| 498 | - ), |
|
| 499 | - ), |
|
| 500 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 501 | - 'metaboxes' => array(), |
|
| 502 | - 'require_nonce' => false, |
|
| 503 | - ), |
|
| 504 | - //override default cpt routes |
|
| 505 | - 'create_new' => '', |
|
| 506 | - 'edit' => '', |
|
| 507 | - ); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * The below methods aren't used by this class currently |
|
| 513 | - */ |
|
| 514 | - protected function _add_screen_options() |
|
| 515 | - { |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - protected function _add_feature_pointers() |
|
| 520 | - { |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - public function admin_init() |
|
| 525 | - { |
|
| 526 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes', |
|
| 527 | - 'event_espresso'); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - public function admin_notices() |
|
| 532 | - { |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - public function admin_footer_scripts() |
|
| 537 | - { |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * get list of registration statuses |
|
| 543 | - * |
|
| 544 | - * @access private |
|
| 545 | - * @return void |
|
| 546 | - */ |
|
| 547 | - private function _get_registration_status_array() |
|
| 548 | - { |
|
| 549 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - protected function _add_screen_options_default() |
|
| 554 | - { |
|
| 555 | - $this->_per_page_screen_option(); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - protected function _add_screen_options_contact_list() |
|
| 560 | - { |
|
| 561 | - $page_title = $this->_admin_page_title; |
|
| 562 | - $this->_admin_page_title = __("Contacts", 'event_espresso'); |
|
| 563 | - $this->_per_page_screen_option(); |
|
| 564 | - $this->_admin_page_title = $page_title; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - public function load_scripts_styles() |
|
| 569 | - { |
|
| 570 | - //style |
|
| 571 | - //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 572 | - wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 573 | - EVENT_ESPRESSO_VERSION); |
|
| 574 | - wp_enqueue_style('espresso_reg'); |
|
| 575 | - //script |
|
| 576 | - wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 577 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true); |
|
| 578 | - wp_enqueue_script('espresso_reg'); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - public function load_scripts_styles_edit_attendee() |
|
| 583 | - { |
|
| 584 | - //stuff to only show up on our attendee edit details page. |
|
| 585 | - $attendee_details_translations = array( |
|
| 586 | - 'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 587 | - $this->_cpt_model_obj->get_datetime('ATT_created')), |
|
| 588 | - ); |
|
| 589 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 590 | - wp_enqueue_script('jquery-validate'); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - public function load_scripts_styles_view_registration() |
|
| 595 | - { |
|
| 596 | - //styles |
|
| 597 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 598 | - //scripts |
|
| 599 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 600 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - public function load_scripts_styles_contact_list() |
|
| 605 | - { |
|
| 606 | - wp_deregister_style('espresso_reg'); |
|
| 607 | - wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 608 | - EVENT_ESPRESSO_VERSION); |
|
| 609 | - wp_enqueue_style('espresso_att'); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - public function load_scripts_styles_new_registration() |
|
| 614 | - { |
|
| 615 | - wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 616 | - EVENT_ESPRESSO_VERSION, true); |
|
| 617 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 618 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 619 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 620 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 621 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 626 | - { |
|
| 627 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 632 | - { |
|
| 633 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - |
|
| 637 | - protected function _set_list_table_views_default() |
|
| 638 | - { |
|
| 639 | - //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 640 | - EED_Messages::set_autoloaders(); |
|
| 641 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 642 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 643 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 644 | - //key= bulk_action_slug, value= message type. |
|
| 645 | - $match_array = array( |
|
| 646 | - 'approve_registration' => 'registration', |
|
| 647 | - 'decline_registration' => 'declined_registration', |
|
| 648 | - 'pending_registration' => 'pending_approval', |
|
| 649 | - 'no_approve_registration' => 'not_approved_registration', |
|
| 650 | - 'cancel_registration' => 'cancelled_registration', |
|
| 651 | - ); |
|
| 652 | - /** setup reg status bulk actions **/ |
|
| 653 | - $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 654 | - if (in_array($match_array['approve_registration'], $active_mts) |
|
| 655 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 656 | - ) { |
|
| 657 | - $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 658 | - 'event_espresso'); |
|
| 659 | - } |
|
| 660 | - $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 661 | - if (in_array($match_array['decline_registration'], $active_mts) |
|
| 662 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 663 | - ) { |
|
| 664 | - $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 665 | - 'event_espresso'); |
|
| 666 | - } |
|
| 667 | - $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 668 | - if (in_array($match_array['pending_registration'], $active_mts) |
|
| 669 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 670 | - ) { |
|
| 671 | - $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', |
|
| 672 | - 'event_espresso'); |
|
| 673 | - } |
|
| 674 | - $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 675 | - if (in_array($match_array['no_approve_registration'], $active_mts) |
|
| 676 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 677 | - ) { |
|
| 678 | - $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', |
|
| 679 | - 'event_espresso'); |
|
| 680 | - } |
|
| 681 | - $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 682 | - if (in_array($match_array['cancel_registration'], $active_mts) |
|
| 683 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 684 | - ) { |
|
| 685 | - $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', |
|
| 686 | - 'event_espresso'); |
|
| 687 | - } |
|
| 688 | - $this->_views = array( |
|
| 689 | - 'all' => array( |
|
| 690 | - 'slug' => 'all', |
|
| 691 | - 'label' => __('View All Registrations', 'event_espresso'), |
|
| 692 | - 'count' => 0, |
|
| 693 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 694 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 695 | - )), |
|
| 696 | - ), |
|
| 697 | - 'month' => array( |
|
| 698 | - 'slug' => 'month', |
|
| 699 | - 'label' => __('This Month', 'event_espresso'), |
|
| 700 | - 'count' => 0, |
|
| 701 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 702 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 703 | - )), |
|
| 704 | - ), |
|
| 705 | - 'today' => array( |
|
| 706 | - 'slug' => 'today', |
|
| 707 | - 'label' => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))), |
|
| 708 | - 'count' => 0, |
|
| 709 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 710 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 711 | - )), |
|
| 712 | - ), |
|
| 713 | - ); |
|
| 714 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 715 | - 'espresso_registrations_delete_registration') |
|
| 716 | - ) { |
|
| 717 | - $this->_views['incomplete'] = array( |
|
| 718 | - 'slug' => 'incomplete', |
|
| 719 | - 'label' => __('Incomplete', 'event_espresso'), |
|
| 720 | - 'count' => 0, |
|
| 721 | - 'bulk_action' => array( |
|
| 722 | - 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 723 | - ), |
|
| 724 | - ); |
|
| 725 | - $this->_views['trash'] = array( |
|
| 726 | - 'slug' => 'trash', |
|
| 727 | - 'label' => __('Trash', 'event_espresso'), |
|
| 728 | - 'count' => 0, |
|
| 729 | - 'bulk_action' => array( |
|
| 730 | - 'restore_registrations' => __('Restore Registrations', 'event_espresso'), |
|
| 731 | - 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso'), |
|
| 732 | - ), |
|
| 733 | - ); |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - protected function _set_list_table_views_contact_list() |
|
| 739 | - { |
|
| 740 | - $this->_views = array( |
|
| 741 | - 'in_use' => array( |
|
| 742 | - 'slug' => 'in_use', |
|
| 743 | - 'label' => __('In Use', 'event_espresso'), |
|
| 744 | - 'count' => 0, |
|
| 745 | - 'bulk_action' => array( |
|
| 746 | - 'trash_attendee' => __('Move to Trash', 'event_espresso'), |
|
| 747 | - ), |
|
| 748 | - ), |
|
| 749 | - ); |
|
| 750 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 751 | - 'espresso_registrations_trash_attendees') |
|
| 752 | - ) { |
|
| 753 | - $this->_views['trash'] = array( |
|
| 754 | - 'slug' => 'trash', |
|
| 755 | - 'label' => __('Trash', 'event_espresso'), |
|
| 756 | - 'count' => 0, |
|
| 757 | - 'bulk_action' => array( |
|
| 758 | - 'restore_attendees' => __('Restore from Trash', 'event_espresso'), |
|
| 759 | - ), |
|
| 760 | - ); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - protected function _registration_legend_items() |
|
| 766 | - { |
|
| 767 | - $fc_items = array( |
|
| 768 | - 'star-icon' => array( |
|
| 769 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 770 | - 'desc' => __('This is the Primary Registrant', 'event_espresso'), |
|
| 771 | - ), |
|
| 772 | - 'view_details' => array( |
|
| 773 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 774 | - 'desc' => __('View Registration Details', 'event_espresso'), |
|
| 775 | - ), |
|
| 776 | - 'edit_attendee' => array( |
|
| 777 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 778 | - 'desc' => __('Edit Contact Details', 'event_espresso'), |
|
| 779 | - ), |
|
| 780 | - 'view_transaction' => array( |
|
| 781 | - 'class' => 'dashicons dashicons-cart', |
|
| 782 | - 'desc' => __('View Transaction Details', 'event_espresso'), |
|
| 783 | - ), |
|
| 784 | - 'view_invoice' => array( |
|
| 785 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 786 | - 'desc' => __('View Transaction Invoice', 'event_espresso'), |
|
| 787 | - ), |
|
| 788 | - ); |
|
| 789 | - if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 790 | - 'espresso_registrations_resend_registration') |
|
| 791 | - ) { |
|
| 792 | - $fc_items['resend_registration'] = array( |
|
| 793 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 794 | - 'desc' => __('Resend Registration Details', 'event_espresso'), |
|
| 795 | - ); |
|
| 796 | - } else { |
|
| 797 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 798 | - } |
|
| 799 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 800 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 801 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 802 | - $fc_items['view_related_messages'] = array( |
|
| 803 | - 'class' => $related_for_icon['css_class'], |
|
| 804 | - 'desc' => $related_for_icon['label'], |
|
| 805 | - ); |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - $sc_items = array( |
|
| 809 | - 'approved_status' => array( |
|
| 810 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 811 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 812 | - ), |
|
| 813 | - 'pending_status' => array( |
|
| 814 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 815 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 816 | - ), |
|
| 817 | - 'wait_list' => array( |
|
| 818 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 819 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 820 | - ), |
|
| 821 | - 'incomplete_status' => array( |
|
| 822 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 823 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'), |
|
| 824 | - ), |
|
| 825 | - 'not_approved' => array( |
|
| 826 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 827 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 828 | - ), |
|
| 829 | - 'declined_status' => array( |
|
| 830 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 831 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 832 | - ), |
|
| 833 | - 'cancelled_status' => array( |
|
| 834 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 835 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 836 | - ), |
|
| 837 | - ); |
|
| 838 | - return array_merge($fc_items, $sc_items); |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - |
|
| 842 | - |
|
| 843 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 844 | - /** |
|
| 845 | - * @throws \EE_Error |
|
| 846 | - */ |
|
| 847 | - protected function _registrations_overview_list_table() |
|
| 848 | - { |
|
| 849 | - $this->_template_args['admin_page_header'] = ''; |
|
| 850 | - $EVT_ID = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0; |
|
| 851 | - if ($EVT_ID) { |
|
| 852 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', |
|
| 853 | - 'espresso_registrations_new_registration', $EVT_ID) |
|
| 854 | - ) { |
|
| 855 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 856 | - array('event_id' => $EVT_ID), 'add-new-h2'); |
|
| 857 | - } |
|
| 858 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 859 | - if ($event instanceof EE_Event) { |
|
| 860 | - $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s', |
|
| 861 | - 'event_espresso'), '<h3 style="line-height:1.5em;">', |
|
| 862 | - '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 863 | - 'action' => 'edit', |
|
| 864 | - 'post' => $event->ID(), |
|
| 865 | - ), EVENTS_ADMIN_URL) . '"> ' . $event->get('EVT_name') . ' </a> ', '</h3>'); |
|
| 866 | - } |
|
| 867 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 868 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 869 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 870 | - $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5); |
|
| 871 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 872 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 873 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 874 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 875 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 879 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * This sets the _registration property for the registration details screen |
|
| 885 | - * |
|
| 886 | - * @access private |
|
| 887 | - * @return bool |
|
| 888 | - */ |
|
| 889 | - private function _set_registration_object() |
|
| 890 | - { |
|
| 891 | - //get out if we've already set the object |
|
| 892 | - if (is_object($this->_registration)) { |
|
| 893 | - return true; |
|
| 894 | - } |
|
| 895 | - $REG = EEM_Registration::instance(); |
|
| 896 | - $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 897 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 898 | - return true; |
|
| 899 | - } else { |
|
| 900 | - $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 901 | - 'event_espresso'), $REG_ID); |
|
| 902 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 903 | - $this->_registration = null; |
|
| 904 | - return false; |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Used to retrieve registrations for the list table. |
|
| 911 | - * |
|
| 912 | - * @param int $per_page |
|
| 913 | - * @param bool $count |
|
| 914 | - * @param bool $this_month |
|
| 915 | - * @param bool $today |
|
| 916 | - * @return \EE_Registration[]|int |
|
| 917 | - */ |
|
| 918 | - public function get_registrations( |
|
| 919 | - $per_page = 10, |
|
| 920 | - $count = false, |
|
| 921 | - $this_month = false, |
|
| 922 | - $today = false |
|
| 923 | - ) { |
|
| 924 | - if( $this_month ) { |
|
| 925 | - $this->_req_data['status'] = 'month'; |
|
| 926 | - } |
|
| 927 | - if( $today ) { |
|
| 928 | - $this->_req_data['status'] = 'today'; |
|
| 929 | - } |
|
| 930 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 931 | - /** |
|
| 932 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 933 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 934 | - * @see EEM_Base::get_all() |
|
| 935 | - */ |
|
| 936 | - $query_params['group_by'] = ''; |
|
| 937 | - |
|
| 938 | - return $count |
|
| 939 | - ? EEM_Registration::instance()->count($query_params) |
|
| 940 | - /** @type EE_Registration[] */ |
|
| 941 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 948 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 949 | - * |
|
| 950 | - * @param array $request |
|
| 951 | - * @param int $per_page |
|
| 952 | - * @param bool $count |
|
| 953 | - * @return array |
|
| 954 | - */ |
|
| 955 | - protected function _get_registration_query_parameters( |
|
| 956 | - $request = array(), |
|
| 957 | - $per_page = 10, |
|
| 958 | - $count = false |
|
| 959 | - ) { |
|
| 960 | - |
|
| 961 | - $query_params = array( |
|
| 962 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 963 | - $request |
|
| 964 | - ), |
|
| 965 | - 'caps' => EEM_Registration::caps_read_admin, |
|
| 966 | - 'default_where_conditions' => 'this_model_only', |
|
| 967 | - ); |
|
| 968 | - if ( ! $count) { |
|
| 969 | - $query_params = array_merge( |
|
| 970 | - $query_params, |
|
| 971 | - $this->_get_orderby_for_registrations_query(), |
|
| 972 | - $this->_get_limit($per_page) |
|
| 973 | - ); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - return $query_params; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 982 | - * |
|
| 983 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 984 | - * @return array |
|
| 985 | - */ |
|
| 986 | - protected function _add_event_id_to_where_conditions(array $request) |
|
| 987 | - { |
|
| 988 | - $where = array(); |
|
| 989 | - if ( ! empty($request['event_id'])) { |
|
| 990 | - $where['EVT_ID'] = absint($request['event_id']); |
|
| 991 | - } |
|
| 992 | - return $where; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - |
|
| 996 | - /** |
|
| 997 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 998 | - * |
|
| 999 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1000 | - * @return array |
|
| 1001 | - */ |
|
| 1002 | - protected function _add_category_id_to_where_conditions(array $request) |
|
| 1003 | - { |
|
| 1004 | - $where = array(); |
|
| 1005 | - if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1006 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1007 | - } |
|
| 1008 | - return $where; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1014 | - * |
|
| 1015 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1016 | - * @return array |
|
| 1017 | - */ |
|
| 1018 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1019 | - { |
|
| 1020 | - $where = array(); |
|
| 1021 | - if ( ! empty($request['datetime_id'])) { |
|
| 1022 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1023 | - } |
|
| 1024 | - if( ! empty($request['DTT_ID'])){ |
|
| 1025 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1026 | - } |
|
| 1027 | - return $where; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1033 | - * |
|
| 1034 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1035 | - * @return array |
|
| 1036 | - */ |
|
| 1037 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1038 | - { |
|
| 1039 | - $where = array(); |
|
| 1040 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1041 | - $registration_status = ! empty($request['_reg_status']) |
|
| 1042 | - ? sanitize_text_field($request['_reg_status']) |
|
| 1043 | - : ''; |
|
| 1044 | - |
|
| 1045 | - /* |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registration |
|
| 28 | + */ |
|
| 29 | + private $_registration; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Event |
|
| 33 | + */ |
|
| 34 | + private $_reg_event; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EE_Session |
|
| 38 | + */ |
|
| 39 | + private $_session; |
|
| 40 | + |
|
| 41 | + private static $_reg_status; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Form for displaying the custom questions for this registration. |
|
| 45 | + * This gets used a few times throughout the request so its best to cache it |
|
| 46 | + * |
|
| 47 | + * @var EE_Registration_Custom_Questions_Form |
|
| 48 | + */ |
|
| 49 | + protected $_reg_custom_questions_form = null; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @Constructor |
|
| 56 | + * @access public |
|
| 57 | + * @param bool $routing |
|
| 58 | + * @return Registrations_Admin_Page |
|
| 59 | + */ |
|
| 60 | + public function __construct($routing = true) |
|
| 61 | + { |
|
| 62 | + parent::__construct($routing); |
|
| 63 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + public function wp_loaded() |
|
| 68 | + { |
|
| 69 | + // when adding a new registration... |
|
| 70 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | + EE_System::do_not_cache(); |
|
| 72 | + if ( ! isset($this->_req_data['processing_registration']) |
|
| 73 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | + ) { |
|
| 75 | + // and it's NOT the attendee information reg step |
|
| 76 | + // force cookie expiration by setting time to last week |
|
| 77 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | + // and update the global |
|
| 79 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + protected function _init_page_props() |
|
| 86 | + { |
|
| 87 | + $this->page_slug = REG_PG_SLUG; |
|
| 88 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | + $this->_admin_base_path = REG_ADMIN; |
|
| 90 | + $this->page_label = __('Registrations', 'event_espresso'); |
|
| 91 | + $this->_cpt_routes = array( |
|
| 92 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | + 'edit_attendee' => 'espresso_attendees', |
|
| 94 | + 'insert_attendee' => 'espresso_attendees', |
|
| 95 | + 'update_attendee' => 'espresso_attendees', |
|
| 96 | + ); |
|
| 97 | + $this->_cpt_model_names = array( |
|
| 98 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | + ); |
|
| 101 | + $this->_cpt_edit_routes = array( |
|
| 102 | + 'espresso_attendees' => 'edit_attendee', |
|
| 103 | + ); |
|
| 104 | + $this->_pagenow_map = array( |
|
| 105 | + 'add_new_attendee' => 'post-new.php', |
|
| 106 | + 'edit_attendee' => 'post.php', |
|
| 107 | + 'trash' => 'post.php', |
|
| 108 | + ); |
|
| 109 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | + //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + public function clear_comment_link($link, $comment, $args) |
|
| 116 | + { |
|
| 117 | + //gotta make sure this only happens on this route |
|
| 118 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | + if ($post_type === 'espresso_attendees') { |
|
| 120 | + return '#commentsdiv'; |
|
| 121 | + } |
|
| 122 | + return $link; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + protected function _ajax_hooks() |
|
| 127 | + { |
|
| 128 | + //todo: all hooks for registrations ajax goes in here |
|
| 129 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + protected function _define_page_props() |
|
| 134 | + { |
|
| 135 | + $this->_admin_page_title = $this->page_label; |
|
| 136 | + $this->_labels = array( |
|
| 137 | + 'buttons' => array( |
|
| 138 | + 'add-registrant' => __('Add New Registration', 'event_espresso'), |
|
| 139 | + 'add-attendee' => __('Add Contact', 'event_espresso'), |
|
| 140 | + 'edit' => __('Edit Contact', 'event_espresso'), |
|
| 141 | + 'report' => __("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | + 'report_all' => __('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | + 'report_filtered' => __('Filtered CSV Report', 'event_espresso'), |
|
| 144 | + 'contact_list_report' => __('Contact List Report', 'event_espresso'), |
|
| 145 | + 'contact_list_export' => __("Export Data", "event_espresso"), |
|
| 146 | + ), |
|
| 147 | + 'publishbox' => array( |
|
| 148 | + 'add_new_attendee' => __("Add Contact Record", 'event_espresso'), |
|
| 149 | + 'edit_attendee' => __("Update Contact Record", 'event_espresso'), |
|
| 150 | + ), |
|
| 151 | + 'hide_add_button_on_cpt_route' => array( |
|
| 152 | + 'edit_attendee' => true, |
|
| 153 | + ), |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * grab url requests and route them |
|
| 160 | + * |
|
| 161 | + * @access private |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + public function _set_page_routes() |
|
| 165 | + { |
|
| 166 | + $this->_get_registration_status_array(); |
|
| 167 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | + ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | + ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post'] |
|
| 172 | + : $att_id; |
|
| 173 | + $this->_page_routes = array( |
|
| 174 | + 'default' => array( |
|
| 175 | + 'func' => '_registrations_overview_list_table', |
|
| 176 | + 'capability' => 'ee_read_registrations', |
|
| 177 | + ), |
|
| 178 | + 'view_registration' => array( |
|
| 179 | + 'func' => '_registration_details', |
|
| 180 | + 'capability' => 'ee_read_registration', |
|
| 181 | + 'obj_id' => $reg_id, |
|
| 182 | + ), |
|
| 183 | + 'edit_registration' => array( |
|
| 184 | + 'func' => '_update_attendee_registration_form', |
|
| 185 | + 'noheader' => true, |
|
| 186 | + 'headers_sent_route' => 'view_registration', |
|
| 187 | + 'capability' => 'ee_edit_registration', |
|
| 188 | + 'obj_id' => $reg_id, |
|
| 189 | + '_REG_ID' => $reg_id, |
|
| 190 | + ), |
|
| 191 | + 'trash_registrations' => array( |
|
| 192 | + 'func' => '_trash_or_restore_registrations', |
|
| 193 | + 'args' => array('trash' => true), |
|
| 194 | + 'noheader' => true, |
|
| 195 | + 'capability' => 'ee_delete_registrations', |
|
| 196 | + ), |
|
| 197 | + 'restore_registrations' => array( |
|
| 198 | + 'func' => '_trash_or_restore_registrations', |
|
| 199 | + 'args' => array('trash' => false), |
|
| 200 | + 'noheader' => true, |
|
| 201 | + 'capability' => 'ee_delete_registrations', |
|
| 202 | + ), |
|
| 203 | + 'delete_registrations' => array( |
|
| 204 | + 'func' => '_delete_registrations', |
|
| 205 | + 'noheader' => true, |
|
| 206 | + 'capability' => 'ee_delete_registrations', |
|
| 207 | + ), |
|
| 208 | + 'new_registration' => array( |
|
| 209 | + 'func' => 'new_registration', |
|
| 210 | + 'capability' => 'ee_edit_registrations', |
|
| 211 | + ), |
|
| 212 | + 'process_reg_step' => array( |
|
| 213 | + 'func' => 'process_reg_step', |
|
| 214 | + 'noheader' => true, |
|
| 215 | + 'capability' => 'ee_edit_registrations', |
|
| 216 | + ), |
|
| 217 | + 'redirect_to_txn' => array( |
|
| 218 | + 'func' => 'redirect_to_txn', |
|
| 219 | + 'noheader' => true, |
|
| 220 | + 'capability' => 'ee_edit_registrations', |
|
| 221 | + ), |
|
| 222 | + 'change_reg_status' => array( |
|
| 223 | + 'func' => '_change_reg_status', |
|
| 224 | + 'noheader' => true, |
|
| 225 | + 'capability' => 'ee_edit_registration', |
|
| 226 | + 'obj_id' => $reg_id, |
|
| 227 | + ), |
|
| 228 | + 'approve_registration' => array( |
|
| 229 | + 'func' => 'approve_registration', |
|
| 230 | + 'noheader' => true, |
|
| 231 | + 'capability' => 'ee_edit_registration', |
|
| 232 | + 'obj_id' => $reg_id, |
|
| 233 | + ), |
|
| 234 | + 'approve_and_notify_registration' => array( |
|
| 235 | + 'func' => 'approve_registration', |
|
| 236 | + 'noheader' => true, |
|
| 237 | + 'args' => array(true), |
|
| 238 | + 'capability' => 'ee_edit_registration', |
|
| 239 | + 'obj_id' => $reg_id, |
|
| 240 | + ), |
|
| 241 | + 'decline_registration' => array( |
|
| 242 | + 'func' => 'decline_registration', |
|
| 243 | + 'noheader' => true, |
|
| 244 | + 'capability' => 'ee_edit_registration', |
|
| 245 | + 'obj_id' => $reg_id, |
|
| 246 | + ), |
|
| 247 | + 'decline_and_notify_registration' => array( |
|
| 248 | + 'func' => 'decline_registration', |
|
| 249 | + 'noheader' => true, |
|
| 250 | + 'args' => array(true), |
|
| 251 | + 'capability' => 'ee_edit_registration', |
|
| 252 | + 'obj_id' => $reg_id, |
|
| 253 | + ), |
|
| 254 | + 'pending_registration' => array( |
|
| 255 | + 'func' => 'pending_registration', |
|
| 256 | + 'noheader' => true, |
|
| 257 | + 'capability' => 'ee_edit_registration', |
|
| 258 | + 'obj_id' => $reg_id, |
|
| 259 | + ), |
|
| 260 | + 'pending_and_notify_registration' => array( |
|
| 261 | + 'func' => 'pending_registration', |
|
| 262 | + 'noheader' => true, |
|
| 263 | + 'args' => array(true), |
|
| 264 | + 'capability' => 'ee_edit_registration', |
|
| 265 | + 'obj_id' => $reg_id, |
|
| 266 | + ), |
|
| 267 | + 'no_approve_registration' => array( |
|
| 268 | + 'func' => 'not_approve_registration', |
|
| 269 | + 'noheader' => true, |
|
| 270 | + 'capability' => 'ee_edit_registration', |
|
| 271 | + 'obj_id' => $reg_id, |
|
| 272 | + ), |
|
| 273 | + 'no_approve_and_notify_registration' => array( |
|
| 274 | + 'func' => 'not_approve_registration', |
|
| 275 | + 'noheader' => true, |
|
| 276 | + 'args' => array(true), |
|
| 277 | + 'capability' => 'ee_edit_registration', |
|
| 278 | + 'obj_id' => $reg_id, |
|
| 279 | + ), |
|
| 280 | + 'cancel_registration' => array( |
|
| 281 | + 'func' => 'cancel_registration', |
|
| 282 | + 'noheader' => true, |
|
| 283 | + 'capability' => 'ee_edit_registration', |
|
| 284 | + 'obj_id' => $reg_id, |
|
| 285 | + ), |
|
| 286 | + 'cancel_and_notify_registration' => array( |
|
| 287 | + 'func' => 'cancel_registration', |
|
| 288 | + 'noheader' => true, |
|
| 289 | + 'args' => array(true), |
|
| 290 | + 'capability' => 'ee_edit_registration', |
|
| 291 | + 'obj_id' => $reg_id, |
|
| 292 | + ), |
|
| 293 | + 'contact_list' => array( |
|
| 294 | + 'func' => '_attendee_contact_list_table', |
|
| 295 | + 'capability' => 'ee_read_contacts', |
|
| 296 | + ), |
|
| 297 | + 'add_new_attendee' => array( |
|
| 298 | + 'func' => '_create_new_cpt_item', |
|
| 299 | + 'args' => array( |
|
| 300 | + 'new_attendee' => true, |
|
| 301 | + 'capability' => 'ee_edit_contacts', |
|
| 302 | + ), |
|
| 303 | + ), |
|
| 304 | + 'edit_attendee' => array( |
|
| 305 | + 'func' => '_edit_cpt_item', |
|
| 306 | + 'capability' => 'ee_edit_contacts', |
|
| 307 | + 'obj_id' => $att_id, |
|
| 308 | + ), |
|
| 309 | + 'duplicate_attendee' => array( |
|
| 310 | + 'func' => '_duplicate_attendee', |
|
| 311 | + 'noheader' => true, |
|
| 312 | + 'capability' => 'ee_edit_contacts', |
|
| 313 | + 'obj_id' => $att_id, |
|
| 314 | + ), |
|
| 315 | + 'insert_attendee' => array( |
|
| 316 | + 'func' => '_insert_or_update_attendee', |
|
| 317 | + 'args' => array( |
|
| 318 | + 'new_attendee' => true, |
|
| 319 | + ), |
|
| 320 | + 'noheader' => true, |
|
| 321 | + 'capability' => 'ee_edit_contacts', |
|
| 322 | + ), |
|
| 323 | + 'update_attendee' => array( |
|
| 324 | + 'func' => '_insert_or_update_attendee', |
|
| 325 | + 'args' => array( |
|
| 326 | + 'new_attendee' => false, |
|
| 327 | + ), |
|
| 328 | + 'noheader' => true, |
|
| 329 | + 'capability' => 'ee_edit_contacts', |
|
| 330 | + 'obj_id' => $att_id, |
|
| 331 | + ), |
|
| 332 | + 'trash_attendee' => array( |
|
| 333 | + 'func' => '_trash_or_restore_attendees', |
|
| 334 | + 'args' => array( |
|
| 335 | + 'trash' => true, |
|
| 336 | + ), |
|
| 337 | + 'noheader' => true, |
|
| 338 | + 'capability' => 'ee_delete_contacts', |
|
| 339 | + 'obj_id' => $att_id, |
|
| 340 | + ), |
|
| 341 | + 'restore_attendees' => array( |
|
| 342 | + 'func' => '_trash_or_restore_attendees', |
|
| 343 | + 'args' => array( |
|
| 344 | + 'trash' => false, |
|
| 345 | + ), |
|
| 346 | + 'noheader' => true, |
|
| 347 | + 'capability' => 'ee_delete_contacts', |
|
| 348 | + 'obj_id' => $att_id, |
|
| 349 | + ), |
|
| 350 | + 'resend_registration' => array( |
|
| 351 | + 'func' => '_resend_registration', |
|
| 352 | + 'noheader' => true, |
|
| 353 | + 'capability' => 'ee_send_message', |
|
| 354 | + ), |
|
| 355 | + 'registrations_report' => array( |
|
| 356 | + 'func' => '_registrations_report', |
|
| 357 | + 'noheader' => true, |
|
| 358 | + 'capability' => 'ee_read_registrations', |
|
| 359 | + ), |
|
| 360 | + 'contact_list_export' => array( |
|
| 361 | + 'func' => '_contact_list_export', |
|
| 362 | + 'noheader' => true, |
|
| 363 | + 'capability' => 'export', |
|
| 364 | + ), |
|
| 365 | + 'contact_list_report' => array( |
|
| 366 | + 'func' => '_contact_list_report', |
|
| 367 | + 'noheader' => true, |
|
| 368 | + 'capability' => 'ee_read_contacts', |
|
| 369 | + ), |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + protected function _set_page_config() |
|
| 375 | + { |
|
| 376 | + $this->_page_config = array( |
|
| 377 | + 'default' => array( |
|
| 378 | + 'nav' => array( |
|
| 379 | + 'label' => __('Overview', 'event_espresso'), |
|
| 380 | + 'order' => 5, |
|
| 381 | + ), |
|
| 382 | + 'help_tabs' => array( |
|
| 383 | + 'registrations_overview_help_tab' => array( |
|
| 384 | + 'title' => __('Registrations Overview', 'event_espresso'), |
|
| 385 | + 'filename' => 'registrations_overview', |
|
| 386 | + ), |
|
| 387 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 388 | + 'title' => __('Registrations Table Column Headings', 'event_espresso'), |
|
| 389 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 390 | + ), |
|
| 391 | + 'registrations_overview_filters_help_tab' => array( |
|
| 392 | + 'title' => __('Registration Filters', 'event_espresso'), |
|
| 393 | + 'filename' => 'registrations_overview_filters', |
|
| 394 | + ), |
|
| 395 | + 'registrations_overview_views_help_tab' => array( |
|
| 396 | + 'title' => __('Registration Views', 'event_espresso'), |
|
| 397 | + 'filename' => 'registrations_overview_views', |
|
| 398 | + ), |
|
| 399 | + 'registrations_regoverview_other_help_tab' => array( |
|
| 400 | + 'title' => __('Registrations Other', 'event_espresso'), |
|
| 401 | + 'filename' => 'registrations_overview_other', |
|
| 402 | + ), |
|
| 403 | + ), |
|
| 404 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 405 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 406 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 407 | + 'require_nonce' => false, |
|
| 408 | + ), |
|
| 409 | + 'view_registration' => array( |
|
| 410 | + 'nav' => array( |
|
| 411 | + 'label' => __('REG Details', 'event_espresso'), |
|
| 412 | + 'order' => 15, |
|
| 413 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
| 414 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 415 | + : $this->_admin_base_url, |
|
| 416 | + 'persistent' => false, |
|
| 417 | + ), |
|
| 418 | + 'help_tabs' => array( |
|
| 419 | + 'registrations_details_help_tab' => array( |
|
| 420 | + 'title' => __('Registration Details', 'event_espresso'), |
|
| 421 | + 'filename' => 'registrations_details', |
|
| 422 | + ), |
|
| 423 | + 'registrations_details_table_help_tab' => array( |
|
| 424 | + 'title' => __('Registration Details Table', 'event_espresso'), |
|
| 425 | + 'filename' => 'registrations_details_table', |
|
| 426 | + ), |
|
| 427 | + 'registrations_details_form_answers_help_tab' => array( |
|
| 428 | + 'title' => __('Registration Form Answers', 'event_espresso'), |
|
| 429 | + 'filename' => 'registrations_details_form_answers', |
|
| 430 | + ), |
|
| 431 | + 'registrations_details_registrant_details_help_tab' => array( |
|
| 432 | + 'title' => __('Contact Details', 'event_espresso'), |
|
| 433 | + 'filename' => 'registrations_details_registrant_details', |
|
| 434 | + ), |
|
| 435 | + ), |
|
| 436 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 437 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 438 | + array('_registration_details_metaboxes')), |
|
| 439 | + 'require_nonce' => false, |
|
| 440 | + ), |
|
| 441 | + 'new_registration' => array( |
|
| 442 | + 'nav' => array( |
|
| 443 | + 'label' => __('Add New Registration', 'event_espresso'), |
|
| 444 | + 'url' => '#', |
|
| 445 | + 'order' => 15, |
|
| 446 | + 'persistent' => false, |
|
| 447 | + ), |
|
| 448 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 449 | + 'labels' => array( |
|
| 450 | + 'publishbox' => __('Save Registration', 'event_espresso'), |
|
| 451 | + ), |
|
| 452 | + 'require_nonce' => false, |
|
| 453 | + ), |
|
| 454 | + 'add_new_attendee' => array( |
|
| 455 | + 'nav' => array( |
|
| 456 | + 'label' => __('Add Contact', 'event_espresso'), |
|
| 457 | + 'order' => 15, |
|
| 458 | + 'persistent' => false, |
|
| 459 | + ), |
|
| 460 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, |
|
| 461 | + array('_publish_post_box', 'attendee_editor_metaboxes')), |
|
| 462 | + 'require_nonce' => false, |
|
| 463 | + ), |
|
| 464 | + 'edit_attendee' => array( |
|
| 465 | + 'nav' => array( |
|
| 466 | + 'label' => __('Edit Contact', 'event_espresso'), |
|
| 467 | + 'order' => 15, |
|
| 468 | + 'persistent' => false, |
|
| 469 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
| 470 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 471 | + : $this->_admin_base_url, |
|
| 472 | + ), |
|
| 473 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 474 | + 'require_nonce' => false, |
|
| 475 | + ), |
|
| 476 | + 'contact_list' => array( |
|
| 477 | + 'nav' => array( |
|
| 478 | + 'label' => __('Contact List', 'event_espresso'), |
|
| 479 | + 'order' => 20, |
|
| 480 | + ), |
|
| 481 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 482 | + 'help_tabs' => array( |
|
| 483 | + 'registrations_contact_list_help_tab' => array( |
|
| 484 | + 'title' => __('Registrations Contact List', 'event_espresso'), |
|
| 485 | + 'filename' => 'registrations_contact_list', |
|
| 486 | + ), |
|
| 487 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 488 | + 'title' => __('Contact List Table Column Headings', 'event_espresso'), |
|
| 489 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 490 | + ), |
|
| 491 | + 'registrations_contact_list_views_help_tab' => array( |
|
| 492 | + 'title' => __('Contact List Views', 'event_espresso'), |
|
| 493 | + 'filename' => 'registrations_contact_list_views', |
|
| 494 | + ), |
|
| 495 | + 'registrations_contact_list_other_help_tab' => array( |
|
| 496 | + 'title' => __('Contact List Other', 'event_espresso'), |
|
| 497 | + 'filename' => 'registrations_contact_list_other', |
|
| 498 | + ), |
|
| 499 | + ), |
|
| 500 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 501 | + 'metaboxes' => array(), |
|
| 502 | + 'require_nonce' => false, |
|
| 503 | + ), |
|
| 504 | + //override default cpt routes |
|
| 505 | + 'create_new' => '', |
|
| 506 | + 'edit' => '', |
|
| 507 | + ); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * The below methods aren't used by this class currently |
|
| 513 | + */ |
|
| 514 | + protected function _add_screen_options() |
|
| 515 | + { |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + protected function _add_feature_pointers() |
|
| 520 | + { |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + public function admin_init() |
|
| 525 | + { |
|
| 526 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes', |
|
| 527 | + 'event_espresso'); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + public function admin_notices() |
|
| 532 | + { |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + public function admin_footer_scripts() |
|
| 537 | + { |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * get list of registration statuses |
|
| 543 | + * |
|
| 544 | + * @access private |
|
| 545 | + * @return void |
|
| 546 | + */ |
|
| 547 | + private function _get_registration_status_array() |
|
| 548 | + { |
|
| 549 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + protected function _add_screen_options_default() |
|
| 554 | + { |
|
| 555 | + $this->_per_page_screen_option(); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + protected function _add_screen_options_contact_list() |
|
| 560 | + { |
|
| 561 | + $page_title = $this->_admin_page_title; |
|
| 562 | + $this->_admin_page_title = __("Contacts", 'event_espresso'); |
|
| 563 | + $this->_per_page_screen_option(); |
|
| 564 | + $this->_admin_page_title = $page_title; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + public function load_scripts_styles() |
|
| 569 | + { |
|
| 570 | + //style |
|
| 571 | + //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
| 572 | + wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'), |
|
| 573 | + EVENT_ESPRESSO_VERSION); |
|
| 574 | + wp_enqueue_style('espresso_reg'); |
|
| 575 | + //script |
|
| 576 | + wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 577 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true); |
|
| 578 | + wp_enqueue_script('espresso_reg'); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + public function load_scripts_styles_edit_attendee() |
|
| 583 | + { |
|
| 584 | + //stuff to only show up on our attendee edit details page. |
|
| 585 | + $attendee_details_translations = array( |
|
| 586 | + 'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 587 | + $this->_cpt_model_obj->get_datetime('ATT_created')), |
|
| 588 | + ); |
|
| 589 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 590 | + wp_enqueue_script('jquery-validate'); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + public function load_scripts_styles_view_registration() |
|
| 595 | + { |
|
| 596 | + //styles |
|
| 597 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 598 | + //scripts |
|
| 599 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 600 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + public function load_scripts_styles_contact_list() |
|
| 605 | + { |
|
| 606 | + wp_deregister_style('espresso_reg'); |
|
| 607 | + wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'), |
|
| 608 | + EVENT_ESPRESSO_VERSION); |
|
| 609 | + wp_enqueue_style('espresso_att'); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + public function load_scripts_styles_new_registration() |
|
| 614 | + { |
|
| 615 | + wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'), |
|
| 616 | + EVENT_ESPRESSO_VERSION, true); |
|
| 617 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 618 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 619 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 620 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 621 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 626 | + { |
|
| 627 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 632 | + { |
|
| 633 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + |
|
| 637 | + protected function _set_list_table_views_default() |
|
| 638 | + { |
|
| 639 | + //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 640 | + EED_Messages::set_autoloaders(); |
|
| 641 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 642 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 643 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 644 | + //key= bulk_action_slug, value= message type. |
|
| 645 | + $match_array = array( |
|
| 646 | + 'approve_registration' => 'registration', |
|
| 647 | + 'decline_registration' => 'declined_registration', |
|
| 648 | + 'pending_registration' => 'pending_approval', |
|
| 649 | + 'no_approve_registration' => 'not_approved_registration', |
|
| 650 | + 'cancel_registration' => 'cancelled_registration', |
|
| 651 | + ); |
|
| 652 | + /** setup reg status bulk actions **/ |
|
| 653 | + $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 654 | + if (in_array($match_array['approve_registration'], $active_mts) |
|
| 655 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 656 | + ) { |
|
| 657 | + $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 658 | + 'event_espresso'); |
|
| 659 | + } |
|
| 660 | + $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 661 | + if (in_array($match_array['decline_registration'], $active_mts) |
|
| 662 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 663 | + ) { |
|
| 664 | + $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 665 | + 'event_espresso'); |
|
| 666 | + } |
|
| 667 | + $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 668 | + if (in_array($match_array['pending_registration'], $active_mts) |
|
| 669 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 670 | + ) { |
|
| 671 | + $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', |
|
| 672 | + 'event_espresso'); |
|
| 673 | + } |
|
| 674 | + $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 675 | + if (in_array($match_array['no_approve_registration'], $active_mts) |
|
| 676 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 677 | + ) { |
|
| 678 | + $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', |
|
| 679 | + 'event_espresso'); |
|
| 680 | + } |
|
| 681 | + $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 682 | + if (in_array($match_array['cancel_registration'], $active_mts) |
|
| 683 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages') |
|
| 684 | + ) { |
|
| 685 | + $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', |
|
| 686 | + 'event_espresso'); |
|
| 687 | + } |
|
| 688 | + $this->_views = array( |
|
| 689 | + 'all' => array( |
|
| 690 | + 'slug' => 'all', |
|
| 691 | + 'label' => __('View All Registrations', 'event_espresso'), |
|
| 692 | + 'count' => 0, |
|
| 693 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 694 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 695 | + )), |
|
| 696 | + ), |
|
| 697 | + 'month' => array( |
|
| 698 | + 'slug' => 'month', |
|
| 699 | + 'label' => __('This Month', 'event_espresso'), |
|
| 700 | + 'count' => 0, |
|
| 701 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 702 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 703 | + )), |
|
| 704 | + ), |
|
| 705 | + 'today' => array( |
|
| 706 | + 'slug' => 'today', |
|
| 707 | + 'label' => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))), |
|
| 708 | + 'count' => 0, |
|
| 709 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 710 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 711 | + )), |
|
| 712 | + ), |
|
| 713 | + ); |
|
| 714 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
| 715 | + 'espresso_registrations_delete_registration') |
|
| 716 | + ) { |
|
| 717 | + $this->_views['incomplete'] = array( |
|
| 718 | + 'slug' => 'incomplete', |
|
| 719 | + 'label' => __('Incomplete', 'event_espresso'), |
|
| 720 | + 'count' => 0, |
|
| 721 | + 'bulk_action' => array( |
|
| 722 | + 'trash_registrations' => __('Trash Registrations', 'event_espresso'), |
|
| 723 | + ), |
|
| 724 | + ); |
|
| 725 | + $this->_views['trash'] = array( |
|
| 726 | + 'slug' => 'trash', |
|
| 727 | + 'label' => __('Trash', 'event_espresso'), |
|
| 728 | + 'count' => 0, |
|
| 729 | + 'bulk_action' => array( |
|
| 730 | + 'restore_registrations' => __('Restore Registrations', 'event_espresso'), |
|
| 731 | + 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso'), |
|
| 732 | + ), |
|
| 733 | + ); |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + protected function _set_list_table_views_contact_list() |
|
| 739 | + { |
|
| 740 | + $this->_views = array( |
|
| 741 | + 'in_use' => array( |
|
| 742 | + 'slug' => 'in_use', |
|
| 743 | + 'label' => __('In Use', 'event_espresso'), |
|
| 744 | + 'count' => 0, |
|
| 745 | + 'bulk_action' => array( |
|
| 746 | + 'trash_attendee' => __('Move to Trash', 'event_espresso'), |
|
| 747 | + ), |
|
| 748 | + ), |
|
| 749 | + ); |
|
| 750 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 751 | + 'espresso_registrations_trash_attendees') |
|
| 752 | + ) { |
|
| 753 | + $this->_views['trash'] = array( |
|
| 754 | + 'slug' => 'trash', |
|
| 755 | + 'label' => __('Trash', 'event_espresso'), |
|
| 756 | + 'count' => 0, |
|
| 757 | + 'bulk_action' => array( |
|
| 758 | + 'restore_attendees' => __('Restore from Trash', 'event_espresso'), |
|
| 759 | + ), |
|
| 760 | + ); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + protected function _registration_legend_items() |
|
| 766 | + { |
|
| 767 | + $fc_items = array( |
|
| 768 | + 'star-icon' => array( |
|
| 769 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 770 | + 'desc' => __('This is the Primary Registrant', 'event_espresso'), |
|
| 771 | + ), |
|
| 772 | + 'view_details' => array( |
|
| 773 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 774 | + 'desc' => __('View Registration Details', 'event_espresso'), |
|
| 775 | + ), |
|
| 776 | + 'edit_attendee' => array( |
|
| 777 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 778 | + 'desc' => __('Edit Contact Details', 'event_espresso'), |
|
| 779 | + ), |
|
| 780 | + 'view_transaction' => array( |
|
| 781 | + 'class' => 'dashicons dashicons-cart', |
|
| 782 | + 'desc' => __('View Transaction Details', 'event_espresso'), |
|
| 783 | + ), |
|
| 784 | + 'view_invoice' => array( |
|
| 785 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 786 | + 'desc' => __('View Transaction Invoice', 'event_espresso'), |
|
| 787 | + ), |
|
| 788 | + ); |
|
| 789 | + if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 790 | + 'espresso_registrations_resend_registration') |
|
| 791 | + ) { |
|
| 792 | + $fc_items['resend_registration'] = array( |
|
| 793 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 794 | + 'desc' => __('Resend Registration Details', 'event_espresso'), |
|
| 795 | + ); |
|
| 796 | + } else { |
|
| 797 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 798 | + } |
|
| 799 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
| 800 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 801 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 802 | + $fc_items['view_related_messages'] = array( |
|
| 803 | + 'class' => $related_for_icon['css_class'], |
|
| 804 | + 'desc' => $related_for_icon['label'], |
|
| 805 | + ); |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + $sc_items = array( |
|
| 809 | + 'approved_status' => array( |
|
| 810 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 811 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 812 | + ), |
|
| 813 | + 'pending_status' => array( |
|
| 814 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 815 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 816 | + ), |
|
| 817 | + 'wait_list' => array( |
|
| 818 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 819 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 820 | + ), |
|
| 821 | + 'incomplete_status' => array( |
|
| 822 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 823 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'), |
|
| 824 | + ), |
|
| 825 | + 'not_approved' => array( |
|
| 826 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 827 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 828 | + ), |
|
| 829 | + 'declined_status' => array( |
|
| 830 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 831 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 832 | + ), |
|
| 833 | + 'cancelled_status' => array( |
|
| 834 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 835 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 836 | + ), |
|
| 837 | + ); |
|
| 838 | + return array_merge($fc_items, $sc_items); |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + |
|
| 842 | + |
|
| 843 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 844 | + /** |
|
| 845 | + * @throws \EE_Error |
|
| 846 | + */ |
|
| 847 | + protected function _registrations_overview_list_table() |
|
| 848 | + { |
|
| 849 | + $this->_template_args['admin_page_header'] = ''; |
|
| 850 | + $EVT_ID = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0; |
|
| 851 | + if ($EVT_ID) { |
|
| 852 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', |
|
| 853 | + 'espresso_registrations_new_registration', $EVT_ID) |
|
| 854 | + ) { |
|
| 855 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant', |
|
| 856 | + array('event_id' => $EVT_ID), 'add-new-h2'); |
|
| 857 | + } |
|
| 858 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 859 | + if ($event instanceof EE_Event) { |
|
| 860 | + $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s', |
|
| 861 | + 'event_espresso'), '<h3 style="line-height:1.5em;">', |
|
| 862 | + '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 863 | + 'action' => 'edit', |
|
| 864 | + 'post' => $event->ID(), |
|
| 865 | + ), EVENTS_ADMIN_URL) . '"> ' . $event->get('EVT_name') . ' </a> ', '</h3>'); |
|
| 866 | + } |
|
| 867 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 868 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 869 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 870 | + $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5); |
|
| 871 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 872 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 873 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 874 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 875 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 879 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * This sets the _registration property for the registration details screen |
|
| 885 | + * |
|
| 886 | + * @access private |
|
| 887 | + * @return bool |
|
| 888 | + */ |
|
| 889 | + private function _set_registration_object() |
|
| 890 | + { |
|
| 891 | + //get out if we've already set the object |
|
| 892 | + if (is_object($this->_registration)) { |
|
| 893 | + return true; |
|
| 894 | + } |
|
| 895 | + $REG = EEM_Registration::instance(); |
|
| 896 | + $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 897 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 898 | + return true; |
|
| 899 | + } else { |
|
| 900 | + $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 901 | + 'event_espresso'), $REG_ID); |
|
| 902 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 903 | + $this->_registration = null; |
|
| 904 | + return false; |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Used to retrieve registrations for the list table. |
|
| 911 | + * |
|
| 912 | + * @param int $per_page |
|
| 913 | + * @param bool $count |
|
| 914 | + * @param bool $this_month |
|
| 915 | + * @param bool $today |
|
| 916 | + * @return \EE_Registration[]|int |
|
| 917 | + */ |
|
| 918 | + public function get_registrations( |
|
| 919 | + $per_page = 10, |
|
| 920 | + $count = false, |
|
| 921 | + $this_month = false, |
|
| 922 | + $today = false |
|
| 923 | + ) { |
|
| 924 | + if( $this_month ) { |
|
| 925 | + $this->_req_data['status'] = 'month'; |
|
| 926 | + } |
|
| 927 | + if( $today ) { |
|
| 928 | + $this->_req_data['status'] = 'today'; |
|
| 929 | + } |
|
| 930 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 931 | + /** |
|
| 932 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 933 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 934 | + * @see EEM_Base::get_all() |
|
| 935 | + */ |
|
| 936 | + $query_params['group_by'] = ''; |
|
| 937 | + |
|
| 938 | + return $count |
|
| 939 | + ? EEM_Registration::instance()->count($query_params) |
|
| 940 | + /** @type EE_Registration[] */ |
|
| 941 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 948 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 949 | + * |
|
| 950 | + * @param array $request |
|
| 951 | + * @param int $per_page |
|
| 952 | + * @param bool $count |
|
| 953 | + * @return array |
|
| 954 | + */ |
|
| 955 | + protected function _get_registration_query_parameters( |
|
| 956 | + $request = array(), |
|
| 957 | + $per_page = 10, |
|
| 958 | + $count = false |
|
| 959 | + ) { |
|
| 960 | + |
|
| 961 | + $query_params = array( |
|
| 962 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 963 | + $request |
|
| 964 | + ), |
|
| 965 | + 'caps' => EEM_Registration::caps_read_admin, |
|
| 966 | + 'default_where_conditions' => 'this_model_only', |
|
| 967 | + ); |
|
| 968 | + if ( ! $count) { |
|
| 969 | + $query_params = array_merge( |
|
| 970 | + $query_params, |
|
| 971 | + $this->_get_orderby_for_registrations_query(), |
|
| 972 | + $this->_get_limit($per_page) |
|
| 973 | + ); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + return $query_params; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 982 | + * |
|
| 983 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 984 | + * @return array |
|
| 985 | + */ |
|
| 986 | + protected function _add_event_id_to_where_conditions(array $request) |
|
| 987 | + { |
|
| 988 | + $where = array(); |
|
| 989 | + if ( ! empty($request['event_id'])) { |
|
| 990 | + $where['EVT_ID'] = absint($request['event_id']); |
|
| 991 | + } |
|
| 992 | + return $where; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 998 | + * |
|
| 999 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1000 | + * @return array |
|
| 1001 | + */ |
|
| 1002 | + protected function _add_category_id_to_where_conditions(array $request) |
|
| 1003 | + { |
|
| 1004 | + $where = array(); |
|
| 1005 | + if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1006 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1007 | + } |
|
| 1008 | + return $where; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1014 | + * |
|
| 1015 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1016 | + * @return array |
|
| 1017 | + */ |
|
| 1018 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1019 | + { |
|
| 1020 | + $where = array(); |
|
| 1021 | + if ( ! empty($request['datetime_id'])) { |
|
| 1022 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1023 | + } |
|
| 1024 | + if( ! empty($request['DTT_ID'])){ |
|
| 1025 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1026 | + } |
|
| 1027 | + return $where; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1033 | + * |
|
| 1034 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1035 | + * @return array |
|
| 1036 | + */ |
|
| 1037 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1038 | + { |
|
| 1039 | + $where = array(); |
|
| 1040 | + $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1041 | + $registration_status = ! empty($request['_reg_status']) |
|
| 1042 | + ? sanitize_text_field($request['_reg_status']) |
|
| 1043 | + : ''; |
|
| 1044 | + |
|
| 1045 | + /* |
|
| 1046 | 1046 | * If filtering by registration status, then we show registrations matching that status. |
| 1047 | 1047 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations UNLESS |
| 1048 | 1048 | * viewing trashed registrations. |
| 1049 | 1049 | */ |
| 1050 | - if ( ! empty($registration_status)) { |
|
| 1051 | - $where['STS_ID'] = $registration_status; |
|
| 1052 | - } else { |
|
| 1053 | - //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1054 | - if ($view === 'trash') { |
|
| 1055 | - $where['REG_deleted'] = true; |
|
| 1056 | - } else if ($view === 'incomplete') { |
|
| 1057 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1058 | - } else { |
|
| 1059 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - return $where; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - |
|
| 1066 | - /** |
|
| 1067 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1068 | - * |
|
| 1069 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1070 | - * @return array |
|
| 1071 | - */ |
|
| 1072 | - protected function _add_date_to_where_conditions(array $request) |
|
| 1073 | - { |
|
| 1074 | - $where = array(); |
|
| 1075 | - $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1076 | - $month_range = ! empty($request['month_range']) |
|
| 1077 | - ? sanitize_text_field($request['month_range']) |
|
| 1078 | - : ''; |
|
| 1079 | - $retrieve_for_today = $view === 'today'; |
|
| 1080 | - $retrieve_for_this_month = $view === 'month'; |
|
| 1081 | - |
|
| 1082 | - if ($retrieve_for_today) { |
|
| 1083 | - $now = date('Y-m-d', current_time('timestamp')); |
|
| 1084 | - $where['REG_date'] = array( |
|
| 1085 | - 'BETWEEN', |
|
| 1086 | - array( |
|
| 1087 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1088 | - 'REG_date', |
|
| 1089 | - $now . ' 00:00:00', |
|
| 1090 | - 'Y-m-d H:i:s' |
|
| 1091 | - ), |
|
| 1092 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1093 | - 'REG_date', |
|
| 1094 | - $now . ' 23:59:59', |
|
| 1095 | - 'Y-m-d H:i:s' |
|
| 1096 | - ), |
|
| 1097 | - ), |
|
| 1098 | - ); |
|
| 1099 | - } elseif ($retrieve_for_this_month) { |
|
| 1100 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1101 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 1102 | - $where['REG_date'] = array( |
|
| 1103 | - 'BETWEEN', |
|
| 1104 | - array( |
|
| 1105 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1106 | - 'REG_date', |
|
| 1107 | - $current_year_and_month . '-01 00:00:00', |
|
| 1108 | - 'Y-m-d H:i:s' |
|
| 1109 | - ), |
|
| 1110 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1111 | - 'REG_date', |
|
| 1112 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1113 | - 'Y-m-d H:i:s' |
|
| 1114 | - ), |
|
| 1115 | - ), |
|
| 1116 | - ); |
|
| 1117 | - } elseif ($month_range) { |
|
| 1118 | - $pieces = explode(' ', $month_range, 3); |
|
| 1119 | - $month_requested = ! empty($pieces[0]) |
|
| 1120 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1121 | - : ''; |
|
| 1122 | - $year_requested = ! empty($pieces[1]) |
|
| 1123 | - ? $pieces[1] |
|
| 1124 | - : ''; |
|
| 1125 | - //if there is not a month or year then we can't go further |
|
| 1126 | - if ($month_requested && $year_requested) { |
|
| 1127 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1128 | - $where['REG_date'] = array( |
|
| 1129 | - 'BETWEEN', |
|
| 1130 | - array( |
|
| 1131 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1132 | - 'REG_date', |
|
| 1133 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1134 | - 'Y-m-d H:i:s' |
|
| 1135 | - ), |
|
| 1136 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1137 | - 'REG_date', |
|
| 1138 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1139 | - 'Y-m-d H:i:s' |
|
| 1140 | - ), |
|
| 1141 | - ), |
|
| 1142 | - ); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - return $where; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - |
|
| 1149 | - /** |
|
| 1150 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1151 | - * |
|
| 1152 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1153 | - * @return array |
|
| 1154 | - */ |
|
| 1155 | - protected function _add_search_to_where_conditions(array $request) |
|
| 1156 | - { |
|
| 1157 | - $where = array(); |
|
| 1158 | - if ( ! empty($request['s'])) { |
|
| 1159 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1160 | - $where['OR'] = array( |
|
| 1161 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1162 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1163 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1164 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1165 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1166 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1167 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1168 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1169 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1170 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1171 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1172 | - 'REG_final_price' => array('LIKE', $search_string), |
|
| 1173 | - 'REG_code' => array('LIKE', $search_string), |
|
| 1174 | - 'REG_count' => array('LIKE', $search_string), |
|
| 1175 | - 'REG_group_size' => array('LIKE', $search_string), |
|
| 1176 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1177 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1178 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1179 | - ); |
|
| 1180 | - } |
|
| 1181 | - return $where; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * Sets up the where conditions for the registrations query. |
|
| 1187 | - * |
|
| 1188 | - * @param array $request |
|
| 1189 | - * @return array |
|
| 1190 | - */ |
|
| 1191 | - protected function _get_where_conditions_for_registrations_query($request) |
|
| 1192 | - { |
|
| 1193 | - return array_merge( |
|
| 1194 | - $this->_add_event_id_to_where_conditions($request), |
|
| 1195 | - $this->_add_category_id_to_where_conditions($request), |
|
| 1196 | - $this->_add_datetime_id_to_where_conditions($request), |
|
| 1197 | - $this->_add_registration_status_to_where_conditions($request), |
|
| 1198 | - $this->_add_date_to_where_conditions($request), |
|
| 1199 | - $this->_add_search_to_where_conditions($request) |
|
| 1200 | - ); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - |
|
| 1204 | - /** |
|
| 1205 | - * Sets up the orderby for the registrations query. |
|
| 1206 | - * |
|
| 1207 | - * @return array |
|
| 1208 | - */ |
|
| 1209 | - protected function _get_orderby_for_registrations_query() |
|
| 1210 | - { |
|
| 1211 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1212 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1213 | - : ''; |
|
| 1214 | - switch ($orderby_field) { |
|
| 1215 | - case '_REG_ID': |
|
| 1216 | - $orderby_field = 'REG_ID'; |
|
| 1217 | - break; |
|
| 1218 | - case '_Reg_status': |
|
| 1219 | - $orderby_field = 'STS_ID'; |
|
| 1220 | - break; |
|
| 1221 | - case 'ATT_fname': |
|
| 1222 | - $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1223 | - break; |
|
| 1224 | - case 'ATT_lname' : |
|
| 1225 | - $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1226 | - break; |
|
| 1227 | - case 'event_name': |
|
| 1228 | - $orderby_field = 'Event.EVT_name'; |
|
| 1229 | - break; |
|
| 1230 | - case 'DTT_EVT_start': |
|
| 1231 | - $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1232 | - break; |
|
| 1233 | - default: //'REG_date' |
|
| 1234 | - $orderby_field = 'REG_date'; |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - //order |
|
| 1238 | - $order = ! empty($this->_req_data['order']) |
|
| 1239 | - ? sanitize_text_field($this->_req_data['order']) |
|
| 1240 | - : 'DESC'; |
|
| 1241 | - |
|
| 1242 | - //mutate orderby_field |
|
| 1243 | - $orderby_field = array_combine( |
|
| 1244 | - (array) $orderby_field, |
|
| 1245 | - array_fill(0, count($orderby_field), $order) |
|
| 1246 | - ); |
|
| 1247 | - return array('order_by' => $orderby_field); |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * Sets up the limit for the registrations query. |
|
| 1253 | - * |
|
| 1254 | - * @param $per_page |
|
| 1255 | - * @return array |
|
| 1256 | - */ |
|
| 1257 | - protected function _get_limit($per_page) |
|
| 1258 | - { |
|
| 1259 | - $current_page = ! empty($this->_req_data['paged']) |
|
| 1260 | - ? absint($this->_req_data['paged']) |
|
| 1261 | - : 1; |
|
| 1262 | - $per_page = ! empty($this->_req_data['perpage']) |
|
| 1263 | - ? $this->_req_data['perpage'] |
|
| 1264 | - : $per_page; |
|
| 1265 | - |
|
| 1266 | - //-1 means return all results so get out if that's set. |
|
| 1267 | - if ((int)$per_page === -1) { |
|
| 1268 | - return array(); |
|
| 1269 | - } |
|
| 1270 | - $per_page = absint($per_page); |
|
| 1271 | - $offset = ($current_page - 1) * $per_page; |
|
| 1272 | - return array('limit' => array($offset, $per_page)); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - public function get_registration_status_array() |
|
| 1277 | - { |
|
| 1278 | - return self::$_reg_status; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - |
|
| 1283 | - |
|
| 1284 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1285 | - /** |
|
| 1286 | - * generates HTML for the View Registration Details Admin page |
|
| 1287 | - * |
|
| 1288 | - * @access protected |
|
| 1289 | - * @return void |
|
| 1290 | - */ |
|
| 1291 | - protected function _registration_details() |
|
| 1292 | - { |
|
| 1293 | - $this->_template_args = array(); |
|
| 1294 | - $this->_set_registration_object(); |
|
| 1295 | - if (is_object($this->_registration)) { |
|
| 1296 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1297 | - : EE_Transaction::new_instance(); |
|
| 1298 | - $this->_session = $transaction->session_data(); |
|
| 1299 | - $event_id = $this->_registration->event_ID(); |
|
| 1300 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1301 | - $this->_template_args['reg_nmbr']['label'] = __('Registration Number', 'event_espresso'); |
|
| 1302 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1303 | - $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso'); |
|
| 1304 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1305 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1306 | - // link back to overview |
|
| 1307 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1308 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1309 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1310 | - 'action' => 'default', |
|
| 1311 | - 'event_id' => $event_id, |
|
| 1312 | - ), REG_ADMIN_URL); |
|
| 1313 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1314 | - 'action' => 'default', |
|
| 1315 | - 'EVT_ID' => $event_id, |
|
| 1316 | - 'page' => 'espresso_transactions', |
|
| 1317 | - ), admin_url('admin.php')); |
|
| 1318 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1319 | - 'page' => 'espresso_events', |
|
| 1320 | - 'action' => 'edit', |
|
| 1321 | - 'post' => $event_id, |
|
| 1322 | - ), admin_url('admin.php')); |
|
| 1323 | - //next and previous links |
|
| 1324 | - $next_reg = $this->_registration->next(null, array(), 'REG_ID'); |
|
| 1325 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1326 | - ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1327 | - 'action' => 'view_registration', |
|
| 1328 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1329 | - ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : ''; |
|
| 1330 | - $previous_reg = $this->_registration->previous(null, array(), 'REG_ID'); |
|
| 1331 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1332 | - ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1333 | - 'action' => 'view_registration', |
|
| 1334 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1335 | - ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
|
| 1336 | - // grab header |
|
| 1337 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1338 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1339 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 1340 | - $this->_template_args, true); |
|
| 1341 | - } else { |
|
| 1342 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1343 | - } |
|
| 1344 | - // the details template wrapper |
|
| 1345 | - $this->display_admin_page_with_sidebar(); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - |
|
| 1349 | - protected function _registration_details_metaboxes() |
|
| 1350 | - { |
|
| 1351 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1352 | - $this->_set_registration_object(); |
|
| 1353 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1354 | - add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'), |
|
| 1355 | - array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1356 | - add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'), |
|
| 1357 | - array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1358 | - if ($attendee instanceof EE_Attendee |
|
| 1359 | - && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox') |
|
| 1360 | - ) { |
|
| 1361 | - add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'), |
|
| 1362 | - array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1363 | - } |
|
| 1364 | - add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'), |
|
| 1365 | - array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high'); |
|
| 1366 | - if ($this->_registration->group_size() > 1) { |
|
| 1367 | - add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1368 | - array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - |
|
| 1373 | - /** |
|
| 1374 | - * set_reg_status_buttons_metabox |
|
| 1375 | - * |
|
| 1376 | - * @access protected |
|
| 1377 | - * @return string |
|
| 1378 | - * @throws \EE_Error |
|
| 1379 | - */ |
|
| 1380 | - public function set_reg_status_buttons_metabox() |
|
| 1381 | - { |
|
| 1382 | - $this->_set_registration_object(); |
|
| 1383 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1384 | - echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array( |
|
| 1385 | - 'action' => 'change_reg_status', |
|
| 1386 | - ), REG_ADMIN_URL)); |
|
| 1387 | - echo $change_reg_status_form->get_html(); |
|
| 1388 | - echo $change_reg_status_form->form_close(); |
|
| 1389 | - } |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - /** |
|
| 1393 | - * @return EE_Form_Section_Proper |
|
| 1394 | - */ |
|
| 1395 | - protected function _generate_reg_status_change_form() |
|
| 1396 | - { |
|
| 1397 | - return new EE_Form_Section_Proper(array( |
|
| 1398 | - 'name' => 'reg_status_change_form', |
|
| 1399 | - 'html_id' => 'reg-status-change-form', |
|
| 1400 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1401 | - 'subsections' => array( |
|
| 1402 | - 'return' => new EE_Hidden_Input(array( |
|
| 1403 | - 'name' => 'return', |
|
| 1404 | - 'default' => 'view_registration', |
|
| 1405 | - )), |
|
| 1406 | - 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1407 | - 'name' => 'REG_ID', |
|
| 1408 | - 'default' => $this->_registration->ID(), |
|
| 1409 | - )), |
|
| 1410 | - 'current_status' => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status', |
|
| 1411 | - 'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1412 | - '', 'status-' . $this->_registration->status_ID(), |
|
| 1413 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;')))), |
|
| 1414 | - 'reg_status' => new EE_Select_Input($this->_get_reg_statuses(), array( |
|
| 1415 | - 'html_label_text' => __('Change Registration Status to', 'event_espresso'), |
|
| 1416 | - 'default' => $this->_registration->status_ID(), |
|
| 1417 | - )), |
|
| 1418 | - 'send_notifications' => new EE_Yes_No_Input(array( |
|
| 1419 | - 'html_label_text' => __('Send Related Messages', 'event_espresso'), |
|
| 1420 | - 'default' => false, |
|
| 1421 | - 'html_help_text' => __('If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1422 | - 'event_espresso'), |
|
| 1423 | - )), |
|
| 1424 | - 'submit' => new EE_Submit_Input(array( |
|
| 1425 | - 'html_class' => 'button-primary', |
|
| 1426 | - 'html_label_text' => ' ', |
|
| 1427 | - 'default' => __('Update Registration Status', 'event_espresso'), |
|
| 1428 | - )), |
|
| 1429 | - ), |
|
| 1430 | - )); |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1437 | - * |
|
| 1438 | - * @return array |
|
| 1439 | - */ |
|
| 1440 | - protected function _get_reg_statuses() |
|
| 1441 | - { |
|
| 1442 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1443 | - unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1444 | - // get current reg status |
|
| 1445 | - $current_status = $this->_registration->status_ID(); |
|
| 1446 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1447 | - if ($current_status != EEM_Registration::status_id_pending_payment |
|
| 1448 | - && $this->_registration->transaction() |
|
| 1449 | - ->is_free() |
|
| 1450 | - ) { |
|
| 1451 | - unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1452 | - } |
|
| 1453 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1459 | - * |
|
| 1460 | - * @param bool $status REG status given for changing registrations to. |
|
| 1461 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1462 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1463 | - */ |
|
| 1464 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1465 | - { |
|
| 1466 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1467 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1468 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1469 | - } else { |
|
| 1470 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1471 | - } |
|
| 1472 | - $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1473 | - //notify? |
|
| 1474 | - if ($success |
|
| 1475 | - && $notify |
|
| 1476 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1477 | - 'espresso_registrations_resend_registration') |
|
| 1478 | - ) { |
|
| 1479 | - $this->_process_resend_registration(); |
|
| 1480 | - } |
|
| 1481 | - return $success; |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1487 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1488 | - * |
|
| 1489 | - * @param array $REG_IDs |
|
| 1490 | - * @param bool $status |
|
| 1491 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1492 | - * the array of updated registrations). |
|
| 1493 | - */ |
|
| 1494 | - protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1495 | - { |
|
| 1496 | - $success = false; |
|
| 1497 | - // typecast $REG_IDs |
|
| 1498 | - $REG_IDs = (array)$REG_IDs; |
|
| 1499 | - if ( ! empty($REG_IDs)) { |
|
| 1500 | - $success = true; |
|
| 1501 | - // set default status if none is passed |
|
| 1502 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1503 | - // sanitize $REG_IDs |
|
| 1504 | - $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1505 | - //loop through REG_ID's and change status |
|
| 1506 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1507 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1508 | - if ($registration instanceof EE_Registration) { |
|
| 1509 | - $registration->set_status($status); |
|
| 1510 | - $result = $registration->save(); |
|
| 1511 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1512 | - $success = $result !== false ? $success : false; |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - } |
|
| 1516 | - //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1517 | - $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1518 | - //return $success and processed registrations |
|
| 1519 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1525 | - * |
|
| 1526 | - * @param string $STS_ID status id for the registration changed to |
|
| 1527 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1528 | - * @return void |
|
| 1529 | - */ |
|
| 1530 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1531 | - { |
|
| 1532 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1533 | - : array('success' => false); |
|
| 1534 | - $success = isset($result['success']) && $result['success']; |
|
| 1535 | - //setup success message |
|
| 1536 | - if ($success) { |
|
| 1537 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1538 | - $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'), |
|
| 1539 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1540 | - } else { |
|
| 1541 | - $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1542 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1543 | - } |
|
| 1544 | - EE_Error::add_success($msg); |
|
| 1545 | - } else { |
|
| 1546 | - EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__, |
|
| 1547 | - __LINE__, __FUNCTION__); |
|
| 1548 | - } |
|
| 1549 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1550 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1551 | - } else { |
|
| 1552 | - $route = array('action' => 'default'); |
|
| 1553 | - } |
|
| 1554 | - //unset nonces |
|
| 1555 | - foreach ($this->_req_data as $ref => $value) { |
|
| 1556 | - if (strpos($ref, 'nonce') !== false) { |
|
| 1557 | - unset($this->_req_data[$ref]); |
|
| 1558 | - continue; |
|
| 1559 | - } |
|
| 1560 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1561 | - $this->_req_data[$ref] = $value; |
|
| 1562 | - } |
|
| 1563 | - //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1564 | - $route = array_merge($this->_req_data, $route); |
|
| 1565 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - |
|
| 1569 | - /** |
|
| 1570 | - * incoming reg status change from reg details page. |
|
| 1571 | - * |
|
| 1572 | - * @return void |
|
| 1573 | - */ |
|
| 1574 | - protected function _change_reg_status() |
|
| 1575 | - { |
|
| 1576 | - $this->_req_data['return'] = 'view_registration'; |
|
| 1577 | - //set notify based on whether the send notifications toggle is set or not |
|
| 1578 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1579 | - //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1580 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1581 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1582 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1583 | - case EEM_Registration::status_id_approved : |
|
| 1584 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1585 | - $this->approve_registration($notify); |
|
| 1586 | - break; |
|
| 1587 | - case EEM_Registration::status_id_pending_payment : |
|
| 1588 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1589 | - $this->pending_registration($notify); |
|
| 1590 | - break; |
|
| 1591 | - case EEM_Registration::status_id_not_approved : |
|
| 1592 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1593 | - $this->not_approve_registration($notify); |
|
| 1594 | - break; |
|
| 1595 | - case EEM_Registration::status_id_declined : |
|
| 1596 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1597 | - $this->decline_registration($notify); |
|
| 1598 | - break; |
|
| 1599 | - case EEM_Registration::status_id_cancelled : |
|
| 1600 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1601 | - $this->cancel_registration($notify); |
|
| 1602 | - break; |
|
| 1603 | - case EEM_Registration::status_id_wait_list : |
|
| 1604 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1605 | - $this->waitlist_registration($notify); |
|
| 1606 | - break; |
|
| 1607 | - case EEM_Registration::status_id_incomplete : |
|
| 1608 | - default : |
|
| 1609 | - $result['success'] = false; |
|
| 1610 | - unset($this->_req_data['return']); |
|
| 1611 | - $this->_reg_status_change_return('', false); |
|
| 1612 | - break; |
|
| 1613 | - } |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - |
|
| 1617 | - /** |
|
| 1618 | - * approve_registration |
|
| 1619 | - * |
|
| 1620 | - * @access protected |
|
| 1621 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1622 | - * @return void |
|
| 1623 | - */ |
|
| 1624 | - protected function approve_registration($notify = false) |
|
| 1625 | - { |
|
| 1626 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1627 | - } |
|
| 1628 | - |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * decline_registration |
|
| 1632 | - * |
|
| 1633 | - * @access protected |
|
| 1634 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1635 | - * @return void |
|
| 1636 | - */ |
|
| 1637 | - protected function decline_registration($notify = false) |
|
| 1638 | - { |
|
| 1639 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * cancel_registration |
|
| 1645 | - * |
|
| 1646 | - * @access protected |
|
| 1647 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1648 | - * @return void |
|
| 1649 | - */ |
|
| 1650 | - protected function cancel_registration($notify = false) |
|
| 1651 | - { |
|
| 1652 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - |
|
| 1656 | - /** |
|
| 1657 | - * not_approve_registration |
|
| 1658 | - * |
|
| 1659 | - * @access protected |
|
| 1660 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1661 | - * @return void |
|
| 1662 | - */ |
|
| 1663 | - protected function not_approve_registration($notify = false) |
|
| 1664 | - { |
|
| 1665 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1666 | - } |
|
| 1667 | - |
|
| 1668 | - |
|
| 1669 | - /** |
|
| 1670 | - * decline_registration |
|
| 1671 | - * |
|
| 1672 | - * @access protected |
|
| 1673 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1674 | - * @return void |
|
| 1675 | - */ |
|
| 1676 | - protected function pending_registration($notify = false) |
|
| 1677 | - { |
|
| 1678 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - |
|
| 1682 | - /** |
|
| 1683 | - * waitlist_registration |
|
| 1684 | - * |
|
| 1685 | - * @access protected |
|
| 1686 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1687 | - * @return void |
|
| 1688 | - */ |
|
| 1689 | - protected function waitlist_registration($notify = false) |
|
| 1690 | - { |
|
| 1691 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * generates HTML for the Registration main meta box |
|
| 1697 | - * |
|
| 1698 | - * @access public |
|
| 1699 | - * @return void |
|
| 1700 | - */ |
|
| 1701 | - public function _reg_details_meta_box() |
|
| 1702 | - { |
|
| 1703 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1704 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1705 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1706 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1707 | - : EE_Transaction::new_instance(); |
|
| 1708 | - $this->_session = $transaction->session_data(); |
|
| 1709 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1710 | - //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1711 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1712 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1713 | - $transaction->total_line_item()); |
|
| 1714 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1715 | - $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1716 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1717 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, |
|
| 1718 | - array('EE_Registration' => $this->_registration)); |
|
| 1719 | - $attendee = $this->_registration->attendee(); |
|
| 1720 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 1721 | - 'espresso_transactions_view_transaction') |
|
| 1722 | - ) { |
|
| 1723 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1724 | - 'action' => 'view_transaction', |
|
| 1725 | - 'TXN_ID' => $transaction->ID(), |
|
| 1726 | - ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right', |
|
| 1727 | - 'dashicons dashicons-cart'); |
|
| 1728 | - } else { |
|
| 1729 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 1730 | - } |
|
| 1731 | - if ($attendee instanceof EE_Attendee |
|
| 1732 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1733 | - 'espresso_registrations_resend_registration') |
|
| 1734 | - ) { |
|
| 1735 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1736 | - 'action' => 'resend_registration', |
|
| 1737 | - '_REG_ID' => $this->_registration->ID(), |
|
| 1738 | - 'redirect_to' => 'view_registration', |
|
| 1739 | - ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right', |
|
| 1740 | - 'dashicons dashicons-email-alt'); |
|
| 1741 | - } else { |
|
| 1742 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 1743 | - } |
|
| 1744 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1745 | - $payment = $transaction->get_first_related('Payment'); |
|
| 1746 | - $payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment; |
|
| 1747 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1748 | - $payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() |
|
| 1749 | - : $payment_method; |
|
| 1750 | - $reg_details = array( |
|
| 1751 | - 'payment_method' => $payment_method->name(), |
|
| 1752 | - 'response_msg' => $payment->gateway_response(), |
|
| 1753 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1754 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 1755 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1756 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1757 | - ); |
|
| 1758 | - if (isset($reg_details['registration_id'])) { |
|
| 1759 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1760 | - $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso'); |
|
| 1761 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 1762 | - } |
|
| 1763 | - if (isset($reg_details['payment_method'])) { |
|
| 1764 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 1765 | - $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', |
|
| 1766 | - 'event_espresso'); |
|
| 1767 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 1768 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 1769 | - $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', |
|
| 1770 | - 'event_espresso'); |
|
| 1771 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 1772 | - } |
|
| 1773 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 1774 | - $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', |
|
| 1775 | - 'event_espresso'); |
|
| 1776 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 1777 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 1778 | - $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', |
|
| 1779 | - 'event_espresso'); |
|
| 1780 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 1781 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 1782 | - $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', |
|
| 1783 | - 'event_espresso'); |
|
| 1784 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 1785 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1786 | - 'action' => 'default', |
|
| 1787 | - 'event_id' => $this->_registration->event_ID(), |
|
| 1788 | - ), REG_ADMIN_URL); |
|
| 1789 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1790 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 1791 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1792 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - |
|
| 1796 | - /** |
|
| 1797 | - * generates HTML for the Registration Questions meta box. |
|
| 1798 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 1799 | - * otherwise uses new forms system |
|
| 1800 | - * |
|
| 1801 | - * @access public |
|
| 1802 | - * @return void |
|
| 1803 | - */ |
|
| 1804 | - public function _reg_questions_meta_box() |
|
| 1805 | - { |
|
| 1806 | - //allow someone to override this method entirely |
|
| 1807 | - if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 1808 | - $this->_registration)) { |
|
| 1809 | - $form = $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 1810 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 ? $form->get_html_and_js() : ''; |
|
| 1811 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 1812 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1813 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1814 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1815 | - } |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * form_before_question_group |
|
| 1821 | - * |
|
| 1822 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1823 | - * @access public |
|
| 1824 | - * @param string $output |
|
| 1825 | - * @return string |
|
| 1826 | - */ |
|
| 1827 | - public function form_before_question_group($output) |
|
| 1828 | - { |
|
| 1829 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1830 | - __('This method would have been protected but was used on a filter callback' |
|
| 1831 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1832 | - '4.8.32.rc.000'); |
|
| 1833 | - return ' |
|
| 1050 | + if ( ! empty($registration_status)) { |
|
| 1051 | + $where['STS_ID'] = $registration_status; |
|
| 1052 | + } else { |
|
| 1053 | + //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1054 | + if ($view === 'trash') { |
|
| 1055 | + $where['REG_deleted'] = true; |
|
| 1056 | + } else if ($view === 'incomplete') { |
|
| 1057 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1058 | + } else { |
|
| 1059 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + return $where; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + |
|
| 1066 | + /** |
|
| 1067 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1068 | + * |
|
| 1069 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1070 | + * @return array |
|
| 1071 | + */ |
|
| 1072 | + protected function _add_date_to_where_conditions(array $request) |
|
| 1073 | + { |
|
| 1074 | + $where = array(); |
|
| 1075 | + $view = EEH_Array::is_set( $request, 'status', '' ); |
|
| 1076 | + $month_range = ! empty($request['month_range']) |
|
| 1077 | + ? sanitize_text_field($request['month_range']) |
|
| 1078 | + : ''; |
|
| 1079 | + $retrieve_for_today = $view === 'today'; |
|
| 1080 | + $retrieve_for_this_month = $view === 'month'; |
|
| 1081 | + |
|
| 1082 | + if ($retrieve_for_today) { |
|
| 1083 | + $now = date('Y-m-d', current_time('timestamp')); |
|
| 1084 | + $where['REG_date'] = array( |
|
| 1085 | + 'BETWEEN', |
|
| 1086 | + array( |
|
| 1087 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1088 | + 'REG_date', |
|
| 1089 | + $now . ' 00:00:00', |
|
| 1090 | + 'Y-m-d H:i:s' |
|
| 1091 | + ), |
|
| 1092 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1093 | + 'REG_date', |
|
| 1094 | + $now . ' 23:59:59', |
|
| 1095 | + 'Y-m-d H:i:s' |
|
| 1096 | + ), |
|
| 1097 | + ), |
|
| 1098 | + ); |
|
| 1099 | + } elseif ($retrieve_for_this_month) { |
|
| 1100 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1101 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 1102 | + $where['REG_date'] = array( |
|
| 1103 | + 'BETWEEN', |
|
| 1104 | + array( |
|
| 1105 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1106 | + 'REG_date', |
|
| 1107 | + $current_year_and_month . '-01 00:00:00', |
|
| 1108 | + 'Y-m-d H:i:s' |
|
| 1109 | + ), |
|
| 1110 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1111 | + 'REG_date', |
|
| 1112 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1113 | + 'Y-m-d H:i:s' |
|
| 1114 | + ), |
|
| 1115 | + ), |
|
| 1116 | + ); |
|
| 1117 | + } elseif ($month_range) { |
|
| 1118 | + $pieces = explode(' ', $month_range, 3); |
|
| 1119 | + $month_requested = ! empty($pieces[0]) |
|
| 1120 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1121 | + : ''; |
|
| 1122 | + $year_requested = ! empty($pieces[1]) |
|
| 1123 | + ? $pieces[1] |
|
| 1124 | + : ''; |
|
| 1125 | + //if there is not a month or year then we can't go further |
|
| 1126 | + if ($month_requested && $year_requested) { |
|
| 1127 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1128 | + $where['REG_date'] = array( |
|
| 1129 | + 'BETWEEN', |
|
| 1130 | + array( |
|
| 1131 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1132 | + 'REG_date', |
|
| 1133 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1134 | + 'Y-m-d H:i:s' |
|
| 1135 | + ), |
|
| 1136 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1137 | + 'REG_date', |
|
| 1138 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1139 | + 'Y-m-d H:i:s' |
|
| 1140 | + ), |
|
| 1141 | + ), |
|
| 1142 | + ); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + return $where; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + |
|
| 1149 | + /** |
|
| 1150 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1151 | + * |
|
| 1152 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1153 | + * @return array |
|
| 1154 | + */ |
|
| 1155 | + protected function _add_search_to_where_conditions(array $request) |
|
| 1156 | + { |
|
| 1157 | + $where = array(); |
|
| 1158 | + if ( ! empty($request['s'])) { |
|
| 1159 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1160 | + $where['OR'] = array( |
|
| 1161 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1162 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1163 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1164 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1165 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1166 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1167 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1168 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1169 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1170 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1171 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1172 | + 'REG_final_price' => array('LIKE', $search_string), |
|
| 1173 | + 'REG_code' => array('LIKE', $search_string), |
|
| 1174 | + 'REG_count' => array('LIKE', $search_string), |
|
| 1175 | + 'REG_group_size' => array('LIKE', $search_string), |
|
| 1176 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1177 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1178 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1179 | + ); |
|
| 1180 | + } |
|
| 1181 | + return $where; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Sets up the where conditions for the registrations query. |
|
| 1187 | + * |
|
| 1188 | + * @param array $request |
|
| 1189 | + * @return array |
|
| 1190 | + */ |
|
| 1191 | + protected function _get_where_conditions_for_registrations_query($request) |
|
| 1192 | + { |
|
| 1193 | + return array_merge( |
|
| 1194 | + $this->_add_event_id_to_where_conditions($request), |
|
| 1195 | + $this->_add_category_id_to_where_conditions($request), |
|
| 1196 | + $this->_add_datetime_id_to_where_conditions($request), |
|
| 1197 | + $this->_add_registration_status_to_where_conditions($request), |
|
| 1198 | + $this->_add_date_to_where_conditions($request), |
|
| 1199 | + $this->_add_search_to_where_conditions($request) |
|
| 1200 | + ); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + |
|
| 1204 | + /** |
|
| 1205 | + * Sets up the orderby for the registrations query. |
|
| 1206 | + * |
|
| 1207 | + * @return array |
|
| 1208 | + */ |
|
| 1209 | + protected function _get_orderby_for_registrations_query() |
|
| 1210 | + { |
|
| 1211 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1212 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1213 | + : ''; |
|
| 1214 | + switch ($orderby_field) { |
|
| 1215 | + case '_REG_ID': |
|
| 1216 | + $orderby_field = 'REG_ID'; |
|
| 1217 | + break; |
|
| 1218 | + case '_Reg_status': |
|
| 1219 | + $orderby_field = 'STS_ID'; |
|
| 1220 | + break; |
|
| 1221 | + case 'ATT_fname': |
|
| 1222 | + $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1223 | + break; |
|
| 1224 | + case 'ATT_lname' : |
|
| 1225 | + $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1226 | + break; |
|
| 1227 | + case 'event_name': |
|
| 1228 | + $orderby_field = 'Event.EVT_name'; |
|
| 1229 | + break; |
|
| 1230 | + case 'DTT_EVT_start': |
|
| 1231 | + $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1232 | + break; |
|
| 1233 | + default: //'REG_date' |
|
| 1234 | + $orderby_field = 'REG_date'; |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + //order |
|
| 1238 | + $order = ! empty($this->_req_data['order']) |
|
| 1239 | + ? sanitize_text_field($this->_req_data['order']) |
|
| 1240 | + : 'DESC'; |
|
| 1241 | + |
|
| 1242 | + //mutate orderby_field |
|
| 1243 | + $orderby_field = array_combine( |
|
| 1244 | + (array) $orderby_field, |
|
| 1245 | + array_fill(0, count($orderby_field), $order) |
|
| 1246 | + ); |
|
| 1247 | + return array('order_by' => $orderby_field); |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * Sets up the limit for the registrations query. |
|
| 1253 | + * |
|
| 1254 | + * @param $per_page |
|
| 1255 | + * @return array |
|
| 1256 | + */ |
|
| 1257 | + protected function _get_limit($per_page) |
|
| 1258 | + { |
|
| 1259 | + $current_page = ! empty($this->_req_data['paged']) |
|
| 1260 | + ? absint($this->_req_data['paged']) |
|
| 1261 | + : 1; |
|
| 1262 | + $per_page = ! empty($this->_req_data['perpage']) |
|
| 1263 | + ? $this->_req_data['perpage'] |
|
| 1264 | + : $per_page; |
|
| 1265 | + |
|
| 1266 | + //-1 means return all results so get out if that's set. |
|
| 1267 | + if ((int)$per_page === -1) { |
|
| 1268 | + return array(); |
|
| 1269 | + } |
|
| 1270 | + $per_page = absint($per_page); |
|
| 1271 | + $offset = ($current_page - 1) * $per_page; |
|
| 1272 | + return array('limit' => array($offset, $per_page)); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + public function get_registration_status_array() |
|
| 1277 | + { |
|
| 1278 | + return self::$_reg_status; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + |
|
| 1283 | + |
|
| 1284 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1285 | + /** |
|
| 1286 | + * generates HTML for the View Registration Details Admin page |
|
| 1287 | + * |
|
| 1288 | + * @access protected |
|
| 1289 | + * @return void |
|
| 1290 | + */ |
|
| 1291 | + protected function _registration_details() |
|
| 1292 | + { |
|
| 1293 | + $this->_template_args = array(); |
|
| 1294 | + $this->_set_registration_object(); |
|
| 1295 | + if (is_object($this->_registration)) { |
|
| 1296 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1297 | + : EE_Transaction::new_instance(); |
|
| 1298 | + $this->_session = $transaction->session_data(); |
|
| 1299 | + $event_id = $this->_registration->event_ID(); |
|
| 1300 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1301 | + $this->_template_args['reg_nmbr']['label'] = __('Registration Number', 'event_espresso'); |
|
| 1302 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1303 | + $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso'); |
|
| 1304 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1305 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1306 | + // link back to overview |
|
| 1307 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1308 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1309 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1310 | + 'action' => 'default', |
|
| 1311 | + 'event_id' => $event_id, |
|
| 1312 | + ), REG_ADMIN_URL); |
|
| 1313 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1314 | + 'action' => 'default', |
|
| 1315 | + 'EVT_ID' => $event_id, |
|
| 1316 | + 'page' => 'espresso_transactions', |
|
| 1317 | + ), admin_url('admin.php')); |
|
| 1318 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1319 | + 'page' => 'espresso_events', |
|
| 1320 | + 'action' => 'edit', |
|
| 1321 | + 'post' => $event_id, |
|
| 1322 | + ), admin_url('admin.php')); |
|
| 1323 | + //next and previous links |
|
| 1324 | + $next_reg = $this->_registration->next(null, array(), 'REG_ID'); |
|
| 1325 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1326 | + ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1327 | + 'action' => 'view_registration', |
|
| 1328 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1329 | + ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : ''; |
|
| 1330 | + $previous_reg = $this->_registration->previous(null, array(), 'REG_ID'); |
|
| 1331 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1332 | + ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1333 | + 'action' => 'view_registration', |
|
| 1334 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1335 | + ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : ''; |
|
| 1336 | + // grab header |
|
| 1337 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1338 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1339 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, |
|
| 1340 | + $this->_template_args, true); |
|
| 1341 | + } else { |
|
| 1342 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1343 | + } |
|
| 1344 | + // the details template wrapper |
|
| 1345 | + $this->display_admin_page_with_sidebar(); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + |
|
| 1349 | + protected function _registration_details_metaboxes() |
|
| 1350 | + { |
|
| 1351 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1352 | + $this->_set_registration_object(); |
|
| 1353 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1354 | + add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'), |
|
| 1355 | + array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1356 | + add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'), |
|
| 1357 | + array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1358 | + if ($attendee instanceof EE_Attendee |
|
| 1359 | + && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox') |
|
| 1360 | + ) { |
|
| 1361 | + add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'), |
|
| 1362 | + array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1363 | + } |
|
| 1364 | + add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'), |
|
| 1365 | + array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high'); |
|
| 1366 | + if ($this->_registration->group_size() > 1) { |
|
| 1367 | + add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1368 | + array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + |
|
| 1373 | + /** |
|
| 1374 | + * set_reg_status_buttons_metabox |
|
| 1375 | + * |
|
| 1376 | + * @access protected |
|
| 1377 | + * @return string |
|
| 1378 | + * @throws \EE_Error |
|
| 1379 | + */ |
|
| 1380 | + public function set_reg_status_buttons_metabox() |
|
| 1381 | + { |
|
| 1382 | + $this->_set_registration_object(); |
|
| 1383 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1384 | + echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array( |
|
| 1385 | + 'action' => 'change_reg_status', |
|
| 1386 | + ), REG_ADMIN_URL)); |
|
| 1387 | + echo $change_reg_status_form->get_html(); |
|
| 1388 | + echo $change_reg_status_form->form_close(); |
|
| 1389 | + } |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + /** |
|
| 1393 | + * @return EE_Form_Section_Proper |
|
| 1394 | + */ |
|
| 1395 | + protected function _generate_reg_status_change_form() |
|
| 1396 | + { |
|
| 1397 | + return new EE_Form_Section_Proper(array( |
|
| 1398 | + 'name' => 'reg_status_change_form', |
|
| 1399 | + 'html_id' => 'reg-status-change-form', |
|
| 1400 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1401 | + 'subsections' => array( |
|
| 1402 | + 'return' => new EE_Hidden_Input(array( |
|
| 1403 | + 'name' => 'return', |
|
| 1404 | + 'default' => 'view_registration', |
|
| 1405 | + )), |
|
| 1406 | + 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1407 | + 'name' => 'REG_ID', |
|
| 1408 | + 'default' => $this->_registration->ID(), |
|
| 1409 | + )), |
|
| 1410 | + 'current_status' => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status', |
|
| 1411 | + 'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(), |
|
| 1412 | + '', 'status-' . $this->_registration->status_ID(), |
|
| 1413 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;')))), |
|
| 1414 | + 'reg_status' => new EE_Select_Input($this->_get_reg_statuses(), array( |
|
| 1415 | + 'html_label_text' => __('Change Registration Status to', 'event_espresso'), |
|
| 1416 | + 'default' => $this->_registration->status_ID(), |
|
| 1417 | + )), |
|
| 1418 | + 'send_notifications' => new EE_Yes_No_Input(array( |
|
| 1419 | + 'html_label_text' => __('Send Related Messages', 'event_espresso'), |
|
| 1420 | + 'default' => false, |
|
| 1421 | + 'html_help_text' => __('If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1422 | + 'event_espresso'), |
|
| 1423 | + )), |
|
| 1424 | + 'submit' => new EE_Submit_Input(array( |
|
| 1425 | + 'html_class' => 'button-primary', |
|
| 1426 | + 'html_label_text' => ' ', |
|
| 1427 | + 'default' => __('Update Registration Status', 'event_espresso'), |
|
| 1428 | + )), |
|
| 1429 | + ), |
|
| 1430 | + )); |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1437 | + * |
|
| 1438 | + * @return array |
|
| 1439 | + */ |
|
| 1440 | + protected function _get_reg_statuses() |
|
| 1441 | + { |
|
| 1442 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1443 | + unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1444 | + // get current reg status |
|
| 1445 | + $current_status = $this->_registration->status_ID(); |
|
| 1446 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1447 | + if ($current_status != EEM_Registration::status_id_pending_payment |
|
| 1448 | + && $this->_registration->transaction() |
|
| 1449 | + ->is_free() |
|
| 1450 | + ) { |
|
| 1451 | + unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1452 | + } |
|
| 1453 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1459 | + * |
|
| 1460 | + * @param bool $status REG status given for changing registrations to. |
|
| 1461 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1462 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1463 | + */ |
|
| 1464 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1465 | + { |
|
| 1466 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1467 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1468 | + ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1469 | + } else { |
|
| 1470 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1471 | + } |
|
| 1472 | + $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1473 | + //notify? |
|
| 1474 | + if ($success |
|
| 1475 | + && $notify |
|
| 1476 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1477 | + 'espresso_registrations_resend_registration') |
|
| 1478 | + ) { |
|
| 1479 | + $this->_process_resend_registration(); |
|
| 1480 | + } |
|
| 1481 | + return $success; |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1487 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1488 | + * |
|
| 1489 | + * @param array $REG_IDs |
|
| 1490 | + * @param bool $status |
|
| 1491 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1492 | + * the array of updated registrations). |
|
| 1493 | + */ |
|
| 1494 | + protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1495 | + { |
|
| 1496 | + $success = false; |
|
| 1497 | + // typecast $REG_IDs |
|
| 1498 | + $REG_IDs = (array)$REG_IDs; |
|
| 1499 | + if ( ! empty($REG_IDs)) { |
|
| 1500 | + $success = true; |
|
| 1501 | + // set default status if none is passed |
|
| 1502 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1503 | + // sanitize $REG_IDs |
|
| 1504 | + $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1505 | + //loop through REG_ID's and change status |
|
| 1506 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1507 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1508 | + if ($registration instanceof EE_Registration) { |
|
| 1509 | + $registration->set_status($status); |
|
| 1510 | + $result = $registration->save(); |
|
| 1511 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1512 | + $success = $result !== false ? $success : false; |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + } |
|
| 1516 | + //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1517 | + $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1518 | + //return $success and processed registrations |
|
| 1519 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1525 | + * |
|
| 1526 | + * @param string $STS_ID status id for the registration changed to |
|
| 1527 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1528 | + * @return void |
|
| 1529 | + */ |
|
| 1530 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1531 | + { |
|
| 1532 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1533 | + : array('success' => false); |
|
| 1534 | + $success = isset($result['success']) && $result['success']; |
|
| 1535 | + //setup success message |
|
| 1536 | + if ($success) { |
|
| 1537 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1538 | + $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'), |
|
| 1539 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1540 | + } else { |
|
| 1541 | + $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1542 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1543 | + } |
|
| 1544 | + EE_Error::add_success($msg); |
|
| 1545 | + } else { |
|
| 1546 | + EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__, |
|
| 1547 | + __LINE__, __FUNCTION__); |
|
| 1548 | + } |
|
| 1549 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1550 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1551 | + } else { |
|
| 1552 | + $route = array('action' => 'default'); |
|
| 1553 | + } |
|
| 1554 | + //unset nonces |
|
| 1555 | + foreach ($this->_req_data as $ref => $value) { |
|
| 1556 | + if (strpos($ref, 'nonce') !== false) { |
|
| 1557 | + unset($this->_req_data[$ref]); |
|
| 1558 | + continue; |
|
| 1559 | + } |
|
| 1560 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1561 | + $this->_req_data[$ref] = $value; |
|
| 1562 | + } |
|
| 1563 | + //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1564 | + $route = array_merge($this->_req_data, $route); |
|
| 1565 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + |
|
| 1569 | + /** |
|
| 1570 | + * incoming reg status change from reg details page. |
|
| 1571 | + * |
|
| 1572 | + * @return void |
|
| 1573 | + */ |
|
| 1574 | + protected function _change_reg_status() |
|
| 1575 | + { |
|
| 1576 | + $this->_req_data['return'] = 'view_registration'; |
|
| 1577 | + //set notify based on whether the send notifications toggle is set or not |
|
| 1578 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1579 | + //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1580 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1581 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1582 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1583 | + case EEM_Registration::status_id_approved : |
|
| 1584 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1585 | + $this->approve_registration($notify); |
|
| 1586 | + break; |
|
| 1587 | + case EEM_Registration::status_id_pending_payment : |
|
| 1588 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1589 | + $this->pending_registration($notify); |
|
| 1590 | + break; |
|
| 1591 | + case EEM_Registration::status_id_not_approved : |
|
| 1592 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1593 | + $this->not_approve_registration($notify); |
|
| 1594 | + break; |
|
| 1595 | + case EEM_Registration::status_id_declined : |
|
| 1596 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1597 | + $this->decline_registration($notify); |
|
| 1598 | + break; |
|
| 1599 | + case EEM_Registration::status_id_cancelled : |
|
| 1600 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1601 | + $this->cancel_registration($notify); |
|
| 1602 | + break; |
|
| 1603 | + case EEM_Registration::status_id_wait_list : |
|
| 1604 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1605 | + $this->waitlist_registration($notify); |
|
| 1606 | + break; |
|
| 1607 | + case EEM_Registration::status_id_incomplete : |
|
| 1608 | + default : |
|
| 1609 | + $result['success'] = false; |
|
| 1610 | + unset($this->_req_data['return']); |
|
| 1611 | + $this->_reg_status_change_return('', false); |
|
| 1612 | + break; |
|
| 1613 | + } |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + |
|
| 1617 | + /** |
|
| 1618 | + * approve_registration |
|
| 1619 | + * |
|
| 1620 | + * @access protected |
|
| 1621 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1622 | + * @return void |
|
| 1623 | + */ |
|
| 1624 | + protected function approve_registration($notify = false) |
|
| 1625 | + { |
|
| 1626 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1627 | + } |
|
| 1628 | + |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * decline_registration |
|
| 1632 | + * |
|
| 1633 | + * @access protected |
|
| 1634 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1635 | + * @return void |
|
| 1636 | + */ |
|
| 1637 | + protected function decline_registration($notify = false) |
|
| 1638 | + { |
|
| 1639 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + |
|
| 1643 | + /** |
|
| 1644 | + * cancel_registration |
|
| 1645 | + * |
|
| 1646 | + * @access protected |
|
| 1647 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1648 | + * @return void |
|
| 1649 | + */ |
|
| 1650 | + protected function cancel_registration($notify = false) |
|
| 1651 | + { |
|
| 1652 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + |
|
| 1656 | + /** |
|
| 1657 | + * not_approve_registration |
|
| 1658 | + * |
|
| 1659 | + * @access protected |
|
| 1660 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1661 | + * @return void |
|
| 1662 | + */ |
|
| 1663 | + protected function not_approve_registration($notify = false) |
|
| 1664 | + { |
|
| 1665 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1666 | + } |
|
| 1667 | + |
|
| 1668 | + |
|
| 1669 | + /** |
|
| 1670 | + * decline_registration |
|
| 1671 | + * |
|
| 1672 | + * @access protected |
|
| 1673 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1674 | + * @return void |
|
| 1675 | + */ |
|
| 1676 | + protected function pending_registration($notify = false) |
|
| 1677 | + { |
|
| 1678 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + |
|
| 1682 | + /** |
|
| 1683 | + * waitlist_registration |
|
| 1684 | + * |
|
| 1685 | + * @access protected |
|
| 1686 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1687 | + * @return void |
|
| 1688 | + */ |
|
| 1689 | + protected function waitlist_registration($notify = false) |
|
| 1690 | + { |
|
| 1691 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * generates HTML for the Registration main meta box |
|
| 1697 | + * |
|
| 1698 | + * @access public |
|
| 1699 | + * @return void |
|
| 1700 | + */ |
|
| 1701 | + public function _reg_details_meta_box() |
|
| 1702 | + { |
|
| 1703 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1704 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1705 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1706 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1707 | + : EE_Transaction::new_instance(); |
|
| 1708 | + $this->_session = $transaction->session_data(); |
|
| 1709 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1710 | + //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1711 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1712 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1713 | + $transaction->total_line_item()); |
|
| 1714 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1715 | + $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1716 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1717 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree, |
|
| 1718 | + array('EE_Registration' => $this->_registration)); |
|
| 1719 | + $attendee = $this->_registration->attendee(); |
|
| 1720 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
| 1721 | + 'espresso_transactions_view_transaction') |
|
| 1722 | + ) { |
|
| 1723 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1724 | + 'action' => 'view_transaction', |
|
| 1725 | + 'TXN_ID' => $transaction->ID(), |
|
| 1726 | + ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right', |
|
| 1727 | + 'dashicons dashicons-cart'); |
|
| 1728 | + } else { |
|
| 1729 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 1730 | + } |
|
| 1731 | + if ($attendee instanceof EE_Attendee |
|
| 1732 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
| 1733 | + 'espresso_registrations_resend_registration') |
|
| 1734 | + ) { |
|
| 1735 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1736 | + 'action' => 'resend_registration', |
|
| 1737 | + '_REG_ID' => $this->_registration->ID(), |
|
| 1738 | + 'redirect_to' => 'view_registration', |
|
| 1739 | + ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right', |
|
| 1740 | + 'dashicons dashicons-email-alt'); |
|
| 1741 | + } else { |
|
| 1742 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 1743 | + } |
|
| 1744 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1745 | + $payment = $transaction->get_first_related('Payment'); |
|
| 1746 | + $payment = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment; |
|
| 1747 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1748 | + $payment_method = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance() |
|
| 1749 | + : $payment_method; |
|
| 1750 | + $reg_details = array( |
|
| 1751 | + 'payment_method' => $payment_method->name(), |
|
| 1752 | + 'response_msg' => $payment->gateway_response(), |
|
| 1753 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1754 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 1755 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1756 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1757 | + ); |
|
| 1758 | + if (isset($reg_details['registration_id'])) { |
|
| 1759 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1760 | + $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso'); |
|
| 1761 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 1762 | + } |
|
| 1763 | + if (isset($reg_details['payment_method'])) { |
|
| 1764 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 1765 | + $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method', |
|
| 1766 | + 'event_espresso'); |
|
| 1767 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 1768 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 1769 | + $this->_template_args['reg_details']['response_msg']['label'] = __('Payment method response', |
|
| 1770 | + 'event_espresso'); |
|
| 1771 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 1772 | + } |
|
| 1773 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 1774 | + $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session', |
|
| 1775 | + 'event_espresso'); |
|
| 1776 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 1777 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 1778 | + $this->_template_args['reg_details']['ip_address']['label'] = __('Registration placed from IP', |
|
| 1779 | + 'event_espresso'); |
|
| 1780 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 1781 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 1782 | + $this->_template_args['reg_details']['user_agent']['label'] = __('Registrant User Agent', |
|
| 1783 | + 'event_espresso'); |
|
| 1784 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 1785 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1786 | + 'action' => 'default', |
|
| 1787 | + 'event_id' => $this->_registration->event_ID(), |
|
| 1788 | + ), REG_ADMIN_URL); |
|
| 1789 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1790 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 1791 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 1792 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + |
|
| 1796 | + /** |
|
| 1797 | + * generates HTML for the Registration Questions meta box. |
|
| 1798 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 1799 | + * otherwise uses new forms system |
|
| 1800 | + * |
|
| 1801 | + * @access public |
|
| 1802 | + * @return void |
|
| 1803 | + */ |
|
| 1804 | + public function _reg_questions_meta_box() |
|
| 1805 | + { |
|
| 1806 | + //allow someone to override this method entirely |
|
| 1807 | + if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 1808 | + $this->_registration)) { |
|
| 1809 | + $form = $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 1810 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 ? $form->get_html_and_js() : ''; |
|
| 1811 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 1812 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1813 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 1814 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1815 | + } |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * form_before_question_group |
|
| 1821 | + * |
|
| 1822 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1823 | + * @access public |
|
| 1824 | + * @param string $output |
|
| 1825 | + * @return string |
|
| 1826 | + */ |
|
| 1827 | + public function form_before_question_group($output) |
|
| 1828 | + { |
|
| 1829 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1830 | + __('This method would have been protected but was used on a filter callback' |
|
| 1831 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1832 | + '4.8.32.rc.000'); |
|
| 1833 | + return ' |
|
| 1834 | 1834 | <table class="form-table ee-width-100"> |
| 1835 | 1835 | <tbody> |
| 1836 | 1836 | '; |
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - |
|
| 1840 | - /** |
|
| 1841 | - * form_after_question_group |
|
| 1842 | - * |
|
| 1843 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1844 | - * @access public |
|
| 1845 | - * @param string $output |
|
| 1846 | - * @return string |
|
| 1847 | - */ |
|
| 1848 | - public function form_after_question_group($output) |
|
| 1849 | - { |
|
| 1850 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1851 | - __('This method would have been protected but was used on a filter callback' |
|
| 1852 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1853 | - '4.8.32.rc.000'); |
|
| 1854 | - return ' |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + |
|
| 1840 | + /** |
|
| 1841 | + * form_after_question_group |
|
| 1842 | + * |
|
| 1843 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1844 | + * @access public |
|
| 1845 | + * @param string $output |
|
| 1846 | + * @return string |
|
| 1847 | + */ |
|
| 1848 | + public function form_after_question_group($output) |
|
| 1849 | + { |
|
| 1850 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1851 | + __('This method would have been protected but was used on a filter callback' |
|
| 1852 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1853 | + '4.8.32.rc.000'); |
|
| 1854 | + return ' |
|
| 1855 | 1855 | <tr class="hide-if-no-js"> |
| 1856 | 1856 | <th> </th> |
| 1857 | 1857 | <td class="reg-admin-edit-attendee-question-td"> |
| 1858 | 1858 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 1859 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 1860 | - . '"> |
|
| 1859 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 1860 | + . '"> |
|
| 1861 | 1861 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 1862 | - . __('edit the above question group', 'event_espresso') |
|
| 1863 | - . '</span> |
|
| 1862 | + . __('edit the above question group', 'event_espresso') |
|
| 1863 | + . '</span> |
|
| 1864 | 1864 | <div class="dashicons dashicons-edit"></div> |
| 1865 | 1865 | </a> |
| 1866 | 1866 | </td> |
@@ -1868,490 +1868,490 @@ discard block |
||
| 1868 | 1868 | </tbody> |
| 1869 | 1869 | </table> |
| 1870 | 1870 | '; |
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - |
|
| 1874 | - /** |
|
| 1875 | - * form_form_field_label_wrap |
|
| 1876 | - * |
|
| 1877 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1878 | - * @access public |
|
| 1879 | - * @param string $label |
|
| 1880 | - * @return string |
|
| 1881 | - */ |
|
| 1882 | - public function form_form_field_label_wrap($label) |
|
| 1883 | - { |
|
| 1884 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1885 | - __('This method would have been protected but was used on a filter callback' |
|
| 1886 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1887 | - '4.8.32.rc.000'); |
|
| 1888 | - return ' |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + |
|
| 1874 | + /** |
|
| 1875 | + * form_form_field_label_wrap |
|
| 1876 | + * |
|
| 1877 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1878 | + * @access public |
|
| 1879 | + * @param string $label |
|
| 1880 | + * @return string |
|
| 1881 | + */ |
|
| 1882 | + public function form_form_field_label_wrap($label) |
|
| 1883 | + { |
|
| 1884 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1885 | + __('This method would have been protected but was used on a filter callback' |
|
| 1886 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1887 | + '4.8.32.rc.000'); |
|
| 1888 | + return ' |
|
| 1889 | 1889 | <tr> |
| 1890 | 1890 | <th> |
| 1891 | 1891 | ' . $label . ' |
| 1892 | 1892 | </th>'; |
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - |
|
| 1896 | - /** |
|
| 1897 | - * form_form_field_input__wrap |
|
| 1898 | - * |
|
| 1899 | - * @deprecated as of 4.8.32.rc.000 |
|
| 1900 | - * @access public |
|
| 1901 | - * @param string $input |
|
| 1902 | - * @return string |
|
| 1903 | - */ |
|
| 1904 | - public function form_form_field_input__wrap($input) |
|
| 1905 | - { |
|
| 1906 | - EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1907 | - __('This method would have been protected but was used on a filter callback' |
|
| 1908 | - . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1909 | - '4.8.32.rc.000'); |
|
| 1910 | - return ' |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + |
|
| 1896 | + /** |
|
| 1897 | + * form_form_field_input__wrap |
|
| 1898 | + * |
|
| 1899 | + * @deprecated as of 4.8.32.rc.000 |
|
| 1900 | + * @access public |
|
| 1901 | + * @param string $input |
|
| 1902 | + * @return string |
|
| 1903 | + */ |
|
| 1904 | + public function form_form_field_input__wrap($input) |
|
| 1905 | + { |
|
| 1906 | + EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, |
|
| 1907 | + __('This method would have been protected but was used on a filter callback' |
|
| 1908 | + . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'), |
|
| 1909 | + '4.8.32.rc.000'); |
|
| 1910 | + return ' |
|
| 1911 | 1911 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 1912 | 1912 | ' . $input . ' |
| 1913 | 1913 | </td> |
| 1914 | 1914 | </tr>'; |
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - |
|
| 1918 | - /** |
|
| 1919 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 1920 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 1921 | - * to display the page |
|
| 1922 | - * |
|
| 1923 | - * @access protected |
|
| 1924 | - * @return void |
|
| 1925 | - */ |
|
| 1926 | - protected function _update_attendee_registration_form() |
|
| 1927 | - { |
|
| 1928 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 1929 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1930 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1931 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 1932 | - if ($success) { |
|
| 1933 | - $what = __('Registration Form', 'event_espresso'); |
|
| 1934 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 1935 | - : array('action' => 'default'); |
|
| 1936 | - $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * Gets the form for saving registrations custom questions (if done |
|
| 1944 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 1945 | - * |
|
| 1946 | - * @param int $REG_ID |
|
| 1947 | - * @return EE_Registration_Custom_Questions_Form |
|
| 1948 | - */ |
|
| 1949 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 1950 | - { |
|
| 1951 | - if ( ! $this->_reg_custom_questions_form) { |
|
| 1952 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1953 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 1954 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 1955 | - ); |
|
| 1956 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 1957 | - } |
|
| 1958 | - return $this->_reg_custom_questions_form; |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * Saves |
|
| 1964 | - * |
|
| 1965 | - * @access private |
|
| 1966 | - * @param bool $REG_ID |
|
| 1967 | - * @return bool |
|
| 1968 | - */ |
|
| 1969 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 1970 | - { |
|
| 1971 | - if ( ! $REG_ID) { |
|
| 1972 | - EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__, |
|
| 1973 | - __FUNCTION__, __LINE__); |
|
| 1974 | - } |
|
| 1975 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 1976 | - $form->receive_form_submission($this->_req_data); |
|
| 1977 | - $success = false; |
|
| 1978 | - if ($form->is_valid()) { |
|
| 1979 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 1980 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 1981 | - $where_conditions = array( |
|
| 1982 | - 'QST_ID' => $question_id, |
|
| 1983 | - 'REG_ID' => $REG_ID, |
|
| 1984 | - ); |
|
| 1985 | - $possibly_new_values = array( |
|
| 1986 | - 'ANS_value' => $input->normalized_value(), |
|
| 1987 | - ); |
|
| 1988 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 1989 | - if ($answer instanceof EE_Answer) { |
|
| 1990 | - $success = $answer->save($possibly_new_values); |
|
| 1991 | - } else { |
|
| 1992 | - //insert it then |
|
| 1993 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 1994 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 1995 | - $success = $answer->save(); |
|
| 1996 | - } |
|
| 1997 | - } |
|
| 1998 | - } |
|
| 1999 | - } else { |
|
| 2000 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2001 | - } |
|
| 2002 | - return $success; |
|
| 2003 | - } |
|
| 2004 | - |
|
| 2005 | - |
|
| 2006 | - /** |
|
| 2007 | - * generates HTML for the Registration main meta box |
|
| 2008 | - * |
|
| 2009 | - * @access public |
|
| 2010 | - * @return void |
|
| 2011 | - */ |
|
| 2012 | - public function _reg_attendees_meta_box() |
|
| 2013 | - { |
|
| 2014 | - $REG = EEM_Registration::instance(); |
|
| 2015 | - //get all other registrations on this transaction, and cache |
|
| 2016 | - //the attendees for them so we don't have to run another query using force_join |
|
| 2017 | - $registrations = $REG->get_all(array( |
|
| 2018 | - array( |
|
| 2019 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2020 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2021 | - ), |
|
| 2022 | - 'force_join' => array('Attendee'), |
|
| 2023 | - )); |
|
| 2024 | - $this->_template_args['attendees'] = array(); |
|
| 2025 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2026 | - if (empty($registrations) |
|
| 2027 | - || (is_array($registrations) |
|
| 2028 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2029 | - ) { |
|
| 2030 | - EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2031 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2032 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2033 | - } else { |
|
| 2034 | - $att_nmbr = 1; |
|
| 2035 | - foreach ($registrations as $registration) { |
|
| 2036 | - /* @var $registration EE_Registration */ |
|
| 2037 | - $attendee = $registration->attendee() |
|
| 2038 | - ? $registration->attendee() |
|
| 2039 | - : EEM_Attendee::instance() |
|
| 2040 | - ->create_default_object(); |
|
| 2041 | - $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2042 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2043 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2044 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2045 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2046 | - $this->_template_args['attendees'][$att_nmbr]['address'] = implode(', ', |
|
| 2047 | - $attendee->full_address_as_array()); |
|
| 2048 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(array( |
|
| 2049 | - 'action' => 'edit_attendee', |
|
| 2050 | - 'post' => $attendee->ID(), |
|
| 2051 | - ), REG_ADMIN_URL); |
|
| 2052 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2053 | - $att_nmbr++; |
|
| 2054 | - } |
|
| 2055 | - //EEH_Debug_Tools::printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' ); |
|
| 2056 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2057 | - // $this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees' ), REG_ADMIN_URL ); |
|
| 2058 | - } |
|
| 2059 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2060 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2061 | - } |
|
| 2062 | - |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * generates HTML for the Edit Registration side meta box |
|
| 2066 | - * |
|
| 2067 | - * @access public |
|
| 2068 | - * @return void |
|
| 2069 | - */ |
|
| 2070 | - public function _reg_registrant_side_meta_box() |
|
| 2071 | - { |
|
| 2072 | - /*@var $attendee EE_Attendee */ |
|
| 2073 | - $att_check = $this->_registration->attendee(); |
|
| 2074 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2075 | - //now let's determine if this is not the primary registration. If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not) |
|
| 2076 | - if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2077 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2078 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2079 | - : null; |
|
| 2080 | - if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2081 | - //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg. |
|
| 2082 | - $primary_registration = null; |
|
| 2083 | - } |
|
| 2084 | - } else { |
|
| 2085 | - $primary_registration = null; |
|
| 2086 | - } |
|
| 2087 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2088 | - $this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname; |
|
| 2089 | - $this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname; |
|
| 2090 | - $this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email; |
|
| 2091 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2092 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2093 | - //edit link |
|
| 2094 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2095 | - 'action' => 'edit_attendee', |
|
| 2096 | - 'post' => $attendee->ID(), |
|
| 2097 | - ), REG_ADMIN_URL); |
|
| 2098 | - $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso'); |
|
| 2099 | - //create link |
|
| 2100 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2101 | - ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2102 | - 'action' => 'duplicate_attendee', |
|
| 2103 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2104 | - ), REG_ADMIN_URL) : ''; |
|
| 2105 | - $this->_template_args['create_label'] = __('Create Contact', 'event_espresso'); |
|
| 2106 | - $this->_template_args['att_check'] = $att_check; |
|
| 2107 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2108 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | - |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * trash or restore registrations |
|
| 2115 | - * |
|
| 2116 | - * @param boolean $trash whether to archive or restore |
|
| 2117 | - * @access protected |
|
| 2118 | - * @return void |
|
| 2119 | - * @throws \EE_Error |
|
| 2120 | - */ |
|
| 2121 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2122 | - { |
|
| 2123 | - //if empty _REG_ID then get out because there's nothing to do |
|
| 2124 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2125 | - EE_Error::add_error( |
|
| 2126 | - sprintf( |
|
| 2127 | - esc_html__( |
|
| 2128 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2129 | - 'event_espresso' |
|
| 2130 | - ), |
|
| 2131 | - $trash ? 'trash' : 'restore' |
|
| 2132 | - ), |
|
| 2133 | - __FILE__, __LINE__, __FUNCTION__ |
|
| 2134 | - ); |
|
| 2135 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2136 | - } |
|
| 2137 | - $success = 0; |
|
| 2138 | - $overwrite_msgs = false; |
|
| 2139 | - //Checkboxes |
|
| 2140 | - if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2141 | - $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2142 | - } |
|
| 2143 | - $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2144 | - // cycle thru checkboxes |
|
| 2145 | - foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2146 | - /** @var EE_Registration $REG */ |
|
| 2147 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2148 | - $payments = $REG->registration_payments(); |
|
| 2149 | - if (! empty($payments)) { |
|
| 2150 | - $name = $REG->attendee() instanceof EE_Attendee |
|
| 2151 | - ? $REG->attendee()->full_name() |
|
| 2152 | - : __('Unknown Attendee', 'event_espresso'); |
|
| 2153 | - $overwrite_msgs = true; |
|
| 2154 | - EE_Error::add_error( |
|
| 2155 | - sprintf( |
|
| 2156 | - __( |
|
| 2157 | - 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2158 | - 'event_espresso' |
|
| 2159 | - ), |
|
| 2160 | - $name |
|
| 2161 | - ), |
|
| 2162 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2163 | - ); |
|
| 2164 | - //can't trash this registration because it has payments. |
|
| 2165 | - continue; |
|
| 2166 | - } |
|
| 2167 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2168 | - if ($updated) { |
|
| 2169 | - $success++; |
|
| 2170 | - } |
|
| 2171 | - } |
|
| 2172 | - $this->_redirect_after_action( |
|
| 2173 | - $success === $reg_count, // were ALL registrations affected? |
|
| 2174 | - $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'), |
|
| 2175 | - $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'), |
|
| 2176 | - array('action' => 'default'), |
|
| 2177 | - $overwrite_msgs |
|
| 2178 | - ); |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2184 | - * registration but also. |
|
| 2185 | - * 1. Removing relations to EE_Attendee |
|
| 2186 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2187 | - * ALSO trashed. |
|
| 2188 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2189 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2190 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2191 | - * 6. Deleting permanently any related Checkins. |
|
| 2192 | - * |
|
| 2193 | - * @return void |
|
| 2194 | - */ |
|
| 2195 | - protected function _delete_registrations() |
|
| 2196 | - { |
|
| 2197 | - $REG_MDL = EEM_Registration::instance(); |
|
| 2198 | - $success = 1; |
|
| 2199 | - //Checkboxes |
|
| 2200 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2201 | - // if array has more than one element than success message should be plural |
|
| 2202 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2203 | - // cycle thru checkboxes |
|
| 2204 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2205 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2206 | - if ( ! $REG instanceof EE_Registration) { |
|
| 2207 | - continue; |
|
| 2208 | - } |
|
| 2209 | - $deleted = $this->_delete_registration($REG); |
|
| 2210 | - if ( ! $deleted) { |
|
| 2211 | - $success = 0; |
|
| 2212 | - } |
|
| 2213 | - } |
|
| 2214 | - } else { |
|
| 2215 | - // grab single id and delete |
|
| 2216 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2217 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2218 | - $deleted = $this->_delete_registration($REG); |
|
| 2219 | - if ( ! $deleted) { |
|
| 2220 | - $success = 0; |
|
| 2221 | - } |
|
| 2222 | - } |
|
| 2223 | - $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2224 | - $action_desc = __('permanently deleted.', 'event_espresso'); |
|
| 2225 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true); |
|
| 2226 | - } |
|
| 2227 | - |
|
| 2228 | - |
|
| 2229 | - /** |
|
| 2230 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2231 | - * models get affected. |
|
| 2232 | - * |
|
| 2233 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2234 | - * @return boolean true = successful deletion, false = fail. |
|
| 2235 | - */ |
|
| 2236 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2237 | - { |
|
| 2238 | - //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed. |
|
| 2239 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2240 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2241 | - $all_trashed = true; |
|
| 2242 | - foreach ($REGS as $registration) { |
|
| 2243 | - if ( ! $registration->get('REG_deleted')) { |
|
| 2244 | - $all_trashed = false; |
|
| 2245 | - } |
|
| 2246 | - } |
|
| 2247 | - if ( ! $all_trashed) { |
|
| 2248 | - EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2249 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2250 | - return false; |
|
| 2251 | - } |
|
| 2252 | - //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one). |
|
| 2253 | - foreach ($REGS as $registration) { |
|
| 2254 | - //delete related answers |
|
| 2255 | - $registration->delete_related_permanently('Answer'); |
|
| 2256 | - //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2257 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2258 | - if ($attendee instanceof EE_Attendee) { |
|
| 2259 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2260 | - } |
|
| 2261 | - //now remove relationships to tickets on this registration. |
|
| 2262 | - $registration->_remove_relations('Ticket'); |
|
| 2263 | - //now delete permanently the checkins related to this registration. |
|
| 2264 | - $registration->delete_related_permanently('Checkin'); |
|
| 2265 | - if ($registration->ID() === $REG->ID()) { |
|
| 2266 | - continue; |
|
| 2267 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2268 | - //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2269 | - $registration->_remove_relations('Transaction'); |
|
| 2270 | - //delete permanently any related messages. |
|
| 2271 | - $registration->delete_related_permanently('Message'); |
|
| 2272 | - //now delete this registration permanently |
|
| 2273 | - $registration->delete_permanently(); |
|
| 2274 | - } |
|
| 2275 | - //now all related registrations on the transaction are handled. So let's just handle this registration itself (the transaction and line items should be all that's left). |
|
| 2276 | - //delete the line items related to the transaction for this registration. |
|
| 2277 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2278 | - //we need to remove all the relationships on the transaction |
|
| 2279 | - $TXN->delete_related_permanently('Payment'); |
|
| 2280 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2281 | - $TXN->delete_related_permanently('Message'); |
|
| 2282 | - //now we can delete this REG permanently (and the transaction of course) |
|
| 2283 | - $REG->delete_related_permanently('Transaction'); |
|
| 2284 | - return $REG->delete_permanently(); |
|
| 2285 | - } |
|
| 2286 | - |
|
| 2287 | - |
|
| 2288 | - /** |
|
| 2289 | - * generates HTML for the Register New Attendee Admin page |
|
| 2290 | - * |
|
| 2291 | - * @access private |
|
| 2292 | - * @throws \EE_Error |
|
| 2293 | - * @return void |
|
| 2294 | - */ |
|
| 2295 | - public function new_registration() |
|
| 2296 | - { |
|
| 2297 | - if ( ! $this->_set_reg_event()) { |
|
| 2298 | - throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', |
|
| 2299 | - 'event_espresso')); |
|
| 2300 | - } |
|
| 2301 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2302 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2303 | - if ( ! defined('DOING_AJAX') |
|
| 2304 | - && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2305 | - ) { |
|
| 2306 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2307 | - } |
|
| 2308 | - $this->_template_args['event_name'] = ''; |
|
| 2309 | - // event name |
|
| 2310 | - if ($this->_reg_event) { |
|
| 2311 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2312 | - $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2313 | - 'action' => 'edit', |
|
| 2314 | - 'post' => $this->_reg_event->ID(), |
|
| 2315 | - ), EVENTS_ADMIN_URL); |
|
| 2316 | - $edit_event_lnk = '<a href="' |
|
| 2317 | - . $edit_event_url |
|
| 2318 | - . '" title="' |
|
| 2319 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2320 | - . $this->_reg_event->name() |
|
| 2321 | - . '">' |
|
| 2322 | - . __('Edit Event', 'event_espresso') |
|
| 2323 | - . '</a>'; |
|
| 2324 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2325 | - . $edit_event_lnk |
|
| 2326 | - . '</span>'; |
|
| 2327 | - } |
|
| 2328 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2329 | - if (defined('DOING_AJAX')) { |
|
| 2330 | - $this->_return_json(); |
|
| 2331 | - } |
|
| 2332 | - // grab header |
|
| 2333 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2334 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2335 | - $this->_template_args, true); |
|
| 2336 | - //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2337 | - // the details template wrapper |
|
| 2338 | - $this->display_admin_page_with_sidebar(); |
|
| 2339 | - } |
|
| 2340 | - |
|
| 2341 | - |
|
| 2342 | - /** |
|
| 2343 | - * This returns the content for a registration step |
|
| 2344 | - * |
|
| 2345 | - * @access protected |
|
| 2346 | - * @return string html |
|
| 2347 | - */ |
|
| 2348 | - protected function _get_registration_step_content() |
|
| 2349 | - { |
|
| 2350 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2351 | - $warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2352 | - 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">', |
|
| 2353 | - '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>'); |
|
| 2354 | - return ' |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + |
|
| 1918 | + /** |
|
| 1919 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 1920 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 1921 | + * to display the page |
|
| 1922 | + * |
|
| 1923 | + * @access protected |
|
| 1924 | + * @return void |
|
| 1925 | + */ |
|
| 1926 | + protected function _update_attendee_registration_form() |
|
| 1927 | + { |
|
| 1928 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 1929 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1930 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1931 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 1932 | + if ($success) { |
|
| 1933 | + $what = __('Registration Form', 'event_espresso'); |
|
| 1934 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 1935 | + : array('action' => 'default'); |
|
| 1936 | + $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * Gets the form for saving registrations custom questions (if done |
|
| 1944 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 1945 | + * |
|
| 1946 | + * @param int $REG_ID |
|
| 1947 | + * @return EE_Registration_Custom_Questions_Form |
|
| 1948 | + */ |
|
| 1949 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 1950 | + { |
|
| 1951 | + if ( ! $this->_reg_custom_questions_form) { |
|
| 1952 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 1953 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 1954 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 1955 | + ); |
|
| 1956 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 1957 | + } |
|
| 1958 | + return $this->_reg_custom_questions_form; |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * Saves |
|
| 1964 | + * |
|
| 1965 | + * @access private |
|
| 1966 | + * @param bool $REG_ID |
|
| 1967 | + * @return bool |
|
| 1968 | + */ |
|
| 1969 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 1970 | + { |
|
| 1971 | + if ( ! $REG_ID) { |
|
| 1972 | + EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__, |
|
| 1973 | + __FUNCTION__, __LINE__); |
|
| 1974 | + } |
|
| 1975 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 1976 | + $form->receive_form_submission($this->_req_data); |
|
| 1977 | + $success = false; |
|
| 1978 | + if ($form->is_valid()) { |
|
| 1979 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 1980 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 1981 | + $where_conditions = array( |
|
| 1982 | + 'QST_ID' => $question_id, |
|
| 1983 | + 'REG_ID' => $REG_ID, |
|
| 1984 | + ); |
|
| 1985 | + $possibly_new_values = array( |
|
| 1986 | + 'ANS_value' => $input->normalized_value(), |
|
| 1987 | + ); |
|
| 1988 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 1989 | + if ($answer instanceof EE_Answer) { |
|
| 1990 | + $success = $answer->save($possibly_new_values); |
|
| 1991 | + } else { |
|
| 1992 | + //insert it then |
|
| 1993 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 1994 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 1995 | + $success = $answer->save(); |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | + } |
|
| 1999 | + } else { |
|
| 2000 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2001 | + } |
|
| 2002 | + return $success; |
|
| 2003 | + } |
|
| 2004 | + |
|
| 2005 | + |
|
| 2006 | + /** |
|
| 2007 | + * generates HTML for the Registration main meta box |
|
| 2008 | + * |
|
| 2009 | + * @access public |
|
| 2010 | + * @return void |
|
| 2011 | + */ |
|
| 2012 | + public function _reg_attendees_meta_box() |
|
| 2013 | + { |
|
| 2014 | + $REG = EEM_Registration::instance(); |
|
| 2015 | + //get all other registrations on this transaction, and cache |
|
| 2016 | + //the attendees for them so we don't have to run another query using force_join |
|
| 2017 | + $registrations = $REG->get_all(array( |
|
| 2018 | + array( |
|
| 2019 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2020 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2021 | + ), |
|
| 2022 | + 'force_join' => array('Attendee'), |
|
| 2023 | + )); |
|
| 2024 | + $this->_template_args['attendees'] = array(); |
|
| 2025 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2026 | + if (empty($registrations) |
|
| 2027 | + || (is_array($registrations) |
|
| 2028 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2029 | + ) { |
|
| 2030 | + EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2031 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2032 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2033 | + } else { |
|
| 2034 | + $att_nmbr = 1; |
|
| 2035 | + foreach ($registrations as $registration) { |
|
| 2036 | + /* @var $registration EE_Registration */ |
|
| 2037 | + $attendee = $registration->attendee() |
|
| 2038 | + ? $registration->attendee() |
|
| 2039 | + : EEM_Attendee::instance() |
|
| 2040 | + ->create_default_object(); |
|
| 2041 | + $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2042 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : ''; |
|
| 2043 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : ''; |
|
| 2044 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : ''; |
|
| 2045 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : ''; |
|
| 2046 | + $this->_template_args['attendees'][$att_nmbr]['address'] = implode(', ', |
|
| 2047 | + $attendee->full_address_as_array()); |
|
| 2048 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(array( |
|
| 2049 | + 'action' => 'edit_attendee', |
|
| 2050 | + 'post' => $attendee->ID(), |
|
| 2051 | + ), REG_ADMIN_URL); |
|
| 2052 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2053 | + $att_nmbr++; |
|
| 2054 | + } |
|
| 2055 | + //EEH_Debug_Tools::printr( $attendees, '$attendees <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' ); |
|
| 2056 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2057 | + // $this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees' ), REG_ADMIN_URL ); |
|
| 2058 | + } |
|
| 2059 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2060 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2061 | + } |
|
| 2062 | + |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * generates HTML for the Edit Registration side meta box |
|
| 2066 | + * |
|
| 2067 | + * @access public |
|
| 2068 | + * @return void |
|
| 2069 | + */ |
|
| 2070 | + public function _reg_registrant_side_meta_box() |
|
| 2071 | + { |
|
| 2072 | + /*@var $attendee EE_Attendee */ |
|
| 2073 | + $att_check = $this->_registration->attendee(); |
|
| 2074 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2075 | + //now let's determine if this is not the primary registration. If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not) |
|
| 2076 | + if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2077 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2078 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2079 | + : null; |
|
| 2080 | + if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2081 | + //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg. |
|
| 2082 | + $primary_registration = null; |
|
| 2083 | + } |
|
| 2084 | + } else { |
|
| 2085 | + $primary_registration = null; |
|
| 2086 | + } |
|
| 2087 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2088 | + $this->_template_args['fname'] = $attendee->fname();//$this->_registration->ATT_fname; |
|
| 2089 | + $this->_template_args['lname'] = $attendee->lname();//$this->_registration->ATT_lname; |
|
| 2090 | + $this->_template_args['email'] = $attendee->email();//$this->_registration->ATT_email; |
|
| 2091 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2092 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2093 | + //edit link |
|
| 2094 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2095 | + 'action' => 'edit_attendee', |
|
| 2096 | + 'post' => $attendee->ID(), |
|
| 2097 | + ), REG_ADMIN_URL); |
|
| 2098 | + $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso'); |
|
| 2099 | + //create link |
|
| 2100 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2101 | + ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2102 | + 'action' => 'duplicate_attendee', |
|
| 2103 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2104 | + ), REG_ADMIN_URL) : ''; |
|
| 2105 | + $this->_template_args['create_label'] = __('Create Contact', 'event_espresso'); |
|
| 2106 | + $this->_template_args['att_check'] = $att_check; |
|
| 2107 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2108 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * trash or restore registrations |
|
| 2115 | + * |
|
| 2116 | + * @param boolean $trash whether to archive or restore |
|
| 2117 | + * @access protected |
|
| 2118 | + * @return void |
|
| 2119 | + * @throws \EE_Error |
|
| 2120 | + */ |
|
| 2121 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2122 | + { |
|
| 2123 | + //if empty _REG_ID then get out because there's nothing to do |
|
| 2124 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2125 | + EE_Error::add_error( |
|
| 2126 | + sprintf( |
|
| 2127 | + esc_html__( |
|
| 2128 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2129 | + 'event_espresso' |
|
| 2130 | + ), |
|
| 2131 | + $trash ? 'trash' : 'restore' |
|
| 2132 | + ), |
|
| 2133 | + __FILE__, __LINE__, __FUNCTION__ |
|
| 2134 | + ); |
|
| 2135 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2136 | + } |
|
| 2137 | + $success = 0; |
|
| 2138 | + $overwrite_msgs = false; |
|
| 2139 | + //Checkboxes |
|
| 2140 | + if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2141 | + $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2142 | + } |
|
| 2143 | + $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2144 | + // cycle thru checkboxes |
|
| 2145 | + foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2146 | + /** @var EE_Registration $REG */ |
|
| 2147 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2148 | + $payments = $REG->registration_payments(); |
|
| 2149 | + if (! empty($payments)) { |
|
| 2150 | + $name = $REG->attendee() instanceof EE_Attendee |
|
| 2151 | + ? $REG->attendee()->full_name() |
|
| 2152 | + : __('Unknown Attendee', 'event_espresso'); |
|
| 2153 | + $overwrite_msgs = true; |
|
| 2154 | + EE_Error::add_error( |
|
| 2155 | + sprintf( |
|
| 2156 | + __( |
|
| 2157 | + 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2158 | + 'event_espresso' |
|
| 2159 | + ), |
|
| 2160 | + $name |
|
| 2161 | + ), |
|
| 2162 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2163 | + ); |
|
| 2164 | + //can't trash this registration because it has payments. |
|
| 2165 | + continue; |
|
| 2166 | + } |
|
| 2167 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2168 | + if ($updated) { |
|
| 2169 | + $success++; |
|
| 2170 | + } |
|
| 2171 | + } |
|
| 2172 | + $this->_redirect_after_action( |
|
| 2173 | + $success === $reg_count, // were ALL registrations affected? |
|
| 2174 | + $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'), |
|
| 2175 | + $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'), |
|
| 2176 | + array('action' => 'default'), |
|
| 2177 | + $overwrite_msgs |
|
| 2178 | + ); |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2184 | + * registration but also. |
|
| 2185 | + * 1. Removing relations to EE_Attendee |
|
| 2186 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2187 | + * ALSO trashed. |
|
| 2188 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2189 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2190 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2191 | + * 6. Deleting permanently any related Checkins. |
|
| 2192 | + * |
|
| 2193 | + * @return void |
|
| 2194 | + */ |
|
| 2195 | + protected function _delete_registrations() |
|
| 2196 | + { |
|
| 2197 | + $REG_MDL = EEM_Registration::instance(); |
|
| 2198 | + $success = 1; |
|
| 2199 | + //Checkboxes |
|
| 2200 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2201 | + // if array has more than one element than success message should be plural |
|
| 2202 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2203 | + // cycle thru checkboxes |
|
| 2204 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2205 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2206 | + if ( ! $REG instanceof EE_Registration) { |
|
| 2207 | + continue; |
|
| 2208 | + } |
|
| 2209 | + $deleted = $this->_delete_registration($REG); |
|
| 2210 | + if ( ! $deleted) { |
|
| 2211 | + $success = 0; |
|
| 2212 | + } |
|
| 2213 | + } |
|
| 2214 | + } else { |
|
| 2215 | + // grab single id and delete |
|
| 2216 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2217 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2218 | + $deleted = $this->_delete_registration($REG); |
|
| 2219 | + if ( ! $deleted) { |
|
| 2220 | + $success = 0; |
|
| 2221 | + } |
|
| 2222 | + } |
|
| 2223 | + $what = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'); |
|
| 2224 | + $action_desc = __('permanently deleted.', 'event_espresso'); |
|
| 2225 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true); |
|
| 2226 | + } |
|
| 2227 | + |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2231 | + * models get affected. |
|
| 2232 | + * |
|
| 2233 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2234 | + * @return boolean true = successful deletion, false = fail. |
|
| 2235 | + */ |
|
| 2236 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2237 | + { |
|
| 2238 | + //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed. |
|
| 2239 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2240 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2241 | + $all_trashed = true; |
|
| 2242 | + foreach ($REGS as $registration) { |
|
| 2243 | + if ( ! $registration->get('REG_deleted')) { |
|
| 2244 | + $all_trashed = false; |
|
| 2245 | + } |
|
| 2246 | + } |
|
| 2247 | + if ( ! $all_trashed) { |
|
| 2248 | + EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2249 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2250 | + return false; |
|
| 2251 | + } |
|
| 2252 | + //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one). |
|
| 2253 | + foreach ($REGS as $registration) { |
|
| 2254 | + //delete related answers |
|
| 2255 | + $registration->delete_related_permanently('Answer'); |
|
| 2256 | + //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2257 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2258 | + if ($attendee instanceof EE_Attendee) { |
|
| 2259 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2260 | + } |
|
| 2261 | + //now remove relationships to tickets on this registration. |
|
| 2262 | + $registration->_remove_relations('Ticket'); |
|
| 2263 | + //now delete permanently the checkins related to this registration. |
|
| 2264 | + $registration->delete_related_permanently('Checkin'); |
|
| 2265 | + if ($registration->ID() === $REG->ID()) { |
|
| 2266 | + continue; |
|
| 2267 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2268 | + //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2269 | + $registration->_remove_relations('Transaction'); |
|
| 2270 | + //delete permanently any related messages. |
|
| 2271 | + $registration->delete_related_permanently('Message'); |
|
| 2272 | + //now delete this registration permanently |
|
| 2273 | + $registration->delete_permanently(); |
|
| 2274 | + } |
|
| 2275 | + //now all related registrations on the transaction are handled. So let's just handle this registration itself (the transaction and line items should be all that's left). |
|
| 2276 | + //delete the line items related to the transaction for this registration. |
|
| 2277 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2278 | + //we need to remove all the relationships on the transaction |
|
| 2279 | + $TXN->delete_related_permanently('Payment'); |
|
| 2280 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2281 | + $TXN->delete_related_permanently('Message'); |
|
| 2282 | + //now we can delete this REG permanently (and the transaction of course) |
|
| 2283 | + $REG->delete_related_permanently('Transaction'); |
|
| 2284 | + return $REG->delete_permanently(); |
|
| 2285 | + } |
|
| 2286 | + |
|
| 2287 | + |
|
| 2288 | + /** |
|
| 2289 | + * generates HTML for the Register New Attendee Admin page |
|
| 2290 | + * |
|
| 2291 | + * @access private |
|
| 2292 | + * @throws \EE_Error |
|
| 2293 | + * @return void |
|
| 2294 | + */ |
|
| 2295 | + public function new_registration() |
|
| 2296 | + { |
|
| 2297 | + if ( ! $this->_set_reg_event()) { |
|
| 2298 | + throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request', |
|
| 2299 | + 'event_espresso')); |
|
| 2300 | + } |
|
| 2301 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2302 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2303 | + if ( ! defined('DOING_AJAX') |
|
| 2304 | + && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2305 | + ) { |
|
| 2306 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2307 | + } |
|
| 2308 | + $this->_template_args['event_name'] = ''; |
|
| 2309 | + // event name |
|
| 2310 | + if ($this->_reg_event) { |
|
| 2311 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2312 | + $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2313 | + 'action' => 'edit', |
|
| 2314 | + 'post' => $this->_reg_event->ID(), |
|
| 2315 | + ), EVENTS_ADMIN_URL); |
|
| 2316 | + $edit_event_lnk = '<a href="' |
|
| 2317 | + . $edit_event_url |
|
| 2318 | + . '" title="' |
|
| 2319 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2320 | + . $this->_reg_event->name() |
|
| 2321 | + . '">' |
|
| 2322 | + . __('Edit Event', 'event_espresso') |
|
| 2323 | + . '</a>'; |
|
| 2324 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2325 | + . $edit_event_lnk |
|
| 2326 | + . '</span>'; |
|
| 2327 | + } |
|
| 2328 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2329 | + if (defined('DOING_AJAX')) { |
|
| 2330 | + $this->_return_json(); |
|
| 2331 | + } |
|
| 2332 | + // grab header |
|
| 2333 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2334 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2335 | + $this->_template_args, true); |
|
| 2336 | + //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2337 | + // the details template wrapper |
|
| 2338 | + $this->display_admin_page_with_sidebar(); |
|
| 2339 | + } |
|
| 2340 | + |
|
| 2341 | + |
|
| 2342 | + /** |
|
| 2343 | + * This returns the content for a registration step |
|
| 2344 | + * |
|
| 2345 | + * @access protected |
|
| 2346 | + * @return string html |
|
| 2347 | + */ |
|
| 2348 | + protected function _get_registration_step_content() |
|
| 2349 | + { |
|
| 2350 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2351 | + $warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2352 | + 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">', |
|
| 2353 | + '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>'); |
|
| 2354 | + return ' |
|
| 2355 | 2355 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 2356 | 2356 | <script > |
| 2357 | 2357 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2364,658 +2364,658 @@ discard block |
||
| 2364 | 2364 | } |
| 2365 | 2365 | }, 800 ); |
| 2366 | 2366 | </script >'; |
| 2367 | - } |
|
| 2368 | - $template_args = array( |
|
| 2369 | - 'title' => '', |
|
| 2370 | - 'content' => '', |
|
| 2371 | - 'step_button_text' => '', |
|
| 2372 | - 'show_notification_toggle' => false, |
|
| 2373 | - ); |
|
| 2374 | - //to indicate we're processing a new registration |
|
| 2375 | - $hidden_fields = array( |
|
| 2376 | - 'processing_registration' => array( |
|
| 2377 | - 'type' => 'hidden', |
|
| 2378 | - 'value' => 0, |
|
| 2379 | - ), |
|
| 2380 | - 'event_id' => array( |
|
| 2381 | - 'type' => 'hidden', |
|
| 2382 | - 'value' => $this->_reg_event->ID(), |
|
| 2383 | - ), |
|
| 2384 | - ); |
|
| 2385 | - //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2386 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2387 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2388 | - switch ($step) { |
|
| 2389 | - case 'ticket' : |
|
| 2390 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 2391 | - $template_args['title'] = __('Step One: Select the Ticket for this registration', |
|
| 2392 | - 'event_espresso'); |
|
| 2393 | - $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2394 | - $template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', |
|
| 2395 | - 'event_espresso'); |
|
| 2396 | - $template_args['show_notification_toggle'] = false; |
|
| 2397 | - break; |
|
| 2398 | - case 'questions' : |
|
| 2399 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 2400 | - $template_args['title'] = __('Step Two: Add Registrant Details for this Registration', |
|
| 2401 | - 'event_espresso'); |
|
| 2402 | - //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run. |
|
| 2403 | - $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2404 | - $template_args['step_button_text'] = __('Save Registration and Continue to Details', |
|
| 2405 | - 'event_espresso'); |
|
| 2406 | - $template_args['show_notification_toggle'] = true; |
|
| 2407 | - break; |
|
| 2408 | - } |
|
| 2409 | - $this->_set_add_edit_form_tags('process_reg_step', |
|
| 2410 | - $hidden_fields); //we come back to the process_registration_step route. |
|
| 2411 | - return EEH_Template::display_template(REG_TEMPLATE_PATH |
|
| 2412 | - . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2413 | - $template_args, true); |
|
| 2414 | - } |
|
| 2415 | - |
|
| 2416 | - |
|
| 2417 | - /** |
|
| 2418 | - * set_reg_event |
|
| 2419 | - * |
|
| 2420 | - * @access private |
|
| 2421 | - * @return boolean |
|
| 2422 | - */ |
|
| 2423 | - private function _set_reg_event() |
|
| 2424 | - { |
|
| 2425 | - if (is_object($this->_reg_event)) { |
|
| 2426 | - return true; |
|
| 2427 | - } |
|
| 2428 | - $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2429 | - if ( ! $EVT_ID) { |
|
| 2430 | - return false; |
|
| 2431 | - } |
|
| 2432 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2433 | - return true; |
|
| 2434 | - } |
|
| 2435 | - |
|
| 2436 | - |
|
| 2437 | - /** |
|
| 2438 | - * process_reg_step |
|
| 2439 | - * |
|
| 2440 | - * @access public |
|
| 2441 | - * @return string |
|
| 2442 | - * @throws \RuntimeException |
|
| 2443 | - * @throws \EE_Error |
|
| 2444 | - */ |
|
| 2445 | - public function process_reg_step() |
|
| 2446 | - { |
|
| 2447 | - EE_System::do_not_cache(); |
|
| 2448 | - $this->_set_reg_event(); |
|
| 2449 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2450 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2451 | - //what step are we on? |
|
| 2452 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2453 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2454 | - //if doing ajax then we need to verify the nonce |
|
| 2455 | - if (defined('DOING_AJAX')) { |
|
| 2456 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2457 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2458 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2459 | - } |
|
| 2460 | - switch ($step) { |
|
| 2461 | - case 'ticket' : |
|
| 2462 | - //process ticket selection |
|
| 2463 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2464 | - if ($success) { |
|
| 2465 | - EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.', |
|
| 2466 | - 'event_espresso')); |
|
| 2467 | - } else { |
|
| 2468 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2469 | - } |
|
| 2470 | - if (defined('DOING_AJAX')) { |
|
| 2471 | - $this->new_registration(); //display next step |
|
| 2472 | - } else { |
|
| 2473 | - $query_args = array( |
|
| 2474 | - 'action' => 'new_registration', |
|
| 2475 | - 'processing_registration' => 1, |
|
| 2476 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2477 | - 'uts' => time(), |
|
| 2478 | - ); |
|
| 2479 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2480 | - } |
|
| 2481 | - break; |
|
| 2482 | - case 'questions' : |
|
| 2483 | - if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) { |
|
| 2484 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2485 | - } |
|
| 2486 | - //process registration |
|
| 2487 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2488 | - if ($cart instanceof EE_Cart) { |
|
| 2489 | - $grand_total = $cart->get_cart_grand_total(); |
|
| 2490 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 2491 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2494 | - if ( ! $transaction instanceof EE_Transaction) { |
|
| 2495 | - $query_args = array( |
|
| 2496 | - 'action' => 'new_registration', |
|
| 2497 | - 'processing_registration' => 2, |
|
| 2498 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2499 | - 'uts' => time(), |
|
| 2500 | - ); |
|
| 2501 | - if (defined('DOING_AJAX')) { |
|
| 2502 | - //display registration form again because there are errors (maybe validation?) |
|
| 2503 | - $this->new_registration(); |
|
| 2504 | - return; |
|
| 2505 | - } else { |
|
| 2506 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2507 | - return; |
|
| 2508 | - } |
|
| 2509 | - } |
|
| 2510 | - // maybe update status, and make sure to save transaction if not done already |
|
| 2511 | - if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2512 | - $transaction->save(); |
|
| 2513 | - } |
|
| 2514 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2515 | - $this->_req_data = array(); |
|
| 2516 | - $query_args = array( |
|
| 2517 | - 'action' => 'redirect_to_txn', |
|
| 2518 | - 'TXN_ID' => $transaction->ID(), |
|
| 2519 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2520 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2521 | - 'redirect_from' => 'new_registration', |
|
| 2522 | - ); |
|
| 2523 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2524 | - break; |
|
| 2525 | - } |
|
| 2526 | - //what are you looking here for? Should be nothing to do at this point. |
|
| 2527 | - } |
|
| 2528 | - |
|
| 2529 | - |
|
| 2530 | - /** |
|
| 2531 | - * redirect_to_txn |
|
| 2532 | - * |
|
| 2533 | - * @access public |
|
| 2534 | - * @return void |
|
| 2535 | - */ |
|
| 2536 | - public function redirect_to_txn() |
|
| 2537 | - { |
|
| 2538 | - EE_System::do_not_cache(); |
|
| 2539 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2540 | - $query_args = array( |
|
| 2541 | - 'action' => 'view_transaction', |
|
| 2542 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2543 | - 'page' => 'espresso_transactions', |
|
| 2544 | - ); |
|
| 2545 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2546 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2547 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2548 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2549 | - } |
|
| 2550 | - EE_Error::add_success(__('Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2551 | - 'event_espresso')); |
|
| 2552 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - |
|
| 2556 | - /** |
|
| 2557 | - * generates HTML for the Attendee Contact List |
|
| 2558 | - * |
|
| 2559 | - * @access protected |
|
| 2560 | - * @return void |
|
| 2561 | - */ |
|
| 2562 | - protected function _attendee_contact_list_table() |
|
| 2563 | - { |
|
| 2564 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2565 | - $this->_search_btn_label = __('Contacts', 'event_espresso'); |
|
| 2566 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2567 | - } |
|
| 2568 | - |
|
| 2569 | - |
|
| 2570 | - /** |
|
| 2571 | - * get_attendees |
|
| 2572 | - * |
|
| 2573 | - * @param bool $count whether to return count or data. |
|
| 2574 | - * @access public |
|
| 2575 | - * @return array |
|
| 2576 | - */ |
|
| 2577 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2578 | - { |
|
| 2579 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2580 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2581 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 2582 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2583 | - switch ($this->_req_data['orderby']) { |
|
| 2584 | - case 'ATT_ID': |
|
| 2585 | - $orderby = 'ATT_ID'; |
|
| 2586 | - break; |
|
| 2587 | - case 'ATT_fname': |
|
| 2588 | - $orderby = 'ATT_fname'; |
|
| 2589 | - break; |
|
| 2590 | - case 'ATT_email': |
|
| 2591 | - $orderby = 'ATT_email'; |
|
| 2592 | - break; |
|
| 2593 | - case 'ATT_city': |
|
| 2594 | - $orderby = 'ATT_city'; |
|
| 2595 | - break; |
|
| 2596 | - case 'STA_ID': |
|
| 2597 | - $orderby = 'STA_ID'; |
|
| 2598 | - break; |
|
| 2599 | - case 'CNT_ID': |
|
| 2600 | - $orderby = 'CNT_ID'; |
|
| 2601 | - break; |
|
| 2602 | - default: |
|
| 2603 | - $orderby = 'ATT_lname'; |
|
| 2604 | - } |
|
| 2605 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 2606 | - : 'ASC'; |
|
| 2607 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2608 | - ? $this->_req_data['paged'] : 1; |
|
| 2609 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2610 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2611 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 2612 | - $_where = array(); |
|
| 2613 | - if ( ! empty($this->_req_data['s'])) { |
|
| 2614 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2615 | - $_where['OR'] = array( |
|
| 2616 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2617 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 2618 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 2619 | - 'ATT_fname' => array('LIKE', $sstr), |
|
| 2620 | - 'ATT_lname' => array('LIKE', $sstr), |
|
| 2621 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 2622 | - 'ATT_email' => array('LIKE', $sstr), |
|
| 2623 | - 'ATT_address' => array('LIKE', $sstr), |
|
| 2624 | - 'ATT_address2' => array('LIKE', $sstr), |
|
| 2625 | - 'ATT_city' => array('LIKE', $sstr), |
|
| 2626 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 2627 | - 'State.STA_name' => array('LIKE', $sstr), |
|
| 2628 | - 'ATT_phone' => array('LIKE', $sstr), |
|
| 2629 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 2630 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 2631 | - 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 2632 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 2633 | - ); |
|
| 2634 | - } |
|
| 2635 | - $offset = ($current_page - 1) * $per_page; |
|
| 2636 | - $limit = $count ? null : array($offset, $per_page); |
|
| 2637 | - if ($trash) { |
|
| 2638 | - $_where['status'] = array('!=', 'publish'); |
|
| 2639 | - $all_attendees = $count |
|
| 2640 | - ? $ATT_MDL->count(array( |
|
| 2641 | - $_where, |
|
| 2642 | - 'order_by' => array($orderby => $sort), |
|
| 2643 | - 'limit' => $limit, |
|
| 2644 | - ), 'ATT_ID', true) |
|
| 2645 | - : $ATT_MDL->get_all(array( |
|
| 2646 | - $_where, |
|
| 2647 | - 'order_by' => array($orderby => $sort), |
|
| 2648 | - 'limit' => $limit, |
|
| 2649 | - )); |
|
| 2650 | - } else { |
|
| 2651 | - $_where['status'] = array('IN', array('publish')); |
|
| 2652 | - $all_attendees = $count |
|
| 2653 | - ? $ATT_MDL->count(array( |
|
| 2654 | - $_where, |
|
| 2655 | - 'order_by' => array($orderby => $sort), |
|
| 2656 | - 'limit' => $limit, |
|
| 2657 | - ), 'ATT_ID', true) |
|
| 2658 | - : $ATT_MDL->get_all(array( |
|
| 2659 | - $_where, |
|
| 2660 | - 'order_by' => array($orderby => $sort), |
|
| 2661 | - 'limit' => $limit, |
|
| 2662 | - )); |
|
| 2663 | - } |
|
| 2664 | - return $all_attendees; |
|
| 2665 | - } |
|
| 2666 | - |
|
| 2667 | - |
|
| 2668 | - /** |
|
| 2669 | - * This is just taking care of resending the registration confirmation |
|
| 2670 | - * |
|
| 2671 | - * @access protected |
|
| 2672 | - * @return void |
|
| 2673 | - */ |
|
| 2674 | - protected function _resend_registration() |
|
| 2675 | - { |
|
| 2676 | - $this->_process_resend_registration(); |
|
| 2677 | - $query_args = isset($this->_req_data['redirect_to']) |
|
| 2678 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 2679 | - : array( |
|
| 2680 | - 'action' => 'default', |
|
| 2681 | - ); |
|
| 2682 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2683 | - } |
|
| 2684 | - |
|
| 2685 | - /** |
|
| 2686 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 2687 | - * to use when selecting registrations |
|
| 2688 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 2689 | - * the query parameters from the request |
|
| 2690 | - * @return void ends the request with a redirect or download |
|
| 2691 | - */ |
|
| 2692 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 2693 | - { |
|
| 2694 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2695 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2696 | - 'page' => 'espresso_batch', |
|
| 2697 | - 'batch' => 'file', |
|
| 2698 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2699 | - 'filters' => urlencode( |
|
| 2700 | - serialize( |
|
| 2701 | - call_user_func( |
|
| 2702 | - array( $this, $method_name_for_getting_query_params ), |
|
| 2703 | - EEH_Array::is_set( |
|
| 2704 | - $this->_req_data, |
|
| 2705 | - 'filters', |
|
| 2706 | - array() |
|
| 2707 | - ) |
|
| 2708 | - ) |
|
| 2709 | - ) |
|
| 2710 | - ), |
|
| 2711 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 2712 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 2713 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2714 | - ))); |
|
| 2715 | - } else { |
|
| 2716 | - $new_request_args = array( |
|
| 2717 | - 'export' => 'report', |
|
| 2718 | - 'action' => 'registrations_report_for_event', |
|
| 2719 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2720 | - ); |
|
| 2721 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 2722 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2723 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2724 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2725 | - $EE_Export->export(); |
|
| 2726 | - } |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - |
|
| 2731 | - |
|
| 2732 | - /** |
|
| 2733 | - * Creates a registration report using only query parameters in the request |
|
| 2734 | - * @return void |
|
| 2735 | - */ |
|
| 2736 | - public function _registrations_report() |
|
| 2737 | - { |
|
| 2738 | - $this->_registrations_report_base( '_get_registration_query_parameters' ); |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - |
|
| 2742 | - public function _contact_list_export() |
|
| 2743 | - { |
|
| 2744 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2745 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2746 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2747 | - $EE_Export->export_attendees(); |
|
| 2748 | - } |
|
| 2749 | - } |
|
| 2750 | - |
|
| 2751 | - |
|
| 2752 | - public function _contact_list_report() |
|
| 2753 | - { |
|
| 2754 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2755 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2756 | - 'page' => 'espresso_batch', |
|
| 2757 | - 'batch' => 'file', |
|
| 2758 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 2759 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2760 | - ))); |
|
| 2761 | - } else { |
|
| 2762 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2763 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2764 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2765 | - $EE_Export->report_attendees(); |
|
| 2766 | - } |
|
| 2767 | - } |
|
| 2768 | - } |
|
| 2769 | - |
|
| 2770 | - |
|
| 2771 | - |
|
| 2772 | - |
|
| 2773 | - |
|
| 2774 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 2775 | - /** |
|
| 2776 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 2777 | - * |
|
| 2778 | - * @return void |
|
| 2779 | - */ |
|
| 2780 | - protected function _duplicate_attendee() |
|
| 2781 | - { |
|
| 2782 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 2783 | - //verify we have necessary info |
|
| 2784 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2785 | - EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 2786 | - 'event_espresso'), __FILE__, __LINE__, __FUNCTION__); |
|
| 2787 | - $query_args = array('action' => $action); |
|
| 2788 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2789 | - } |
|
| 2790 | - //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 2791 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 2792 | - $attendee = $registration->attendee(); |
|
| 2793 | - //remove relation of existing attendee on registration |
|
| 2794 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2795 | - //new attendee |
|
| 2796 | - $new_attendee = clone $attendee; |
|
| 2797 | - $new_attendee->set('ATT_ID', 0); |
|
| 2798 | - $new_attendee->save(); |
|
| 2799 | - //add new attendee to reg |
|
| 2800 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 2801 | - EE_Error::add_success(__('New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 2802 | - 'event_espresso')); |
|
| 2803 | - //redirect to edit page for attendee |
|
| 2804 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 2805 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2806 | - } |
|
| 2807 | - |
|
| 2808 | - |
|
| 2809 | - //related to cpt routes |
|
| 2810 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 2811 | - { |
|
| 2812 | - $success = true; |
|
| 2813 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 2814 | - //for attendee updates |
|
| 2815 | - if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 2816 | - //note we should only be UPDATING attendees at this point. |
|
| 2817 | - $updated_fields = array( |
|
| 2818 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 2819 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 2820 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 2821 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 2822 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 2823 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 2824 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 2825 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 2826 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 2827 | - 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 2828 | - 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 2829 | - ); |
|
| 2830 | - foreach ($updated_fields as $field => $value) { |
|
| 2831 | - $attendee->set($field, $value); |
|
| 2832 | - } |
|
| 2833 | - $success = $attendee->save(); |
|
| 2834 | - $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 2835 | - array()); |
|
| 2836 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 2837 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 2838 | - throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 2839 | - 'event_espresso'), $a_callback)); |
|
| 2840 | - } |
|
| 2841 | - } |
|
| 2842 | - } |
|
| 2843 | - if ($success === false) { |
|
| 2844 | - EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', |
|
| 2845 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2846 | - } |
|
| 2847 | - } |
|
| 2848 | - |
|
| 2849 | - |
|
| 2850 | - public function trash_cpt_item($post_id) |
|
| 2851 | - { |
|
| 2852 | - } |
|
| 2853 | - |
|
| 2854 | - |
|
| 2855 | - public function delete_cpt_item($post_id) |
|
| 2856 | - { |
|
| 2857 | - } |
|
| 2858 | - |
|
| 2859 | - |
|
| 2860 | - public function restore_cpt_item($post_id) |
|
| 2861 | - { |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - |
|
| 2865 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 2866 | - { |
|
| 2867 | - } |
|
| 2868 | - |
|
| 2869 | - |
|
| 2870 | - public function attendee_editor_metaboxes() |
|
| 2871 | - { |
|
| 2872 | - $this->verify_cpt_object(); |
|
| 2873 | - remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 2874 | - 'normal', 'core'); |
|
| 2875 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2876 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 2877 | - add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', |
|
| 2878 | - $this->_cpt_routes[$this->_req_action], 'normal'); |
|
| 2879 | - } |
|
| 2880 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 2881 | - add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', |
|
| 2882 | - $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2883 | - } |
|
| 2884 | - add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), |
|
| 2885 | - array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core'); |
|
| 2886 | - add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), |
|
| 2887 | - array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2888 | - add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'), |
|
| 2889 | - array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high'); |
|
| 2890 | - } |
|
| 2891 | - |
|
| 2892 | - |
|
| 2893 | - /** |
|
| 2894 | - * Metabox for attendee contact info |
|
| 2895 | - * |
|
| 2896 | - * @param WP_Post $post wp post object |
|
| 2897 | - * @return string attendee contact info ( and form ) |
|
| 2898 | - */ |
|
| 2899 | - public function attendee_contact_info($post) |
|
| 2900 | - { |
|
| 2901 | - //get attendee object ( should already have it ) |
|
| 2902 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2903 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 2904 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2905 | - } |
|
| 2906 | - |
|
| 2907 | - |
|
| 2908 | - /** |
|
| 2909 | - * Metabox for attendee details |
|
| 2910 | - * |
|
| 2911 | - * @param WP_Post $post wp post object |
|
| 2912 | - * @return string attendee address details (and form) |
|
| 2913 | - */ |
|
| 2914 | - public function attendee_address_details($post) |
|
| 2915 | - { |
|
| 2916 | - //get attendee object (should already have it) |
|
| 2917 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2918 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2919 | - 'QST_ID' => 0, |
|
| 2920 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 2921 | - 'QST_system' => 'admin-state', |
|
| 2922 | - )), EE_Answer::new_instance(array( |
|
| 2923 | - 'ANS_ID' => 0, |
|
| 2924 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 2925 | - )), array( |
|
| 2926 | - 'input_id' => 'STA_ID', |
|
| 2927 | - 'input_name' => 'STA_ID', |
|
| 2928 | - 'input_prefix' => '', |
|
| 2929 | - 'append_qstn_id' => false, |
|
| 2930 | - ))); |
|
| 2931 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2932 | - 'QST_ID' => 0, |
|
| 2933 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 2934 | - 'QST_system' => 'admin-country', |
|
| 2935 | - )), EE_Answer::new_instance(array( |
|
| 2936 | - 'ANS_ID' => 0, |
|
| 2937 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 2938 | - )), array( |
|
| 2939 | - 'input_id' => 'CNT_ISO', |
|
| 2940 | - 'input_name' => 'CNT_ISO', |
|
| 2941 | - 'input_prefix' => '', |
|
| 2942 | - 'append_qstn_id' => false, |
|
| 2943 | - ))); |
|
| 2944 | - $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 2945 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2946 | - } |
|
| 2947 | - |
|
| 2948 | - |
|
| 2949 | - /** |
|
| 2950 | - * _attendee_details |
|
| 2951 | - * |
|
| 2952 | - * @access protected |
|
| 2953 | - * @return void |
|
| 2954 | - */ |
|
| 2955 | - public function attendee_registrations_meta_box($post) |
|
| 2956 | - { |
|
| 2957 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2958 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 2959 | - $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 2960 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 2961 | - } |
|
| 2962 | - |
|
| 2963 | - |
|
| 2964 | - /** |
|
| 2965 | - * add in the form fields for the attendee edit |
|
| 2966 | - * |
|
| 2967 | - * @param WP_Post $post wp post object |
|
| 2968 | - * @return string html for new form. |
|
| 2969 | - */ |
|
| 2970 | - public function after_title_form_fields($post) |
|
| 2971 | - { |
|
| 2972 | - if ($post->post_type == 'espresso_attendees') { |
|
| 2973 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 2974 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2975 | - EEH_Template::display_template($template, $template_args); |
|
| 2976 | - } |
|
| 2977 | - } |
|
| 2978 | - |
|
| 2979 | - |
|
| 2980 | - /** |
|
| 2981 | - * _trash_or_restore_attendee |
|
| 2982 | - * |
|
| 2983 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 2984 | - * @access protected |
|
| 2985 | - * @return void |
|
| 2986 | - */ |
|
| 2987 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 2988 | - { |
|
| 2989 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2990 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 2991 | - $success = 1; |
|
| 2992 | - //Checkboxes |
|
| 2993 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2994 | - // if array has more than one element than success message should be plural |
|
| 2995 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2996 | - // cycle thru checkboxes |
|
| 2997 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2998 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 2999 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3000 | - if ( ! $updated) { |
|
| 3001 | - $success = 0; |
|
| 3002 | - } |
|
| 3003 | - } |
|
| 3004 | - } else { |
|
| 3005 | - // grab single id and delete |
|
| 3006 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3007 | - //get attendee |
|
| 3008 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3009 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3010 | - $updated = $att->save(); |
|
| 3011 | - if ( ! $updated) { |
|
| 3012 | - $success = 0; |
|
| 3013 | - } |
|
| 3014 | - } |
|
| 3015 | - $what = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso'); |
|
| 3016 | - $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 3017 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3018 | - } |
|
| 2367 | + } |
|
| 2368 | + $template_args = array( |
|
| 2369 | + 'title' => '', |
|
| 2370 | + 'content' => '', |
|
| 2371 | + 'step_button_text' => '', |
|
| 2372 | + 'show_notification_toggle' => false, |
|
| 2373 | + ); |
|
| 2374 | + //to indicate we're processing a new registration |
|
| 2375 | + $hidden_fields = array( |
|
| 2376 | + 'processing_registration' => array( |
|
| 2377 | + 'type' => 'hidden', |
|
| 2378 | + 'value' => 0, |
|
| 2379 | + ), |
|
| 2380 | + 'event_id' => array( |
|
| 2381 | + 'type' => 'hidden', |
|
| 2382 | + 'value' => $this->_reg_event->ID(), |
|
| 2383 | + ), |
|
| 2384 | + ); |
|
| 2385 | + //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2386 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2387 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2388 | + switch ($step) { |
|
| 2389 | + case 'ticket' : |
|
| 2390 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 2391 | + $template_args['title'] = __('Step One: Select the Ticket for this registration', |
|
| 2392 | + 'event_espresso'); |
|
| 2393 | + $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2394 | + $template_args['step_button_text'] = __('Add Tickets and Continue to Registrant Details', |
|
| 2395 | + 'event_espresso'); |
|
| 2396 | + $template_args['show_notification_toggle'] = false; |
|
| 2397 | + break; |
|
| 2398 | + case 'questions' : |
|
| 2399 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 2400 | + $template_args['title'] = __('Step Two: Add Registrant Details for this Registration', |
|
| 2401 | + 'event_espresso'); |
|
| 2402 | + //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run. |
|
| 2403 | + $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2404 | + $template_args['step_button_text'] = __('Save Registration and Continue to Details', |
|
| 2405 | + 'event_espresso'); |
|
| 2406 | + $template_args['show_notification_toggle'] = true; |
|
| 2407 | + break; |
|
| 2408 | + } |
|
| 2409 | + $this->_set_add_edit_form_tags('process_reg_step', |
|
| 2410 | + $hidden_fields); //we come back to the process_registration_step route. |
|
| 2411 | + return EEH_Template::display_template(REG_TEMPLATE_PATH |
|
| 2412 | + . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2413 | + $template_args, true); |
|
| 2414 | + } |
|
| 2415 | + |
|
| 2416 | + |
|
| 2417 | + /** |
|
| 2418 | + * set_reg_event |
|
| 2419 | + * |
|
| 2420 | + * @access private |
|
| 2421 | + * @return boolean |
|
| 2422 | + */ |
|
| 2423 | + private function _set_reg_event() |
|
| 2424 | + { |
|
| 2425 | + if (is_object($this->_reg_event)) { |
|
| 2426 | + return true; |
|
| 2427 | + } |
|
| 2428 | + $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2429 | + if ( ! $EVT_ID) { |
|
| 2430 | + return false; |
|
| 2431 | + } |
|
| 2432 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2433 | + return true; |
|
| 2434 | + } |
|
| 2435 | + |
|
| 2436 | + |
|
| 2437 | + /** |
|
| 2438 | + * process_reg_step |
|
| 2439 | + * |
|
| 2440 | + * @access public |
|
| 2441 | + * @return string |
|
| 2442 | + * @throws \RuntimeException |
|
| 2443 | + * @throws \EE_Error |
|
| 2444 | + */ |
|
| 2445 | + public function process_reg_step() |
|
| 2446 | + { |
|
| 2447 | + EE_System::do_not_cache(); |
|
| 2448 | + $this->_set_reg_event(); |
|
| 2449 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2450 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2451 | + //what step are we on? |
|
| 2452 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2453 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2454 | + //if doing ajax then we need to verify the nonce |
|
| 2455 | + if (defined('DOING_AJAX')) { |
|
| 2456 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2457 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2458 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2459 | + } |
|
| 2460 | + switch ($step) { |
|
| 2461 | + case 'ticket' : |
|
| 2462 | + //process ticket selection |
|
| 2463 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2464 | + if ($success) { |
|
| 2465 | + EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.', |
|
| 2466 | + 'event_espresso')); |
|
| 2467 | + } else { |
|
| 2468 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2469 | + } |
|
| 2470 | + if (defined('DOING_AJAX')) { |
|
| 2471 | + $this->new_registration(); //display next step |
|
| 2472 | + } else { |
|
| 2473 | + $query_args = array( |
|
| 2474 | + 'action' => 'new_registration', |
|
| 2475 | + 'processing_registration' => 1, |
|
| 2476 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2477 | + 'uts' => time(), |
|
| 2478 | + ); |
|
| 2479 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2480 | + } |
|
| 2481 | + break; |
|
| 2482 | + case 'questions' : |
|
| 2483 | + if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) { |
|
| 2484 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2485 | + } |
|
| 2486 | + //process registration |
|
| 2487 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2488 | + if ($cart instanceof EE_Cart) { |
|
| 2489 | + $grand_total = $cart->get_cart_grand_total(); |
|
| 2490 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 2491 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 2495 | + $query_args = array( |
|
| 2496 | + 'action' => 'new_registration', |
|
| 2497 | + 'processing_registration' => 2, |
|
| 2498 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2499 | + 'uts' => time(), |
|
| 2500 | + ); |
|
| 2501 | + if (defined('DOING_AJAX')) { |
|
| 2502 | + //display registration form again because there are errors (maybe validation?) |
|
| 2503 | + $this->new_registration(); |
|
| 2504 | + return; |
|
| 2505 | + } else { |
|
| 2506 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2507 | + return; |
|
| 2508 | + } |
|
| 2509 | + } |
|
| 2510 | + // maybe update status, and make sure to save transaction if not done already |
|
| 2511 | + if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2512 | + $transaction->save(); |
|
| 2513 | + } |
|
| 2514 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2515 | + $this->_req_data = array(); |
|
| 2516 | + $query_args = array( |
|
| 2517 | + 'action' => 'redirect_to_txn', |
|
| 2518 | + 'TXN_ID' => $transaction->ID(), |
|
| 2519 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2520 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2521 | + 'redirect_from' => 'new_registration', |
|
| 2522 | + ); |
|
| 2523 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2524 | + break; |
|
| 2525 | + } |
|
| 2526 | + //what are you looking here for? Should be nothing to do at this point. |
|
| 2527 | + } |
|
| 2528 | + |
|
| 2529 | + |
|
| 2530 | + /** |
|
| 2531 | + * redirect_to_txn |
|
| 2532 | + * |
|
| 2533 | + * @access public |
|
| 2534 | + * @return void |
|
| 2535 | + */ |
|
| 2536 | + public function redirect_to_txn() |
|
| 2537 | + { |
|
| 2538 | + EE_System::do_not_cache(); |
|
| 2539 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2540 | + $query_args = array( |
|
| 2541 | + 'action' => 'view_transaction', |
|
| 2542 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2543 | + 'page' => 'espresso_transactions', |
|
| 2544 | + ); |
|
| 2545 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2546 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2547 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2548 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2549 | + } |
|
| 2550 | + EE_Error::add_success(__('Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2551 | + 'event_espresso')); |
|
| 2552 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + |
|
| 2556 | + /** |
|
| 2557 | + * generates HTML for the Attendee Contact List |
|
| 2558 | + * |
|
| 2559 | + * @access protected |
|
| 2560 | + * @return void |
|
| 2561 | + */ |
|
| 2562 | + protected function _attendee_contact_list_table() |
|
| 2563 | + { |
|
| 2564 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2565 | + $this->_search_btn_label = __('Contacts', 'event_espresso'); |
|
| 2566 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2567 | + } |
|
| 2568 | + |
|
| 2569 | + |
|
| 2570 | + /** |
|
| 2571 | + * get_attendees |
|
| 2572 | + * |
|
| 2573 | + * @param bool $count whether to return count or data. |
|
| 2574 | + * @access public |
|
| 2575 | + * @return array |
|
| 2576 | + */ |
|
| 2577 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2578 | + { |
|
| 2579 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2580 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2581 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 2582 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2583 | + switch ($this->_req_data['orderby']) { |
|
| 2584 | + case 'ATT_ID': |
|
| 2585 | + $orderby = 'ATT_ID'; |
|
| 2586 | + break; |
|
| 2587 | + case 'ATT_fname': |
|
| 2588 | + $orderby = 'ATT_fname'; |
|
| 2589 | + break; |
|
| 2590 | + case 'ATT_email': |
|
| 2591 | + $orderby = 'ATT_email'; |
|
| 2592 | + break; |
|
| 2593 | + case 'ATT_city': |
|
| 2594 | + $orderby = 'ATT_city'; |
|
| 2595 | + break; |
|
| 2596 | + case 'STA_ID': |
|
| 2597 | + $orderby = 'STA_ID'; |
|
| 2598 | + break; |
|
| 2599 | + case 'CNT_ID': |
|
| 2600 | + $orderby = 'CNT_ID'; |
|
| 2601 | + break; |
|
| 2602 | + default: |
|
| 2603 | + $orderby = 'ATT_lname'; |
|
| 2604 | + } |
|
| 2605 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 2606 | + : 'ASC'; |
|
| 2607 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2608 | + ? $this->_req_data['paged'] : 1; |
|
| 2609 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2610 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2611 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 2612 | + $_where = array(); |
|
| 2613 | + if ( ! empty($this->_req_data['s'])) { |
|
| 2614 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2615 | + $_where['OR'] = array( |
|
| 2616 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2617 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 2618 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 2619 | + 'ATT_fname' => array('LIKE', $sstr), |
|
| 2620 | + 'ATT_lname' => array('LIKE', $sstr), |
|
| 2621 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 2622 | + 'ATT_email' => array('LIKE', $sstr), |
|
| 2623 | + 'ATT_address' => array('LIKE', $sstr), |
|
| 2624 | + 'ATT_address2' => array('LIKE', $sstr), |
|
| 2625 | + 'ATT_city' => array('LIKE', $sstr), |
|
| 2626 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 2627 | + 'State.STA_name' => array('LIKE', $sstr), |
|
| 2628 | + 'ATT_phone' => array('LIKE', $sstr), |
|
| 2629 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 2630 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 2631 | + 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 2632 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 2633 | + ); |
|
| 2634 | + } |
|
| 2635 | + $offset = ($current_page - 1) * $per_page; |
|
| 2636 | + $limit = $count ? null : array($offset, $per_page); |
|
| 2637 | + if ($trash) { |
|
| 2638 | + $_where['status'] = array('!=', 'publish'); |
|
| 2639 | + $all_attendees = $count |
|
| 2640 | + ? $ATT_MDL->count(array( |
|
| 2641 | + $_where, |
|
| 2642 | + 'order_by' => array($orderby => $sort), |
|
| 2643 | + 'limit' => $limit, |
|
| 2644 | + ), 'ATT_ID', true) |
|
| 2645 | + : $ATT_MDL->get_all(array( |
|
| 2646 | + $_where, |
|
| 2647 | + 'order_by' => array($orderby => $sort), |
|
| 2648 | + 'limit' => $limit, |
|
| 2649 | + )); |
|
| 2650 | + } else { |
|
| 2651 | + $_where['status'] = array('IN', array('publish')); |
|
| 2652 | + $all_attendees = $count |
|
| 2653 | + ? $ATT_MDL->count(array( |
|
| 2654 | + $_where, |
|
| 2655 | + 'order_by' => array($orderby => $sort), |
|
| 2656 | + 'limit' => $limit, |
|
| 2657 | + ), 'ATT_ID', true) |
|
| 2658 | + : $ATT_MDL->get_all(array( |
|
| 2659 | + $_where, |
|
| 2660 | + 'order_by' => array($orderby => $sort), |
|
| 2661 | + 'limit' => $limit, |
|
| 2662 | + )); |
|
| 2663 | + } |
|
| 2664 | + return $all_attendees; |
|
| 2665 | + } |
|
| 2666 | + |
|
| 2667 | + |
|
| 2668 | + /** |
|
| 2669 | + * This is just taking care of resending the registration confirmation |
|
| 2670 | + * |
|
| 2671 | + * @access protected |
|
| 2672 | + * @return void |
|
| 2673 | + */ |
|
| 2674 | + protected function _resend_registration() |
|
| 2675 | + { |
|
| 2676 | + $this->_process_resend_registration(); |
|
| 2677 | + $query_args = isset($this->_req_data['redirect_to']) |
|
| 2678 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 2679 | + : array( |
|
| 2680 | + 'action' => 'default', |
|
| 2681 | + ); |
|
| 2682 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + /** |
|
| 2686 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 2687 | + * to use when selecting registrations |
|
| 2688 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 2689 | + * the query parameters from the request |
|
| 2690 | + * @return void ends the request with a redirect or download |
|
| 2691 | + */ |
|
| 2692 | + public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 2693 | + { |
|
| 2694 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2695 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2696 | + 'page' => 'espresso_batch', |
|
| 2697 | + 'batch' => 'file', |
|
| 2698 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2699 | + 'filters' => urlencode( |
|
| 2700 | + serialize( |
|
| 2701 | + call_user_func( |
|
| 2702 | + array( $this, $method_name_for_getting_query_params ), |
|
| 2703 | + EEH_Array::is_set( |
|
| 2704 | + $this->_req_data, |
|
| 2705 | + 'filters', |
|
| 2706 | + array() |
|
| 2707 | + ) |
|
| 2708 | + ) |
|
| 2709 | + ) |
|
| 2710 | + ), |
|
| 2711 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 2712 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 2713 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2714 | + ))); |
|
| 2715 | + } else { |
|
| 2716 | + $new_request_args = array( |
|
| 2717 | + 'export' => 'report', |
|
| 2718 | + 'action' => 'registrations_report_for_event', |
|
| 2719 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 2720 | + ); |
|
| 2721 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 2722 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2723 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2724 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2725 | + $EE_Export->export(); |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + |
|
| 2731 | + |
|
| 2732 | + /** |
|
| 2733 | + * Creates a registration report using only query parameters in the request |
|
| 2734 | + * @return void |
|
| 2735 | + */ |
|
| 2736 | + public function _registrations_report() |
|
| 2737 | + { |
|
| 2738 | + $this->_registrations_report_base( '_get_registration_query_parameters' ); |
|
| 2739 | + } |
|
| 2740 | + |
|
| 2741 | + |
|
| 2742 | + public function _contact_list_export() |
|
| 2743 | + { |
|
| 2744 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2745 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2746 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2747 | + $EE_Export->export_attendees(); |
|
| 2748 | + } |
|
| 2749 | + } |
|
| 2750 | + |
|
| 2751 | + |
|
| 2752 | + public function _contact_list_report() |
|
| 2753 | + { |
|
| 2754 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 2755 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2756 | + 'page' => 'espresso_batch', |
|
| 2757 | + 'batch' => 'file', |
|
| 2758 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 2759 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 2760 | + ))); |
|
| 2761 | + } else { |
|
| 2762 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 2763 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 2764 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 2765 | + $EE_Export->report_attendees(); |
|
| 2766 | + } |
|
| 2767 | + } |
|
| 2768 | + } |
|
| 2769 | + |
|
| 2770 | + |
|
| 2771 | + |
|
| 2772 | + |
|
| 2773 | + |
|
| 2774 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 2775 | + /** |
|
| 2776 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 2777 | + * |
|
| 2778 | + * @return void |
|
| 2779 | + */ |
|
| 2780 | + protected function _duplicate_attendee() |
|
| 2781 | + { |
|
| 2782 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 2783 | + //verify we have necessary info |
|
| 2784 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2785 | + EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 2786 | + 'event_espresso'), __FILE__, __LINE__, __FUNCTION__); |
|
| 2787 | + $query_args = array('action' => $action); |
|
| 2788 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2789 | + } |
|
| 2790 | + //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 2791 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 2792 | + $attendee = $registration->attendee(); |
|
| 2793 | + //remove relation of existing attendee on registration |
|
| 2794 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2795 | + //new attendee |
|
| 2796 | + $new_attendee = clone $attendee; |
|
| 2797 | + $new_attendee->set('ATT_ID', 0); |
|
| 2798 | + $new_attendee->save(); |
|
| 2799 | + //add new attendee to reg |
|
| 2800 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 2801 | + EE_Error::add_success(__('New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 2802 | + 'event_espresso')); |
|
| 2803 | + //redirect to edit page for attendee |
|
| 2804 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 2805 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 2806 | + } |
|
| 2807 | + |
|
| 2808 | + |
|
| 2809 | + //related to cpt routes |
|
| 2810 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 2811 | + { |
|
| 2812 | + $success = true; |
|
| 2813 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 2814 | + //for attendee updates |
|
| 2815 | + if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 2816 | + //note we should only be UPDATING attendees at this point. |
|
| 2817 | + $updated_fields = array( |
|
| 2818 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 2819 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 2820 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 2821 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 2822 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 2823 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 2824 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 2825 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 2826 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 2827 | + 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 2828 | + 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 2829 | + ); |
|
| 2830 | + foreach ($updated_fields as $field => $value) { |
|
| 2831 | + $attendee->set($field, $value); |
|
| 2832 | + } |
|
| 2833 | + $success = $attendee->save(); |
|
| 2834 | + $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 2835 | + array()); |
|
| 2836 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 2837 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 2838 | + throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 2839 | + 'event_espresso'), $a_callback)); |
|
| 2840 | + } |
|
| 2841 | + } |
|
| 2842 | + } |
|
| 2843 | + if ($success === false) { |
|
| 2844 | + EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.', |
|
| 2845 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 2846 | + } |
|
| 2847 | + } |
|
| 2848 | + |
|
| 2849 | + |
|
| 2850 | + public function trash_cpt_item($post_id) |
|
| 2851 | + { |
|
| 2852 | + } |
|
| 2853 | + |
|
| 2854 | + |
|
| 2855 | + public function delete_cpt_item($post_id) |
|
| 2856 | + { |
|
| 2857 | + } |
|
| 2858 | + |
|
| 2859 | + |
|
| 2860 | + public function restore_cpt_item($post_id) |
|
| 2861 | + { |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + |
|
| 2865 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 2866 | + { |
|
| 2867 | + } |
|
| 2868 | + |
|
| 2869 | + |
|
| 2870 | + public function attendee_editor_metaboxes() |
|
| 2871 | + { |
|
| 2872 | + $this->verify_cpt_object(); |
|
| 2873 | + remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 2874 | + 'normal', 'core'); |
|
| 2875 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2876 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 2877 | + add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box', |
|
| 2878 | + $this->_cpt_routes[$this->_req_action], 'normal'); |
|
| 2879 | + } |
|
| 2880 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 2881 | + add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box', |
|
| 2882 | + $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2883 | + } |
|
| 2884 | + add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'), |
|
| 2885 | + array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core'); |
|
| 2886 | + add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'), |
|
| 2887 | + array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 2888 | + add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'), |
|
| 2889 | + array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high'); |
|
| 2890 | + } |
|
| 2891 | + |
|
| 2892 | + |
|
| 2893 | + /** |
|
| 2894 | + * Metabox for attendee contact info |
|
| 2895 | + * |
|
| 2896 | + * @param WP_Post $post wp post object |
|
| 2897 | + * @return string attendee contact info ( and form ) |
|
| 2898 | + */ |
|
| 2899 | + public function attendee_contact_info($post) |
|
| 2900 | + { |
|
| 2901 | + //get attendee object ( should already have it ) |
|
| 2902 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2903 | + $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 2904 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2905 | + } |
|
| 2906 | + |
|
| 2907 | + |
|
| 2908 | + /** |
|
| 2909 | + * Metabox for attendee details |
|
| 2910 | + * |
|
| 2911 | + * @param WP_Post $post wp post object |
|
| 2912 | + * @return string attendee address details (and form) |
|
| 2913 | + */ |
|
| 2914 | + public function attendee_address_details($post) |
|
| 2915 | + { |
|
| 2916 | + //get attendee object (should already have it) |
|
| 2917 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2918 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2919 | + 'QST_ID' => 0, |
|
| 2920 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 2921 | + 'QST_system' => 'admin-state', |
|
| 2922 | + )), EE_Answer::new_instance(array( |
|
| 2923 | + 'ANS_ID' => 0, |
|
| 2924 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 2925 | + )), array( |
|
| 2926 | + 'input_id' => 'STA_ID', |
|
| 2927 | + 'input_name' => 'STA_ID', |
|
| 2928 | + 'input_prefix' => '', |
|
| 2929 | + 'append_qstn_id' => false, |
|
| 2930 | + ))); |
|
| 2931 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array( |
|
| 2932 | + 'QST_ID' => 0, |
|
| 2933 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 2934 | + 'QST_system' => 'admin-country', |
|
| 2935 | + )), EE_Answer::new_instance(array( |
|
| 2936 | + 'ANS_ID' => 0, |
|
| 2937 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 2938 | + )), array( |
|
| 2939 | + 'input_id' => 'CNT_ISO', |
|
| 2940 | + 'input_name' => 'CNT_ISO', |
|
| 2941 | + 'input_prefix' => '', |
|
| 2942 | + 'append_qstn_id' => false, |
|
| 2943 | + ))); |
|
| 2944 | + $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 2945 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2946 | + } |
|
| 2947 | + |
|
| 2948 | + |
|
| 2949 | + /** |
|
| 2950 | + * _attendee_details |
|
| 2951 | + * |
|
| 2952 | + * @access protected |
|
| 2953 | + * @return void |
|
| 2954 | + */ |
|
| 2955 | + public function attendee_registrations_meta_box($post) |
|
| 2956 | + { |
|
| 2957 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2958 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 2959 | + $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 2960 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 2961 | + } |
|
| 2962 | + |
|
| 2963 | + |
|
| 2964 | + /** |
|
| 2965 | + * add in the form fields for the attendee edit |
|
| 2966 | + * |
|
| 2967 | + * @param WP_Post $post wp post object |
|
| 2968 | + * @return string html for new form. |
|
| 2969 | + */ |
|
| 2970 | + public function after_title_form_fields($post) |
|
| 2971 | + { |
|
| 2972 | + if ($post->post_type == 'espresso_attendees') { |
|
| 2973 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 2974 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 2975 | + EEH_Template::display_template($template, $template_args); |
|
| 2976 | + } |
|
| 2977 | + } |
|
| 2978 | + |
|
| 2979 | + |
|
| 2980 | + /** |
|
| 2981 | + * _trash_or_restore_attendee |
|
| 2982 | + * |
|
| 2983 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 2984 | + * @access protected |
|
| 2985 | + * @return void |
|
| 2986 | + */ |
|
| 2987 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 2988 | + { |
|
| 2989 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2990 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 2991 | + $success = 1; |
|
| 2992 | + //Checkboxes |
|
| 2993 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 2994 | + // if array has more than one element than success message should be plural |
|
| 2995 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 2996 | + // cycle thru checkboxes |
|
| 2997 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 2998 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 2999 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3000 | + if ( ! $updated) { |
|
| 3001 | + $success = 0; |
|
| 3002 | + } |
|
| 3003 | + } |
|
| 3004 | + } else { |
|
| 3005 | + // grab single id and delete |
|
| 3006 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3007 | + //get attendee |
|
| 3008 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3009 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3010 | + $updated = $att->save(); |
|
| 3011 | + if ( ! $updated) { |
|
| 3012 | + $success = 0; |
|
| 3013 | + } |
|
| 3014 | + } |
|
| 3015 | + $what = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso'); |
|
| 3016 | + $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'); |
|
| 3017 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3018 | + } |
|
| 3019 | 3019 | |
| 3020 | 3020 | } |
| 3021 | 3021 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -24,445 +24,445 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * This gets set in _setup_cpt |
|
| 29 | - * It will contain the object for the custom post type. |
|
| 30 | - * |
|
| 31 | - * @var object |
|
| 32 | - */ |
|
| 33 | - protected $_cpt_object; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
| 39 | - * |
|
| 40 | - * @var bool |
|
| 41 | - */ |
|
| 42 | - protected $_cpt_route = false; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 48 | - * //in this array we define what the custom post type for this route is. |
|
| 49 | - * array( |
|
| 50 | - * 'route_name' => 'custom_post_type_slug' |
|
| 51 | - * ) |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $_cpt_routes = array(); |
|
| 56 | - |
|
| 27 | + /** |
|
| 28 | + * This gets set in _setup_cpt |
|
| 29 | + * It will contain the object for the custom post type. |
|
| 30 | + * |
|
| 31 | + * @var object |
|
| 32 | + */ |
|
| 33 | + protected $_cpt_object; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
| 39 | + * |
|
| 40 | + * @var bool |
|
| 41 | + */ |
|
| 42 | + protected $_cpt_route = false; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
| 48 | + * //in this array we define what the custom post type for this route is. |
|
| 49 | + * array( |
|
| 50 | + * 'route_name' => 'custom_post_type_slug' |
|
| 51 | + * ) |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $_cpt_routes = array(); |
|
| 56 | + |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 61 | - * in this format: |
|
| 62 | - * array( |
|
| 63 | - * 'post_type_slug' => 'edit_route' |
|
| 64 | - * ) |
|
| 65 | - * |
|
| 66 | - * @var array |
|
| 67 | - */ |
|
| 68 | - protected $_cpt_edit_routes = array(); |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 74 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 75 | - * _cpt_model_names property should be in the following format: array( |
|
| 76 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
| 77 | - * |
|
| 78 | - * @var array $_cpt_model_names |
|
| 79 | - */ |
|
| 80 | - protected $_cpt_model_names = array(); |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var EE_CPT_Base |
|
| 85 | - */ |
|
| 86 | - protected $_cpt_model_obj = false; |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 92 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 93 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 94 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
| 95 | - * |
|
| 96 | - * @var array() |
|
| 97 | - */ |
|
| 98 | - protected $_autosave_containers = array(); |
|
| 99 | - protected $_autosave_fields = array(); |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 103 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 104 | - * |
|
| 105 | - * @var array |
|
| 106 | - */ |
|
| 107 | - protected $_pagenow_map = null; |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 113 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 114 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 115 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 116 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 117 | - * |
|
| 118 | - * @access protected |
|
| 119 | - * @abstract |
|
| 120 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 121 | - * @param object $post The post object of the cpt that was saved. |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 130 | - * |
|
| 131 | - * @abstract |
|
| 132 | - * @access public |
|
| 133 | - * @param string $post_id The ID of the cpt that was trashed |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - abstract public function trash_cpt_item($post_id); |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 142 | - * |
|
| 143 | - * @param string $post_id theID of the cpt that was untrashed |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - abstract public function restore_cpt_item($post_id); |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 152 | - * from the db |
|
| 153 | - * |
|
| 154 | - * @param string $post_id the ID of the cpt that was deleted |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - abstract public function delete_cpt_item($post_id); |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 163 | - * |
|
| 164 | - * @access protected |
|
| 165 | - * @return void |
|
| 166 | - */ |
|
| 167 | - protected function _before_page_setup() |
|
| 168 | - { |
|
| 169 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
| 170 | - $this->_cpt_routes = array_merge(array( |
|
| 171 | - 'create_new' => $this->page_slug, |
|
| 172 | - 'edit' => $this->page_slug, |
|
| 173 | - 'trash' => $this->page_slug, |
|
| 174 | - ), $this->_cpt_routes); |
|
| 175 | - //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
| 176 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 177 | - ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
| 178 | - : get_post_type_object($page); |
|
| 179 | - //tweak pagenow for page loading. |
|
| 180 | - if ( ! $this->_pagenow_map) { |
|
| 181 | - $this->_pagenow_map = array( |
|
| 182 | - 'create_new' => 'post-new.php', |
|
| 183 | - 'edit' => 'post.php', |
|
| 184 | - 'trash' => 'post.php', |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
| 188 | - //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 189 | - //get current page from autosave |
|
| 190 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
| 191 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
| 192 | - : null; |
|
| 193 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
| 194 | - ? $this->_req_data['current_page'] |
|
| 195 | - : $current_page; |
|
| 196 | - //autosave... make sure its only for the correct page |
|
| 197 | - if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
| 198 | - //setup autosave ajax hook |
|
| 199 | - //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
| 207 | - * |
|
| 208 | - * @param WP_Screen $current_screen |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function modify_pagenow($current_screen) |
|
| 212 | - { |
|
| 213 | - global $pagenow, $hook_suffix; |
|
| 214 | - //possibly reset pagenow. |
|
| 215 | - if ( ! empty($this->_req_data['page']) |
|
| 216 | - && $this->_req_data['page'] == $this->page_slug |
|
| 217 | - && ! empty($this->_req_data['action']) |
|
| 218 | - && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
| 219 | - ) { |
|
| 220 | - $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
| 221 | - $hook_suffix = $pagenow; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 229 | - * |
|
| 230 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 231 | - * automatically register the id for the post metabox as a container. |
|
| 232 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 233 | - * you would send along the id of a metabox container. |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - protected function _register_autosave_containers($ids) |
|
| 237 | - { |
|
| 238 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 245 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 246 | - */ |
|
| 247 | - protected function _set_autosave_containers() |
|
| 248 | - { |
|
| 249 | - global $wp_meta_boxes; |
|
| 250 | - $containers = array(); |
|
| 251 | - if (empty($wp_meta_boxes)) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
| 255 | - foreach ($current_metaboxes as $box_context) { |
|
| 256 | - foreach ($box_context as $box_details) { |
|
| 257 | - foreach ($box_details as $box) { |
|
| 258 | - if (is_array($box['callback']) |
|
| 259 | - && ($box['callback'][0] instanceof EE_Admin_Page |
|
| 260 | - || $box['callback'][0] instanceof EE_Admin_Hooks) |
|
| 261 | - ) { |
|
| 262 | - $containers[] = $box['id']; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 268 | - //add hidden inputs container |
|
| 269 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - protected function _load_autosave_scripts_styles() |
|
| 275 | - { |
|
| 276 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 59 | + /** |
|
| 60 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
| 61 | + * in this format: |
|
| 62 | + * array( |
|
| 63 | + * 'post_type_slug' => 'edit_route' |
|
| 64 | + * ) |
|
| 65 | + * |
|
| 66 | + * @var array |
|
| 67 | + */ |
|
| 68 | + protected $_cpt_edit_routes = array(); |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
| 74 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
| 75 | + * _cpt_model_names property should be in the following format: array( |
|
| 76 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
| 77 | + * |
|
| 78 | + * @var array $_cpt_model_names |
|
| 79 | + */ |
|
| 80 | + protected $_cpt_model_names = array(); |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var EE_CPT_Base |
|
| 85 | + */ |
|
| 86 | + protected $_cpt_model_obj = false; |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
| 92 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
| 93 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
| 94 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
| 95 | + * |
|
| 96 | + * @var array() |
|
| 97 | + */ |
|
| 98 | + protected $_autosave_containers = array(); |
|
| 99 | + protected $_autosave_fields = array(); |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
| 103 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
| 104 | + * |
|
| 105 | + * @var array |
|
| 106 | + */ |
|
| 107 | + protected $_pagenow_map = null; |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
| 113 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
| 114 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
| 115 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
| 116 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
| 117 | + * |
|
| 118 | + * @access protected |
|
| 119 | + * @abstract |
|
| 120 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
| 121 | + * @param object $post The post object of the cpt that was saved. |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
| 130 | + * |
|
| 131 | + * @abstract |
|
| 132 | + * @access public |
|
| 133 | + * @param string $post_id The ID of the cpt that was trashed |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + abstract public function trash_cpt_item($post_id); |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
| 142 | + * |
|
| 143 | + * @param string $post_id theID of the cpt that was untrashed |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + abstract public function restore_cpt_item($post_id); |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
| 152 | + * from the db |
|
| 153 | + * |
|
| 154 | + * @param string $post_id the ID of the cpt that was deleted |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + abstract public function delete_cpt_item($post_id); |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
| 163 | + * |
|
| 164 | + * @access protected |
|
| 165 | + * @return void |
|
| 166 | + */ |
|
| 167 | + protected function _before_page_setup() |
|
| 168 | + { |
|
| 169 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
| 170 | + $this->_cpt_routes = array_merge(array( |
|
| 171 | + 'create_new' => $this->page_slug, |
|
| 172 | + 'edit' => $this->page_slug, |
|
| 173 | + 'trash' => $this->page_slug, |
|
| 174 | + ), $this->_cpt_routes); |
|
| 175 | + //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
| 176 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 177 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
| 178 | + : get_post_type_object($page); |
|
| 179 | + //tweak pagenow for page loading. |
|
| 180 | + if ( ! $this->_pagenow_map) { |
|
| 181 | + $this->_pagenow_map = array( |
|
| 182 | + 'create_new' => 'post-new.php', |
|
| 183 | + 'edit' => 'post.php', |
|
| 184 | + 'trash' => 'post.php', |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
| 188 | + //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
| 189 | + //get current page from autosave |
|
| 190 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
| 191 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
| 192 | + : null; |
|
| 193 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
| 194 | + ? $this->_req_data['current_page'] |
|
| 195 | + : $current_page; |
|
| 196 | + //autosave... make sure its only for the correct page |
|
| 197 | + if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
| 198 | + //setup autosave ajax hook |
|
| 199 | + //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
| 207 | + * |
|
| 208 | + * @param WP_Screen $current_screen |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function modify_pagenow($current_screen) |
|
| 212 | + { |
|
| 213 | + global $pagenow, $hook_suffix; |
|
| 214 | + //possibly reset pagenow. |
|
| 215 | + if ( ! empty($this->_req_data['page']) |
|
| 216 | + && $this->_req_data['page'] == $this->page_slug |
|
| 217 | + && ! empty($this->_req_data['action']) |
|
| 218 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
| 219 | + ) { |
|
| 220 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
| 221 | + $hook_suffix = $pagenow; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
| 229 | + * |
|
| 230 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
| 231 | + * automatically register the id for the post metabox as a container. |
|
| 232 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
| 233 | + * you would send along the id of a metabox container. |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + protected function _register_autosave_containers($ids) |
|
| 237 | + { |
|
| 238 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
| 245 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
| 246 | + */ |
|
| 247 | + protected function _set_autosave_containers() |
|
| 248 | + { |
|
| 249 | + global $wp_meta_boxes; |
|
| 250 | + $containers = array(); |
|
| 251 | + if (empty($wp_meta_boxes)) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
| 255 | + foreach ($current_metaboxes as $box_context) { |
|
| 256 | + foreach ($box_context as $box_details) { |
|
| 257 | + foreach ($box_details as $box) { |
|
| 258 | + if (is_array($box['callback']) |
|
| 259 | + && ($box['callback'][0] instanceof EE_Admin_Page |
|
| 260 | + || $box['callback'][0] instanceof EE_Admin_Hooks) |
|
| 261 | + ) { |
|
| 262 | + $containers[] = $box['id']; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
| 268 | + //add hidden inputs container |
|
| 269 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + protected function _load_autosave_scripts_styles() |
|
| 275 | + { |
|
| 276 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 277 | 277 | wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2 |
| 278 | 278 | |
| 279 | - //filter _autosave_containers |
|
| 280 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 281 | - $this->_autosave_containers, $this); |
|
| 282 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 283 | - $containers, $this); |
|
| 284 | - |
|
| 285 | - wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
| 286 | - $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 287 | - |
|
| 288 | - $unsaved_data_msg = array( |
|
| 289 | - 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 290 | - 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 291 | - 'inputChanged' => 0, |
|
| 292 | - ); |
|
| 293 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - public function load_page_dependencies() |
|
| 299 | - { |
|
| 300 | - try { |
|
| 301 | - $this->_load_page_dependencies(); |
|
| 302 | - } catch (EE_Error $e) { |
|
| 303 | - $e->get_error(); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 311 | - * |
|
| 312 | - * @access protected |
|
| 313 | - * @return void |
|
| 314 | - */ |
|
| 315 | - protected function _load_page_dependencies() |
|
| 316 | - { |
|
| 317 | - //we only add stuff if this is a cpt_route! |
|
| 318 | - if ( ! $this->_cpt_route) { |
|
| 319 | - parent::_load_page_dependencies(); |
|
| 320 | - return; |
|
| 321 | - } |
|
| 322 | - //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place. |
|
| 323 | - //the following filters are for setting all the redirects on DEFAULT WP custom post type actions |
|
| 324 | - //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects! Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 325 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
| 326 | - //inject our Admin page nav tabs... |
|
| 327 | - //let's make sure the nav tabs are set if they aren't already |
|
| 328 | - //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 329 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
| 330 | - //modify the post_updated messages array |
|
| 331 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
| 332 | - //add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
| 333 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
| 334 | - //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 335 | - if ( ! empty($this->_labels['publishbox'])) { |
|
| 336 | - $box_label = is_array($this->_labels['publishbox']) |
|
| 337 | - && isset($this->_labels['publishbox'][$this->_req_action]) |
|
| 338 | - ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 339 | - remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 340 | - 'side', 'core'); |
|
| 341 | - add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 342 | - 'side', 'core'); |
|
| 343 | - } |
|
| 344 | - //let's add page_templates metabox if this cpt added support for it. |
|
| 345 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 346 | - add_meta_box('page_templates', __('Page Template', 'event_espresso'), |
|
| 347 | - array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default'); |
|
| 348 | - } |
|
| 349 | - //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 350 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
| 351 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
| 352 | - } |
|
| 353 | - //add preview button |
|
| 354 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
| 355 | - //insert our own post_stati dropdown |
|
| 356 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
| 357 | - //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 358 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 359 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
| 360 | - } |
|
| 361 | - //This allows for adding additional stuff after the title field on the wp post edit form. This is also before the wp_editor for post description field. |
|
| 362 | - if (method_exists($this, 'edit_form_after_title')) { |
|
| 363 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
| 364 | - } |
|
| 365 | - /** |
|
| 366 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 367 | - */ |
|
| 368 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
| 369 | - parent::_load_page_dependencies(); |
|
| 370 | - //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes. |
|
| 371 | - global $pagenow; |
|
| 372 | - do_action('load-' . $pagenow); |
|
| 373 | - $this->modify_current_screen(); |
|
| 374 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
| 375 | - //we route REALLY early. |
|
| 376 | - try { |
|
| 377 | - $this->_route_admin_request(); |
|
| 378 | - } catch (EE_Error $e) { |
|
| 379 | - $e->get_error(); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 387 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 388 | - * route instead. |
|
| 389 | - * |
|
| 390 | - * @param string $good_protocol_url The escaped url. |
|
| 391 | - * @param string $original_url The original url. |
|
| 392 | - * @param string $_context The context sendt to the esc_url method. |
|
| 393 | - * @return string possibly a new url for our route. |
|
| 394 | - */ |
|
| 395 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
| 396 | - { |
|
| 397 | - $routes_to_match = array( |
|
| 398 | - 0 => array( |
|
| 399 | - 'edit.php?post_type=espresso_attendees', |
|
| 400 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 401 | - ), |
|
| 402 | - 1 => array( |
|
| 403 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 404 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
| 405 | - ), |
|
| 406 | - ); |
|
| 407 | - foreach ($routes_to_match as $route_matches) { |
|
| 408 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 409 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - return $good_protocol_url; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Determine whether the current cpt supports page templates or not. |
|
| 419 | - * |
|
| 420 | - * @since %VER% |
|
| 421 | - * @param string $cpt_name The cpt slug we're checking on. |
|
| 422 | - * @return bool True supported, false not. |
|
| 423 | - */ |
|
| 424 | - private function _supports_page_templates($cpt_name) |
|
| 425 | - { |
|
| 426 | - |
|
| 427 | - $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
| 428 | - $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
| 429 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 430 | - |
|
| 431 | - //if the installed version of WP is > 4.7 we do some additional checks. |
|
| 432 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 433 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
| 434 | - //if there are $post_templates for this cpt, then we return false for this method because |
|
| 435 | - //that means we aren't going to load our page template manager and leave that up to the native |
|
| 436 | - //cpt template manager. |
|
| 437 | - $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - return $cpt_has_support; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Callback for the page_templates metabox selector. |
|
| 446 | - * |
|
| 447 | - * @since %VER% |
|
| 448 | - * @return string html |
|
| 449 | - */ |
|
| 450 | - public function page_template_meta_box() |
|
| 451 | - { |
|
| 452 | - global $post; |
|
| 453 | - $template = ''; |
|
| 454 | - |
|
| 455 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 456 | - $page_template_count = count(get_page_templates()); |
|
| 457 | - } else { |
|
| 458 | - $page_template_count = count(get_page_templates($post)); |
|
| 459 | - }; |
|
| 460 | - |
|
| 461 | - if ($page_template_count) { |
|
| 462 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 463 | - $template = ! empty($page_template) ? $page_template : ''; |
|
| 464 | - } |
|
| 465 | - ?> |
|
| 279 | + //filter _autosave_containers |
|
| 280 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
| 281 | + $this->_autosave_containers, $this); |
|
| 282 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 283 | + $containers, $this); |
|
| 284 | + |
|
| 285 | + wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
| 286 | + $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
| 287 | + |
|
| 288 | + $unsaved_data_msg = array( |
|
| 289 | + 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
| 290 | + 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 291 | + 'inputChanged' => 0, |
|
| 292 | + ); |
|
| 293 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + public function load_page_dependencies() |
|
| 299 | + { |
|
| 300 | + try { |
|
| 301 | + $this->_load_page_dependencies(); |
|
| 302 | + } catch (EE_Error $e) { |
|
| 303 | + $e->get_error(); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
| 311 | + * |
|
| 312 | + * @access protected |
|
| 313 | + * @return void |
|
| 314 | + */ |
|
| 315 | + protected function _load_page_dependencies() |
|
| 316 | + { |
|
| 317 | + //we only add stuff if this is a cpt_route! |
|
| 318 | + if ( ! $this->_cpt_route) { |
|
| 319 | + parent::_load_page_dependencies(); |
|
| 320 | + return; |
|
| 321 | + } |
|
| 322 | + //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place. |
|
| 323 | + //the following filters are for setting all the redirects on DEFAULT WP custom post type actions |
|
| 324 | + //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects! Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
| 325 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
| 326 | + //inject our Admin page nav tabs... |
|
| 327 | + //let's make sure the nav tabs are set if they aren't already |
|
| 328 | + //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
| 329 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
| 330 | + //modify the post_updated messages array |
|
| 331 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
| 332 | + //add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts! |
|
| 333 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
| 334 | + //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
| 335 | + if ( ! empty($this->_labels['publishbox'])) { |
|
| 336 | + $box_label = is_array($this->_labels['publishbox']) |
|
| 337 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
| 338 | + ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox']; |
|
| 339 | + remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 340 | + 'side', 'core'); |
|
| 341 | + add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action], |
|
| 342 | + 'side', 'core'); |
|
| 343 | + } |
|
| 344 | + //let's add page_templates metabox if this cpt added support for it. |
|
| 345 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
| 346 | + add_meta_box('page_templates', __('Page Template', 'event_espresso'), |
|
| 347 | + array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default'); |
|
| 348 | + } |
|
| 349 | + //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
| 350 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
| 351 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
| 352 | + } |
|
| 353 | + //add preview button |
|
| 354 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
| 355 | + //insert our own post_stati dropdown |
|
| 356 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
| 357 | + //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
| 358 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
| 359 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
| 360 | + } |
|
| 361 | + //This allows for adding additional stuff after the title field on the wp post edit form. This is also before the wp_editor for post description field. |
|
| 362 | + if (method_exists($this, 'edit_form_after_title')) { |
|
| 363 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
| 364 | + } |
|
| 365 | + /** |
|
| 366 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
| 367 | + */ |
|
| 368 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
| 369 | + parent::_load_page_dependencies(); |
|
| 370 | + //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes. |
|
| 371 | + global $pagenow; |
|
| 372 | + do_action('load-' . $pagenow); |
|
| 373 | + $this->modify_current_screen(); |
|
| 374 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
| 375 | + //we route REALLY early. |
|
| 376 | + try { |
|
| 377 | + $this->_route_admin_request(); |
|
| 378 | + } catch (EE_Error $e) { |
|
| 379 | + $e->get_error(); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
| 387 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
| 388 | + * route instead. |
|
| 389 | + * |
|
| 390 | + * @param string $good_protocol_url The escaped url. |
|
| 391 | + * @param string $original_url The original url. |
|
| 392 | + * @param string $_context The context sendt to the esc_url method. |
|
| 393 | + * @return string possibly a new url for our route. |
|
| 394 | + */ |
|
| 395 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
| 396 | + { |
|
| 397 | + $routes_to_match = array( |
|
| 398 | + 0 => array( |
|
| 399 | + 'edit.php?post_type=espresso_attendees', |
|
| 400 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
| 401 | + ), |
|
| 402 | + 1 => array( |
|
| 403 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 404 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
| 405 | + ), |
|
| 406 | + ); |
|
| 407 | + foreach ($routes_to_match as $route_matches) { |
|
| 408 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
| 409 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + return $good_protocol_url; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Determine whether the current cpt supports page templates or not. |
|
| 419 | + * |
|
| 420 | + * @since %VER% |
|
| 421 | + * @param string $cpt_name The cpt slug we're checking on. |
|
| 422 | + * @return bool True supported, false not. |
|
| 423 | + */ |
|
| 424 | + private function _supports_page_templates($cpt_name) |
|
| 425 | + { |
|
| 426 | + |
|
| 427 | + $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
| 428 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
| 429 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
| 430 | + |
|
| 431 | + //if the installed version of WP is > 4.7 we do some additional checks. |
|
| 432 | + if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 433 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
| 434 | + //if there are $post_templates for this cpt, then we return false for this method because |
|
| 435 | + //that means we aren't going to load our page template manager and leave that up to the native |
|
| 436 | + //cpt template manager. |
|
| 437 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + return $cpt_has_support; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Callback for the page_templates metabox selector. |
|
| 446 | + * |
|
| 447 | + * @since %VER% |
|
| 448 | + * @return string html |
|
| 449 | + */ |
|
| 450 | + public function page_template_meta_box() |
|
| 451 | + { |
|
| 452 | + global $post; |
|
| 453 | + $template = ''; |
|
| 454 | + |
|
| 455 | + if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 456 | + $page_template_count = count(get_page_templates()); |
|
| 457 | + } else { |
|
| 458 | + $page_template_count = count(get_page_templates($post)); |
|
| 459 | + }; |
|
| 460 | + |
|
| 461 | + if ($page_template_count) { |
|
| 462 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
| 463 | + $template = ! empty($page_template) ? $page_template : ''; |
|
| 464 | + } |
|
| 465 | + ?> |
|
| 466 | 466 | <p><strong><?php _e('Template') ?></strong></p> |
| 467 | 467 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select |
| 468 | 468 | name="page_template" id="page_template"> |
@@ -470,435 +470,435 @@ discard block |
||
| 470 | 470 | <?php page_template_dropdown($template); ?> |
| 471 | 471 | </select> |
| 472 | 472 | <?php |
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 479 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 480 | - * |
|
| 481 | - * @param string $return the current html |
|
| 482 | - * @param int $id the post id for the page |
|
| 483 | - * @param string $new_title What the title is |
|
| 484 | - * @param string $new_slug what the slug is |
|
| 485 | - * @return string The new html string for the permalink area |
|
| 486 | - */ |
|
| 487 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
| 488 | - { |
|
| 489 | - $post = get_post($id); |
|
| 490 | - if ('publish' != get_post_status($post)) { |
|
| 491 | - //include shims for the `get_preview_post_link` function |
|
| 492 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
| 493 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
| 494 | - . get_preview_post_link($id) |
|
| 495 | - . '" class="button button-small">' |
|
| 496 | - . __('Preview', 'event_espresso') |
|
| 497 | - . '</a></span>' |
|
| 498 | - . "\n"; |
|
| 499 | - } |
|
| 500 | - return $return; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
| 507 | - * |
|
| 508 | - * @return string html for dropdown |
|
| 509 | - */ |
|
| 510 | - public function custom_post_stati_dropdown() |
|
| 511 | - { |
|
| 512 | - |
|
| 513 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 514 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 515 | - ? $statuses[$this->_cpt_model_obj->status()] |
|
| 516 | - : ''; |
|
| 517 | - $template_args = array( |
|
| 518 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 519 | - 'statuses' => $statuses, |
|
| 520 | - 'cur_status_label' => $cur_status_label, |
|
| 521 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 522 | - ); |
|
| 523 | - //we'll add a trash post status (WP doesn't add one for some reason) |
|
| 524 | - if ($this->_cpt_model_obj->status() == 'trash') { |
|
| 525 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
| 526 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
| 527 | - $template_args['statuses'] = $statuses; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 531 | - EEH_Template::display_template($template, $template_args); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - public function setup_autosave_hooks() |
|
| 537 | - { |
|
| 538 | - $this->_set_autosave_containers(); |
|
| 539 | - $this->_load_autosave_scripts_styles(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
| 546 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 547 | - * for the nonce in here, but then this method looks for two things: |
|
| 548 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 549 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 550 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 551 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 552 | - * template args. |
|
| 553 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 554 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 555 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 556 | - * $this->_template_args['data']['items'] = array( |
|
| 557 | - * 'event-datetime-ids' => '1,2,3'; |
|
| 558 | - * ); |
|
| 559 | - * Keep in mind the following things: |
|
| 560 | - * - "where" index is for the input with the id as that string. |
|
| 561 | - * - "what" index is what will be used for the value of that input. |
|
| 562 | - * |
|
| 563 | - * @return void |
|
| 564 | - */ |
|
| 565 | - public function do_extra_autosave_stuff() |
|
| 566 | - { |
|
| 567 | - //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 568 | - $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null; |
|
| 569 | - $this->_verify_nonce($nonce, 'autosave'); |
|
| 570 | - //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 571 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
| 572 | - define('DOING_AUTOSAVE', true); |
|
| 573 | - } |
|
| 574 | - //if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 575 | - if (method_exists($this, '_ee_autosave_' . $this->_current_view)) { |
|
| 576 | - call_user_func(array($this, '_ee_autosave_' . $this->_current_view)); |
|
| 577 | - } else { |
|
| 578 | - $this->_template_args['success'] = true; |
|
| 579 | - } |
|
| 580 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 581 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 582 | - //now let's return json |
|
| 583 | - $this->_return_json(); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 590 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 591 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 592 | - * |
|
| 593 | - * @access protected |
|
| 594 | - * @throws EE_Error |
|
| 595 | - * @return void |
|
| 596 | - */ |
|
| 597 | - protected function _extend_page_config_for_cpt() |
|
| 598 | - { |
|
| 599 | - //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 600 | - if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) { |
|
| 601 | - return; |
|
| 602 | - } |
|
| 603 | - //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 604 | - if ( ! empty($this->_cpt_object)) { |
|
| 605 | - $this->_page_routes = array_merge(array( |
|
| 606 | - 'create_new' => '_create_new_cpt_item', |
|
| 607 | - 'edit' => '_edit_cpt_item', |
|
| 608 | - ), $this->_page_routes); |
|
| 609 | - $this->_page_config = array_merge(array( |
|
| 610 | - 'create_new' => array( |
|
| 611 | - 'nav' => array( |
|
| 612 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 613 | - 'order' => 5, |
|
| 614 | - ), |
|
| 615 | - 'require_nonce' => false, |
|
| 616 | - ), |
|
| 617 | - 'edit' => array( |
|
| 618 | - 'nav' => array( |
|
| 619 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
| 620 | - 'order' => 5, |
|
| 621 | - 'persistent' => false, |
|
| 622 | - 'url' => '', |
|
| 623 | - ), |
|
| 624 | - 'require_nonce' => false, |
|
| 625 | - ), |
|
| 626 | - ), |
|
| 627 | - $this->_page_config |
|
| 628 | - ); |
|
| 629 | - } |
|
| 630 | - //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 631 | - if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
| 632 | - return; |
|
| 633 | - } |
|
| 634 | - $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
| 635 | - //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 636 | - if (empty($this->_cpt_object)) { |
|
| 637 | - $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
| 638 | - $this->page_slug, $this->_req_action, get_class($this)); |
|
| 639 | - throw new EE_Error($msg); |
|
| 640 | - } |
|
| 641 | - if ($this->_cpt_route) { |
|
| 642 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 643 | - $this->_set_model_object($id); |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 651 | - * |
|
| 652 | - * @access protected |
|
| 653 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 654 | - * @param bool $ignore_route_check |
|
| 655 | - */ |
|
| 656 | - protected function _set_model_object($id = null, $ignore_route_check = false) |
|
| 657 | - { |
|
| 658 | - $model = null; |
|
| 659 | - if ( |
|
| 660 | - empty($this->_cpt_model_names) |
|
| 661 | - || ( |
|
| 662 | - ! $ignore_route_check |
|
| 663 | - && ! isset($this->_cpt_routes[$this->_req_action]) |
|
| 664 | - ) || ( |
|
| 665 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 666 | - && $this->_cpt_model_obj->ID() === $id |
|
| 667 | - ) |
|
| 668 | - ) { |
|
| 669 | - //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 670 | - return; |
|
| 671 | - } |
|
| 672 | - //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
| 673 | - if ($ignore_route_check) { |
|
| 674 | - $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
| 675 | - $post_type = get_post_type($id); |
|
| 676 | - if (isset($model_names[$post_type])) { |
|
| 677 | - $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
| 678 | - } |
|
| 679 | - } else { |
|
| 680 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
| 681 | - } |
|
| 682 | - if ($model instanceof EEM_Base) { |
|
| 683 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 684 | - } |
|
| 685 | - do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object'); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - /** |
|
| 691 | - * admin_init_global |
|
| 692 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
| 693 | - * This method executes for ALL EE Admin pages. |
|
| 694 | - * |
|
| 695 | - * @access public |
|
| 696 | - * @return void |
|
| 697 | - */ |
|
| 698 | - public function admin_init_global() |
|
| 699 | - { |
|
| 700 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
| 701 | - //its possible this is a new save so let's catch that instead |
|
| 702 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
| 703 | - $post_type = $post ? $post->post_type : false; |
|
| 704 | - $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] |
|
| 705 | - : 'shouldneverwork'; |
|
| 706 | - $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] |
|
| 707 | - : ''; |
|
| 708 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
| 709 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
| 710 | - if ($post_type === $route_to_check) { |
|
| 711 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
| 712 | - } |
|
| 713 | - //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 714 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 715 | - if ( ! empty($revision)) { |
|
| 716 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
| 717 | - //doing a restore? |
|
| 718 | - if ( ! empty($action) && $action == 'restore') { |
|
| 719 | - //get post for revision |
|
| 720 | - $rev_post = get_post($revision); |
|
| 721 | - $rev_parent = get_post($rev_post->post_parent); |
|
| 722 | - //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 723 | - if ($rev_parent && $rev_parent->post_type == $this->page_slug) { |
|
| 724 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
| 725 | - //restores of revisions |
|
| 726 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 731 | - if ($post_type && $post_type === $route_to_check) { |
|
| 732 | - //$post_id, $post |
|
| 733 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
| 734 | - //$post_id |
|
| 735 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
| 736 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
| 737 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
| 738 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * Callback for the WordPress trashed_post hook. |
|
| 746 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 747 | - * |
|
| 748 | - * @param int $post_id |
|
| 749 | - */ |
|
| 750 | - public function before_trash_cpt_item($post_id) |
|
| 751 | - { |
|
| 752 | - $this->_set_model_object($post_id, true); |
|
| 753 | - //if our cpt object isn't existent then get out immediately. |
|
| 754 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 755 | - return; |
|
| 756 | - } |
|
| 757 | - $this->trash_cpt_item($post_id); |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - |
|
| 762 | - /** |
|
| 763 | - * Callback for the WordPress untrashed_post hook. |
|
| 764 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 765 | - * |
|
| 766 | - * @param $post_id |
|
| 767 | - */ |
|
| 768 | - public function before_restore_cpt_item($post_id) |
|
| 769 | - { |
|
| 770 | - $this->_set_model_object($post_id, true); |
|
| 771 | - //if our cpt object isn't existent then get out immediately. |
|
| 772 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 773 | - return; |
|
| 774 | - } |
|
| 775 | - $this->restore_cpt_item($post_id); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - /** |
|
| 781 | - * Callback for the WordPress after_delete_post hook. |
|
| 782 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 783 | - * |
|
| 784 | - * @param $post_id |
|
| 785 | - */ |
|
| 786 | - public function before_delete_cpt_item($post_id) |
|
| 787 | - { |
|
| 788 | - $this->_set_model_object($post_id, true); |
|
| 789 | - //if our cpt object isn't existent then get out immediately. |
|
| 790 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 791 | - return; |
|
| 792 | - } |
|
| 793 | - $this->delete_cpt_item($post_id); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 800 | - * accordingly. |
|
| 801 | - * |
|
| 802 | - * @access public |
|
| 803 | - * @throws EE_Error |
|
| 804 | - * @return void |
|
| 805 | - */ |
|
| 806 | - public function verify_cpt_object() |
|
| 807 | - { |
|
| 808 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 809 | - // verify event object |
|
| 810 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 811 | - throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 812 | - 'event_espresso'), $label)); |
|
| 813 | - } |
|
| 814 | - //if auto-draft then throw an error |
|
| 815 | - if ($this->_cpt_model_obj->get('status') == 'auto-draft') { |
|
| 816 | - EE_Error::overwrite_errors(); |
|
| 817 | - EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
| 818 | - $label), __FILE__, __FUNCTION__, __LINE__); |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * admin_footer_scripts_global |
|
| 826 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 827 | - * will apply on ALL EE_Admin pages. |
|
| 828 | - * |
|
| 829 | - * @access public |
|
| 830 | - * @return void |
|
| 831 | - */ |
|
| 832 | - public function admin_footer_scripts_global() |
|
| 833 | - { |
|
| 834 | - $this->_add_admin_page_ajax_loading_img(); |
|
| 835 | - $this->_add_admin_page_overlay(); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * add in any global scripts for cpt routes |
|
| 842 | - * |
|
| 843 | - * @return void |
|
| 844 | - */ |
|
| 845 | - public function load_global_scripts_styles() |
|
| 846 | - { |
|
| 847 | - parent::load_global_scripts_styles(); |
|
| 848 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 849 | - //setup custom post status object for localize script but only if we've got a cpt object |
|
| 850 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 851 | - if ( ! empty($statuses)) { |
|
| 852 | - //get ALL statuses! |
|
| 853 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 854 | - //setup object |
|
| 855 | - $ee_cpt_statuses = array(); |
|
| 856 | - foreach ($statuses as $status => $label) { |
|
| 857 | - $ee_cpt_statuses[$status] = array( |
|
| 858 | - 'label' => $label, |
|
| 859 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
| 860 | - ); |
|
| 861 | - } |
|
| 862 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - /** |
|
| 870 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 871 | - * insert/updates |
|
| 872 | - * |
|
| 873 | - * @param int $post_id ID of post being updated |
|
| 874 | - * @param WP_Post $post Post object from WP |
|
| 875 | - * @param bool $update Whether this is an update or a new save. |
|
| 876 | - * @return void |
|
| 877 | - */ |
|
| 878 | - public function insert_update($post_id, $post, $update) |
|
| 879 | - { |
|
| 880 | - //make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 881 | - if ( |
|
| 882 | - isset($this->_req_data['action']) |
|
| 883 | - && ( |
|
| 884 | - $this->_req_data['action'] == 'restore' |
|
| 885 | - || $this->_req_data['action'] == 'trash' |
|
| 886 | - ) |
|
| 887 | - ) { |
|
| 888 | - return; |
|
| 889 | - } |
|
| 890 | - $this->_set_model_object($post_id, true); |
|
| 891 | - //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 892 | - if ($update |
|
| 893 | - && ( |
|
| 894 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 895 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
| 896 | - ) |
|
| 897 | - ) { |
|
| 898 | - return; |
|
| 899 | - } |
|
| 900 | - //check for autosave and update our req_data property accordingly. |
|
| 901 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
| 479 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
| 480 | + * |
|
| 481 | + * @param string $return the current html |
|
| 482 | + * @param int $id the post id for the page |
|
| 483 | + * @param string $new_title What the title is |
|
| 484 | + * @param string $new_slug what the slug is |
|
| 485 | + * @return string The new html string for the permalink area |
|
| 486 | + */ |
|
| 487 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
| 488 | + { |
|
| 489 | + $post = get_post($id); |
|
| 490 | + if ('publish' != get_post_status($post)) { |
|
| 491 | + //include shims for the `get_preview_post_link` function |
|
| 492 | + require_once( EE_CORE . 'wordpress-shims.php' ); |
|
| 493 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
| 494 | + . get_preview_post_link($id) |
|
| 495 | + . '" class="button button-small">' |
|
| 496 | + . __('Preview', 'event_espresso') |
|
| 497 | + . '</a></span>' |
|
| 498 | + . "\n"; |
|
| 499 | + } |
|
| 500 | + return $return; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
| 507 | + * |
|
| 508 | + * @return string html for dropdown |
|
| 509 | + */ |
|
| 510 | + public function custom_post_stati_dropdown() |
|
| 511 | + { |
|
| 512 | + |
|
| 513 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 514 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
| 515 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
| 516 | + : ''; |
|
| 517 | + $template_args = array( |
|
| 518 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
| 519 | + 'statuses' => $statuses, |
|
| 520 | + 'cur_status_label' => $cur_status_label, |
|
| 521 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
| 522 | + ); |
|
| 523 | + //we'll add a trash post status (WP doesn't add one for some reason) |
|
| 524 | + if ($this->_cpt_model_obj->status() == 'trash') { |
|
| 525 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
| 526 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
| 527 | + $template_args['statuses'] = $statuses; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 531 | + EEH_Template::display_template($template, $template_args); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + public function setup_autosave_hooks() |
|
| 537 | + { |
|
| 538 | + $this->_set_autosave_containers(); |
|
| 539 | + $this->_load_autosave_scripts_styles(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
| 546 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
| 547 | + * for the nonce in here, but then this method looks for two things: |
|
| 548 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
| 549 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
| 550 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
| 551 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
| 552 | + * template args. |
|
| 553 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
| 554 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
| 555 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
| 556 | + * $this->_template_args['data']['items'] = array( |
|
| 557 | + * 'event-datetime-ids' => '1,2,3'; |
|
| 558 | + * ); |
|
| 559 | + * Keep in mind the following things: |
|
| 560 | + * - "where" index is for the input with the id as that string. |
|
| 561 | + * - "what" index is what will be used for the value of that input. |
|
| 562 | + * |
|
| 563 | + * @return void |
|
| 564 | + */ |
|
| 565 | + public function do_extra_autosave_stuff() |
|
| 566 | + { |
|
| 567 | + //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
| 568 | + $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null; |
|
| 569 | + $this->_verify_nonce($nonce, 'autosave'); |
|
| 570 | + //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
| 571 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
| 572 | + define('DOING_AUTOSAVE', true); |
|
| 573 | + } |
|
| 574 | + //if we made it here then the nonce checked out. Let's run our methods and actions |
|
| 575 | + if (method_exists($this, '_ee_autosave_' . $this->_current_view)) { |
|
| 576 | + call_user_func(array($this, '_ee_autosave_' . $this->_current_view)); |
|
| 577 | + } else { |
|
| 578 | + $this->_template_args['success'] = true; |
|
| 579 | + } |
|
| 580 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
| 581 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 582 | + //now let's return json |
|
| 583 | + $this->_return_json(); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
| 590 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
| 591 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
| 592 | + * |
|
| 593 | + * @access protected |
|
| 594 | + * @throws EE_Error |
|
| 595 | + * @return void |
|
| 596 | + */ |
|
| 597 | + protected function _extend_page_config_for_cpt() |
|
| 598 | + { |
|
| 599 | + //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
| 600 | + if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) { |
|
| 601 | + return; |
|
| 602 | + } |
|
| 603 | + //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
| 604 | + if ( ! empty($this->_cpt_object)) { |
|
| 605 | + $this->_page_routes = array_merge(array( |
|
| 606 | + 'create_new' => '_create_new_cpt_item', |
|
| 607 | + 'edit' => '_edit_cpt_item', |
|
| 608 | + ), $this->_page_routes); |
|
| 609 | + $this->_page_config = array_merge(array( |
|
| 610 | + 'create_new' => array( |
|
| 611 | + 'nav' => array( |
|
| 612 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
| 613 | + 'order' => 5, |
|
| 614 | + ), |
|
| 615 | + 'require_nonce' => false, |
|
| 616 | + ), |
|
| 617 | + 'edit' => array( |
|
| 618 | + 'nav' => array( |
|
| 619 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
| 620 | + 'order' => 5, |
|
| 621 | + 'persistent' => false, |
|
| 622 | + 'url' => '', |
|
| 623 | + ), |
|
| 624 | + 'require_nonce' => false, |
|
| 625 | + ), |
|
| 626 | + ), |
|
| 627 | + $this->_page_config |
|
| 628 | + ); |
|
| 629 | + } |
|
| 630 | + //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
| 631 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
| 632 | + return; |
|
| 633 | + } |
|
| 634 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
| 635 | + //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
| 636 | + if (empty($this->_cpt_object)) { |
|
| 637 | + $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
| 638 | + $this->page_slug, $this->_req_action, get_class($this)); |
|
| 639 | + throw new EE_Error($msg); |
|
| 640 | + } |
|
| 641 | + if ($this->_cpt_route) { |
|
| 642 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 643 | + $this->_set_model_object($id); |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
| 651 | + * |
|
| 652 | + * @access protected |
|
| 653 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
| 654 | + * @param bool $ignore_route_check |
|
| 655 | + */ |
|
| 656 | + protected function _set_model_object($id = null, $ignore_route_check = false) |
|
| 657 | + { |
|
| 658 | + $model = null; |
|
| 659 | + if ( |
|
| 660 | + empty($this->_cpt_model_names) |
|
| 661 | + || ( |
|
| 662 | + ! $ignore_route_check |
|
| 663 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
| 664 | + ) || ( |
|
| 665 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 666 | + && $this->_cpt_model_obj->ID() === $id |
|
| 667 | + ) |
|
| 668 | + ) { |
|
| 669 | + //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
| 670 | + return; |
|
| 671 | + } |
|
| 672 | + //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
| 673 | + if ($ignore_route_check) { |
|
| 674 | + $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
| 675 | + $post_type = get_post_type($id); |
|
| 676 | + if (isset($model_names[$post_type])) { |
|
| 677 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
| 678 | + } |
|
| 679 | + } else { |
|
| 680 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
| 681 | + } |
|
| 682 | + if ($model instanceof EEM_Base) { |
|
| 683 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
| 684 | + } |
|
| 685 | + do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object'); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + /** |
|
| 691 | + * admin_init_global |
|
| 692 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
| 693 | + * This method executes for ALL EE Admin pages. |
|
| 694 | + * |
|
| 695 | + * @access public |
|
| 696 | + * @return void |
|
| 697 | + */ |
|
| 698 | + public function admin_init_global() |
|
| 699 | + { |
|
| 700 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
| 701 | + //its possible this is a new save so let's catch that instead |
|
| 702 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
| 703 | + $post_type = $post ? $post->post_type : false; |
|
| 704 | + $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] |
|
| 705 | + : 'shouldneverwork'; |
|
| 706 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] |
|
| 707 | + : ''; |
|
| 708 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
| 709 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
| 710 | + if ($post_type === $route_to_check) { |
|
| 711 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
| 712 | + } |
|
| 713 | + //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
| 714 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 715 | + if ( ! empty($revision)) { |
|
| 716 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
| 717 | + //doing a restore? |
|
| 718 | + if ( ! empty($action) && $action == 'restore') { |
|
| 719 | + //get post for revision |
|
| 720 | + $rev_post = get_post($revision); |
|
| 721 | + $rev_parent = get_post($rev_post->post_parent); |
|
| 722 | + //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
| 723 | + if ($rev_parent && $rev_parent->post_type == $this->page_slug) { |
|
| 724 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
| 725 | + //restores of revisions |
|
| 726 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
| 731 | + if ($post_type && $post_type === $route_to_check) { |
|
| 732 | + //$post_id, $post |
|
| 733 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
| 734 | + //$post_id |
|
| 735 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
| 736 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
| 737 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
| 738 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * Callback for the WordPress trashed_post hook. |
|
| 746 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
| 747 | + * |
|
| 748 | + * @param int $post_id |
|
| 749 | + */ |
|
| 750 | + public function before_trash_cpt_item($post_id) |
|
| 751 | + { |
|
| 752 | + $this->_set_model_object($post_id, true); |
|
| 753 | + //if our cpt object isn't existent then get out immediately. |
|
| 754 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 755 | + return; |
|
| 756 | + } |
|
| 757 | + $this->trash_cpt_item($post_id); |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + |
|
| 762 | + /** |
|
| 763 | + * Callback for the WordPress untrashed_post hook. |
|
| 764 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
| 765 | + * |
|
| 766 | + * @param $post_id |
|
| 767 | + */ |
|
| 768 | + public function before_restore_cpt_item($post_id) |
|
| 769 | + { |
|
| 770 | + $this->_set_model_object($post_id, true); |
|
| 771 | + //if our cpt object isn't existent then get out immediately. |
|
| 772 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 773 | + return; |
|
| 774 | + } |
|
| 775 | + $this->restore_cpt_item($post_id); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + /** |
|
| 781 | + * Callback for the WordPress after_delete_post hook. |
|
| 782 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
| 783 | + * |
|
| 784 | + * @param $post_id |
|
| 785 | + */ |
|
| 786 | + public function before_delete_cpt_item($post_id) |
|
| 787 | + { |
|
| 788 | + $this->_set_model_object($post_id, true); |
|
| 789 | + //if our cpt object isn't existent then get out immediately. |
|
| 790 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
| 791 | + return; |
|
| 792 | + } |
|
| 793 | + $this->delete_cpt_item($post_id); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
| 800 | + * accordingly. |
|
| 801 | + * |
|
| 802 | + * @access public |
|
| 803 | + * @throws EE_Error |
|
| 804 | + * @return void |
|
| 805 | + */ |
|
| 806 | + public function verify_cpt_object() |
|
| 807 | + { |
|
| 808 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
| 809 | + // verify event object |
|
| 810 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 811 | + throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
| 812 | + 'event_espresso'), $label)); |
|
| 813 | + } |
|
| 814 | + //if auto-draft then throw an error |
|
| 815 | + if ($this->_cpt_model_obj->get('status') == 'auto-draft') { |
|
| 816 | + EE_Error::overwrite_errors(); |
|
| 817 | + EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
| 818 | + $label), __FILE__, __FUNCTION__, __LINE__); |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * admin_footer_scripts_global |
|
| 826 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
| 827 | + * will apply on ALL EE_Admin pages. |
|
| 828 | + * |
|
| 829 | + * @access public |
|
| 830 | + * @return void |
|
| 831 | + */ |
|
| 832 | + public function admin_footer_scripts_global() |
|
| 833 | + { |
|
| 834 | + $this->_add_admin_page_ajax_loading_img(); |
|
| 835 | + $this->_add_admin_page_overlay(); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * add in any global scripts for cpt routes |
|
| 842 | + * |
|
| 843 | + * @return void |
|
| 844 | + */ |
|
| 845 | + public function load_global_scripts_styles() |
|
| 846 | + { |
|
| 847 | + parent::load_global_scripts_styles(); |
|
| 848 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 849 | + //setup custom post status object for localize script but only if we've got a cpt object |
|
| 850 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
| 851 | + if ( ! empty($statuses)) { |
|
| 852 | + //get ALL statuses! |
|
| 853 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
| 854 | + //setup object |
|
| 855 | + $ee_cpt_statuses = array(); |
|
| 856 | + foreach ($statuses as $status => $label) { |
|
| 857 | + $ee_cpt_statuses[$status] = array( |
|
| 858 | + 'label' => $label, |
|
| 859 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
| 860 | + ); |
|
| 861 | + } |
|
| 862 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + /** |
|
| 870 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
| 871 | + * insert/updates |
|
| 872 | + * |
|
| 873 | + * @param int $post_id ID of post being updated |
|
| 874 | + * @param WP_Post $post Post object from WP |
|
| 875 | + * @param bool $update Whether this is an update or a new save. |
|
| 876 | + * @return void |
|
| 877 | + */ |
|
| 878 | + public function insert_update($post_id, $post, $update) |
|
| 879 | + { |
|
| 880 | + //make sure that if this is a revision OR trash action that we don't do any updates! |
|
| 881 | + if ( |
|
| 882 | + isset($this->_req_data['action']) |
|
| 883 | + && ( |
|
| 884 | + $this->_req_data['action'] == 'restore' |
|
| 885 | + || $this->_req_data['action'] == 'trash' |
|
| 886 | + ) |
|
| 887 | + ) { |
|
| 888 | + return; |
|
| 889 | + } |
|
| 890 | + $this->_set_model_object($post_id, true); |
|
| 891 | + //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
| 892 | + if ($update |
|
| 893 | + && ( |
|
| 894 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
| 895 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
| 896 | + ) |
|
| 897 | + ) { |
|
| 898 | + return; |
|
| 899 | + } |
|
| 900 | + //check for autosave and update our req_data property accordingly. |
|
| 901 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
| 902 | 902 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
| 903 | 903 | |
| 904 | 904 | foreach ( (array) $values as $key => $value ) { |
@@ -908,524 +908,524 @@ discard block |
||
| 908 | 908 | |
| 909 | 909 | }/**/ //TODO reactivate after autosave is implemented in 4.2 |
| 910 | 910 | |
| 911 | - //take care of updating any selected page_template IF this cpt supports it. |
|
| 912 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
| 913 | - //wp version aware. |
|
| 914 | - if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
| 915 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
| 916 | - } else { |
|
| 917 | - $post->page_template = $this->_req_data['page_template']; |
|
| 918 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 919 | - } |
|
| 920 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
| 921 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 922 | - } else { |
|
| 923 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 927 | - return; |
|
| 928 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 929 | - $this->_insert_update_cpt_item($post_id, $post); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 936 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 937 | - * so we don't have to check for our CPT. |
|
| 938 | - * |
|
| 939 | - * @param int $post_id ID of the post |
|
| 940 | - * @return void |
|
| 941 | - */ |
|
| 942 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
| 943 | - { |
|
| 944 | - //only do this if we're actually processing one of our CPTs |
|
| 945 | - //if our cpt object isn't existent then get out immediately. |
|
| 946 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 947 | - return; |
|
| 948 | - } |
|
| 949 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 950 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 951 | - //our cpts may have comments so let's take care of that too |
|
| 952 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 959 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 960 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 961 | - * |
|
| 962 | - * @param int $post_id ID of cpt item |
|
| 963 | - * @param int $revision_id ID of revision being restored |
|
| 964 | - * @return void |
|
| 965 | - */ |
|
| 966 | - public function restore_revision($post_id, $revision_id) |
|
| 967 | - { |
|
| 968 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
| 969 | - //global action |
|
| 970 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 971 | - //class specific action so you can limit hooking into a specific page. |
|
| 972 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * @see restore_revision() for details |
|
| 979 | - * @param int $post_id ID of cpt item |
|
| 980 | - * @param int $revision_id ID of revision for item |
|
| 981 | - * @return void |
|
| 982 | - */ |
|
| 983 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
| 984 | - |
|
| 985 | - |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 989 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 990 | - * To fix we have to reset the current_screen using the page_slug |
|
| 991 | - * (which is identical - or should be - to our registered_post_type id.) |
|
| 992 | - * Also, since the core WP file loads the admin_header.php for WP |
|
| 993 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 994 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 995 | - * |
|
| 996 | - * @return void |
|
| 997 | - */ |
|
| 998 | - public function modify_current_screen() |
|
| 999 | - { |
|
| 1000 | - //ONLY do this if the current page_route IS a cpt route |
|
| 1001 | - if ( ! $this->_cpt_route) { |
|
| 1002 | - return; |
|
| 1003 | - } |
|
| 1004 | - //routing things REALLY early b/c this is a cpt admin page |
|
| 1005 | - set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
| 1006 | - $this->_current_screen = get_current_screen(); |
|
| 1007 | - $this->_current_screen->base = 'event-espresso'; |
|
| 1008 | - $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
| 1009 | - /*try { |
|
| 911 | + //take care of updating any selected page_template IF this cpt supports it. |
|
| 912 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
| 913 | + //wp version aware. |
|
| 914 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
| 915 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
| 916 | + } else { |
|
| 917 | + $post->page_template = $this->_req_data['page_template']; |
|
| 918 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
| 919 | + } |
|
| 920 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
| 921 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 922 | + } else { |
|
| 923 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
| 927 | + return; |
|
| 928 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
| 929 | + $this->_insert_update_cpt_item($post_id, $post); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
| 936 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
| 937 | + * so we don't have to check for our CPT. |
|
| 938 | + * |
|
| 939 | + * @param int $post_id ID of the post |
|
| 940 | + * @return void |
|
| 941 | + */ |
|
| 942 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
| 943 | + { |
|
| 944 | + //only do this if we're actually processing one of our CPTs |
|
| 945 | + //if our cpt object isn't existent then get out immediately. |
|
| 946 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
| 947 | + return; |
|
| 948 | + } |
|
| 949 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
| 950 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
| 951 | + //our cpts may have comments so let's take care of that too |
|
| 952 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
| 959 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
| 960 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
| 961 | + * |
|
| 962 | + * @param int $post_id ID of cpt item |
|
| 963 | + * @param int $revision_id ID of revision being restored |
|
| 964 | + * @return void |
|
| 965 | + */ |
|
| 966 | + public function restore_revision($post_id, $revision_id) |
|
| 967 | + { |
|
| 968 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
| 969 | + //global action |
|
| 970 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
| 971 | + //class specific action so you can limit hooking into a specific page. |
|
| 972 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * @see restore_revision() for details |
|
| 979 | + * @param int $post_id ID of cpt item |
|
| 980 | + * @param int $revision_id ID of revision for item |
|
| 981 | + * @return void |
|
| 982 | + */ |
|
| 983 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
| 984 | + |
|
| 985 | + |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
| 989 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
| 990 | + * To fix we have to reset the current_screen using the page_slug |
|
| 991 | + * (which is identical - or should be - to our registered_post_type id.) |
|
| 992 | + * Also, since the core WP file loads the admin_header.php for WP |
|
| 993 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
| 994 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
| 995 | + * |
|
| 996 | + * @return void |
|
| 997 | + */ |
|
| 998 | + public function modify_current_screen() |
|
| 999 | + { |
|
| 1000 | + //ONLY do this if the current page_route IS a cpt route |
|
| 1001 | + if ( ! $this->_cpt_route) { |
|
| 1002 | + return; |
|
| 1003 | + } |
|
| 1004 | + //routing things REALLY early b/c this is a cpt admin page |
|
| 1005 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
| 1006 | + $this->_current_screen = get_current_screen(); |
|
| 1007 | + $this->_current_screen->base = 'event-espresso'; |
|
| 1008 | + $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
| 1009 | + /*try { |
|
| 1010 | 1010 | $this->_route_admin_request(); |
| 1011 | 1011 | } catch ( EE_Error $e ) { |
| 1012 | 1012 | $e->get_error(); |
| 1013 | 1013 | }/**/ |
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1020 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1021 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1022 | - * default to be. |
|
| 1023 | - * |
|
| 1024 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
| 1025 | - * @return string |
|
| 1026 | - */ |
|
| 1027 | - public function add_custom_editor_default_title($title) |
|
| 1028 | - { |
|
| 1029 | - return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
| 1030 | - ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
| 1031 | - : $title; |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - /** |
|
| 1037 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1038 | - * |
|
| 1039 | - * @param string $shortlink The already generated shortlink |
|
| 1040 | - * @param int $id Post ID for this item |
|
| 1041 | - * @param string $context The context for the link |
|
| 1042 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
| 1043 | - * @return string |
|
| 1044 | - */ |
|
| 1045 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
| 1046 | - { |
|
| 1047 | - if ( ! empty($id) && '' != get_option('permalink_structure')) { |
|
| 1048 | - $post = get_post($id); |
|
| 1049 | - if (isset($post->post_type) && $this->page_slug == $post->post_type) { |
|
| 1050 | - $shortlink = home_url('?p=' . $post->ID); |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - return $shortlink; |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - |
|
| 1058 | - /** |
|
| 1059 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1060 | - * already run in modify_current_screen()) |
|
| 1061 | - * |
|
| 1062 | - * @return void |
|
| 1063 | - */ |
|
| 1064 | - public function route_admin_request() |
|
| 1065 | - { |
|
| 1066 | - if ($this->_cpt_route) { |
|
| 1067 | - return; |
|
| 1068 | - } |
|
| 1069 | - try { |
|
| 1070 | - $this->_route_admin_request(); |
|
| 1071 | - } catch (EE_Error $e) { |
|
| 1072 | - $e->get_error(); |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1080 | - * |
|
| 1081 | - * @return string html |
|
| 1082 | - */ |
|
| 1083 | - public function cpt_post_form_hidden_input() |
|
| 1084 | - { |
|
| 1085 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
| 1086 | - //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1087 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
| 1088 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
| 1089 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
| 1090 | - echo '</div>'; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1097 | - * |
|
| 1098 | - * @param string $location Original location url |
|
| 1099 | - * @param int $status Status for http header |
|
| 1100 | - * @return string new (or original) url to redirect to. |
|
| 1101 | - */ |
|
| 1102 | - public function revision_redirect($location, $status) |
|
| 1103 | - { |
|
| 1104 | - //get revision |
|
| 1105 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 1106 | - //can't do anything without revision so let's get out if not present |
|
| 1107 | - if (empty($rev_id)) { |
|
| 1108 | - return $location; |
|
| 1109 | - } |
|
| 1110 | - //get rev_post_data |
|
| 1111 | - $rev = get_post($rev_id); |
|
| 1112 | - $admin_url = $this->_admin_base_url; |
|
| 1113 | - $query_args = array( |
|
| 1114 | - 'action' => 'edit', |
|
| 1115 | - 'post' => $rev->post_parent, |
|
| 1116 | - 'revision' => $rev_id, |
|
| 1117 | - 'message' => 5, |
|
| 1118 | - ); |
|
| 1119 | - $this->_process_notices($query_args, true); |
|
| 1120 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1127 | - * |
|
| 1128 | - * @param string $link the original generated link |
|
| 1129 | - * @param int $id post id |
|
| 1130 | - * @param string $context optional, defaults to display. How to write the '&' |
|
| 1131 | - * @return string the link |
|
| 1132 | - */ |
|
| 1133 | - public function modify_edit_post_link($link, $id, $context) |
|
| 1134 | - { |
|
| 1135 | - $post = get_post($id); |
|
| 1136 | - if ( ! isset($this->_req_data['action']) |
|
| 1137 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1138 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
| 1139 | - ) { |
|
| 1140 | - return $link; |
|
| 1141 | - } |
|
| 1142 | - $query_args = array( |
|
| 1143 | - 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
| 1144 | - ? $this->_cpt_edit_routes[$post->post_type] |
|
| 1145 | - : 'edit', |
|
| 1146 | - 'post' => $id, |
|
| 1147 | - ); |
|
| 1148 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1154 | - * our routes. |
|
| 1155 | - * |
|
| 1156 | - * @param string $delete_link original delete link |
|
| 1157 | - * @param int $post_id id of cpt object |
|
| 1158 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
| 1159 | - * @return string new delete link |
|
| 1160 | - * @throws EE_Error |
|
| 1161 | - */ |
|
| 1162 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
| 1163 | - { |
|
| 1164 | - $post = get_post($post_id); |
|
| 1165 | - if ( ! isset($this->_req_data['action']) |
|
| 1166 | - || (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1167 | - && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]) |
|
| 1168 | - ) { |
|
| 1169 | - return $delete_link; |
|
| 1170 | - } |
|
| 1171 | - $this->_set_model_object($this->_req_data['post'], true); |
|
| 1172 | - //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1173 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1174 | - |
|
| 1175 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1176 | - array( |
|
| 1177 | - 'page' => $this->_req_data['page'], |
|
| 1178 | - 'action' => $action, |
|
| 1179 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
| 1180 | - => $this->_req_data['post'] |
|
| 1181 | - ), |
|
| 1182 | - admin_url() |
|
| 1183 | - ); |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - |
|
| 1187 | - |
|
| 1188 | - /** |
|
| 1189 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1190 | - * so that we can hijack the default redirect locations for wp custom post types |
|
| 1191 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1192 | - * |
|
| 1193 | - * @param string $location This is the incoming currently set redirect location |
|
| 1194 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1195 | - * @return string the new location to redirect to |
|
| 1196 | - */ |
|
| 1197 | - public function cpt_post_location_redirect($location, $post_id) |
|
| 1198 | - { |
|
| 1199 | - //we DO have a match so let's setup the url |
|
| 1200 | - //we have to get the post to determine our route |
|
| 1201 | - $post = get_post($post_id); |
|
| 1202 | - $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
| 1203 | - //shared query_args |
|
| 1204 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
| 1205 | - $admin_url = $this->_admin_base_url; |
|
| 1206 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
| 1207 | - $status = get_post_status($post_id); |
|
| 1208 | - if (isset($this->_req_data['publish'])) { |
|
| 1209 | - switch ($status) { |
|
| 1210 | - case 'pending': |
|
| 1211 | - $message = 8; |
|
| 1212 | - break; |
|
| 1213 | - case 'future': |
|
| 1214 | - $message = 9; |
|
| 1215 | - break; |
|
| 1216 | - default: |
|
| 1217 | - $message = 6; |
|
| 1218 | - } |
|
| 1219 | - } else { |
|
| 1220 | - $message = 'draft' == $status ? 10 : 1; |
|
| 1221 | - } |
|
| 1222 | - } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
| 1223 | - $message = 2; |
|
| 1224 | - // $append = '#postcustom'; |
|
| 1225 | - } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
| 1226 | - $message = 3; |
|
| 1227 | - // $append = '#postcustom'; |
|
| 1228 | - } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') { |
|
| 1229 | - $message = 7; |
|
| 1230 | - } else { |
|
| 1231 | - $message = 4; |
|
| 1232 | - } |
|
| 1233 | - //change the message if the post type is not viewable on the frontend |
|
| 1234 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1235 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1236 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
| 1237 | - $this->_process_notices($query_args, true); |
|
| 1238 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1239 | - } |
|
| 1240 | - |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * This method is called to inject nav tabs on core WP cpt pages |
|
| 1245 | - * |
|
| 1246 | - * @access public |
|
| 1247 | - * @return string html |
|
| 1248 | - */ |
|
| 1249 | - public function inject_nav_tabs() |
|
| 1250 | - { |
|
| 1251 | - //can we hijack and insert the nav_tabs? |
|
| 1252 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
| 1253 | - //first close off existing form tag |
|
| 1254 | - $html = '>'; |
|
| 1255 | - $html .= $nav_tabs; |
|
| 1256 | - //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
| 1257 | - $html .= '<span></span'; |
|
| 1258 | - echo $html; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - |
|
| 1263 | - /** |
|
| 1264 | - * This just sets up the post update messages when an update form is loaded |
|
| 1265 | - * |
|
| 1266 | - * @access public |
|
| 1267 | - * @param array $messages the original messages array |
|
| 1268 | - * @return array the new messages array |
|
| 1269 | - */ |
|
| 1270 | - public function post_update_messages($messages) |
|
| 1271 | - { |
|
| 1272 | - global $post; |
|
| 1273 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1274 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1275 | - // $post_type = $post ? $post->post_type : false; |
|
| 1276 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
| 1020 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
| 1021 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
| 1022 | + * default to be. |
|
| 1023 | + * |
|
| 1024 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
| 1025 | + * @return string |
|
| 1026 | + */ |
|
| 1027 | + public function add_custom_editor_default_title($title) |
|
| 1028 | + { |
|
| 1029 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
| 1030 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
| 1031 | + : $title; |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + /** |
|
| 1037 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
| 1038 | + * |
|
| 1039 | + * @param string $shortlink The already generated shortlink |
|
| 1040 | + * @param int $id Post ID for this item |
|
| 1041 | + * @param string $context The context for the link |
|
| 1042 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
| 1043 | + * @return string |
|
| 1044 | + */ |
|
| 1045 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
| 1046 | + { |
|
| 1047 | + if ( ! empty($id) && '' != get_option('permalink_structure')) { |
|
| 1048 | + $post = get_post($id); |
|
| 1049 | + if (isset($post->post_type) && $this->page_slug == $post->post_type) { |
|
| 1050 | + $shortlink = home_url('?p=' . $post->ID); |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + return $shortlink; |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + |
|
| 1058 | + /** |
|
| 1059 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
| 1060 | + * already run in modify_current_screen()) |
|
| 1061 | + * |
|
| 1062 | + * @return void |
|
| 1063 | + */ |
|
| 1064 | + public function route_admin_request() |
|
| 1065 | + { |
|
| 1066 | + if ($this->_cpt_route) { |
|
| 1067 | + return; |
|
| 1068 | + } |
|
| 1069 | + try { |
|
| 1070 | + $this->_route_admin_request(); |
|
| 1071 | + } catch (EE_Error $e) { |
|
| 1072 | + $e->get_error(); |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
| 1080 | + * |
|
| 1081 | + * @return string html |
|
| 1082 | + */ |
|
| 1083 | + public function cpt_post_form_hidden_input() |
|
| 1084 | + { |
|
| 1085 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
| 1086 | + //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
| 1087 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
| 1088 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
| 1089 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
| 1090 | + echo '</div>'; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
| 1097 | + * |
|
| 1098 | + * @param string $location Original location url |
|
| 1099 | + * @param int $status Status for http header |
|
| 1100 | + * @return string new (or original) url to redirect to. |
|
| 1101 | + */ |
|
| 1102 | + public function revision_redirect($location, $status) |
|
| 1103 | + { |
|
| 1104 | + //get revision |
|
| 1105 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
| 1106 | + //can't do anything without revision so let's get out if not present |
|
| 1107 | + if (empty($rev_id)) { |
|
| 1108 | + return $location; |
|
| 1109 | + } |
|
| 1110 | + //get rev_post_data |
|
| 1111 | + $rev = get_post($rev_id); |
|
| 1112 | + $admin_url = $this->_admin_base_url; |
|
| 1113 | + $query_args = array( |
|
| 1114 | + 'action' => 'edit', |
|
| 1115 | + 'post' => $rev->post_parent, |
|
| 1116 | + 'revision' => $rev_id, |
|
| 1117 | + 'message' => 5, |
|
| 1118 | + ); |
|
| 1119 | + $this->_process_notices($query_args, true); |
|
| 1120 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
| 1127 | + * |
|
| 1128 | + * @param string $link the original generated link |
|
| 1129 | + * @param int $id post id |
|
| 1130 | + * @param string $context optional, defaults to display. How to write the '&' |
|
| 1131 | + * @return string the link |
|
| 1132 | + */ |
|
| 1133 | + public function modify_edit_post_link($link, $id, $context) |
|
| 1134 | + { |
|
| 1135 | + $post = get_post($id); |
|
| 1136 | + if ( ! isset($this->_req_data['action']) |
|
| 1137 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1138 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
| 1139 | + ) { |
|
| 1140 | + return $link; |
|
| 1141 | + } |
|
| 1142 | + $query_args = array( |
|
| 1143 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
| 1144 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
| 1145 | + : 'edit', |
|
| 1146 | + 'post' => $id, |
|
| 1147 | + ); |
|
| 1148 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
| 1154 | + * our routes. |
|
| 1155 | + * |
|
| 1156 | + * @param string $delete_link original delete link |
|
| 1157 | + * @param int $post_id id of cpt object |
|
| 1158 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
| 1159 | + * @return string new delete link |
|
| 1160 | + * @throws EE_Error |
|
| 1161 | + */ |
|
| 1162 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
| 1163 | + { |
|
| 1164 | + $post = get_post($post_id); |
|
| 1165 | + if ( ! isset($this->_req_data['action']) |
|
| 1166 | + || (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1167 | + && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]) |
|
| 1168 | + ) { |
|
| 1169 | + return $delete_link; |
|
| 1170 | + } |
|
| 1171 | + $this->_set_model_object($this->_req_data['post'], true); |
|
| 1172 | + //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
| 1173 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1174 | + |
|
| 1175 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
| 1176 | + array( |
|
| 1177 | + 'page' => $this->_req_data['page'], |
|
| 1178 | + 'action' => $action, |
|
| 1179 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
| 1180 | + => $this->_req_data['post'] |
|
| 1181 | + ), |
|
| 1182 | + admin_url() |
|
| 1183 | + ); |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + |
|
| 1187 | + |
|
| 1188 | + /** |
|
| 1189 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
| 1190 | + * so that we can hijack the default redirect locations for wp custom post types |
|
| 1191 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
| 1192 | + * |
|
| 1193 | + * @param string $location This is the incoming currently set redirect location |
|
| 1194 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
| 1195 | + * @return string the new location to redirect to |
|
| 1196 | + */ |
|
| 1197 | + public function cpt_post_location_redirect($location, $post_id) |
|
| 1198 | + { |
|
| 1199 | + //we DO have a match so let's setup the url |
|
| 1200 | + //we have to get the post to determine our route |
|
| 1201 | + $post = get_post($post_id); |
|
| 1202 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
| 1203 | + //shared query_args |
|
| 1204 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
| 1205 | + $admin_url = $this->_admin_base_url; |
|
| 1206 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
| 1207 | + $status = get_post_status($post_id); |
|
| 1208 | + if (isset($this->_req_data['publish'])) { |
|
| 1209 | + switch ($status) { |
|
| 1210 | + case 'pending': |
|
| 1211 | + $message = 8; |
|
| 1212 | + break; |
|
| 1213 | + case 'future': |
|
| 1214 | + $message = 9; |
|
| 1215 | + break; |
|
| 1216 | + default: |
|
| 1217 | + $message = 6; |
|
| 1218 | + } |
|
| 1219 | + } else { |
|
| 1220 | + $message = 'draft' == $status ? 10 : 1; |
|
| 1221 | + } |
|
| 1222 | + } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
| 1223 | + $message = 2; |
|
| 1224 | + // $append = '#postcustom'; |
|
| 1225 | + } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
| 1226 | + $message = 3; |
|
| 1227 | + // $append = '#postcustom'; |
|
| 1228 | + } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') { |
|
| 1229 | + $message = 7; |
|
| 1230 | + } else { |
|
| 1231 | + $message = 4; |
|
| 1232 | + } |
|
| 1233 | + //change the message if the post type is not viewable on the frontend |
|
| 1234 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
| 1235 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
| 1236 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
| 1237 | + $this->_process_notices($query_args, true); |
|
| 1238 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
| 1239 | + } |
|
| 1240 | + |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * This method is called to inject nav tabs on core WP cpt pages |
|
| 1245 | + * |
|
| 1246 | + * @access public |
|
| 1247 | + * @return string html |
|
| 1248 | + */ |
|
| 1249 | + public function inject_nav_tabs() |
|
| 1250 | + { |
|
| 1251 | + //can we hijack and insert the nav_tabs? |
|
| 1252 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
| 1253 | + //first close off existing form tag |
|
| 1254 | + $html = '>'; |
|
| 1255 | + $html .= $nav_tabs; |
|
| 1256 | + //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
| 1257 | + $html .= '<span></span'; |
|
| 1258 | + echo $html; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + |
|
| 1263 | + /** |
|
| 1264 | + * This just sets up the post update messages when an update form is loaded |
|
| 1265 | + * |
|
| 1266 | + * @access public |
|
| 1267 | + * @param array $messages the original messages array |
|
| 1268 | + * @return array the new messages array |
|
| 1269 | + */ |
|
| 1270 | + public function post_update_messages($messages) |
|
| 1271 | + { |
|
| 1272 | + global $post; |
|
| 1273 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1274 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
| 1275 | + // $post_type = $post ? $post->post_type : false; |
|
| 1276 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
| 1277 | 1277 | |
| 1278 | 1278 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
| 1279 | - $messages[$post->post_type] = array( |
|
| 1280 | - 0 => '', //Unused. Messages start at index 1. |
|
| 1281 | - 1 => sprintf( |
|
| 1282 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1283 | - $this->_cpt_object->labels->singular_name, |
|
| 1284 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1285 | - '</a>' |
|
| 1286 | - ), |
|
| 1287 | - 2 => __('Custom field updated'), |
|
| 1288 | - 3 => __('Custom field deleted.'), |
|
| 1289 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1290 | - 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
| 1291 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
| 1292 | - : false, |
|
| 1293 | - 6 => sprintf( |
|
| 1294 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1295 | - $this->_cpt_object->labels->singular_name, |
|
| 1296 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1297 | - '</a>' |
|
| 1298 | - ), |
|
| 1299 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1300 | - 8 => sprintf( |
|
| 1301 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1302 | - $this->_cpt_object->labels->singular_name, |
|
| 1303 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1304 | - '</a>' |
|
| 1305 | - ), |
|
| 1306 | - 9 => sprintf( |
|
| 1307 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1308 | - $this->_cpt_object->labels->singular_name, |
|
| 1309 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
| 1310 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1311 | - '</a>' |
|
| 1312 | - ), |
|
| 1313 | - 10 => sprintf( |
|
| 1314 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1315 | - $this->_cpt_object->labels->singular_name, |
|
| 1316 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1317 | - '</a>' |
|
| 1318 | - ), |
|
| 1319 | - ); |
|
| 1320 | - return $messages; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * default method for the 'create_new' route for cpt admin pages. |
|
| 1327 | - * For reference what to include in here, see wp-admin/post-new.php |
|
| 1328 | - * |
|
| 1329 | - * @access protected |
|
| 1330 | - * @return string template for add new cpt form |
|
| 1331 | - */ |
|
| 1332 | - protected function _create_new_cpt_item() |
|
| 1333 | - { |
|
| 1334 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1335 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1336 | - $post_type_object = $this->_cpt_object; |
|
| 1337 | - $title = $post_type_object->labels->add_new_item; |
|
| 1338 | - $editing = true; |
|
| 1339 | - wp_enqueue_script('autosave'); |
|
| 1340 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
| 1341 | - $post_ID = $post->ID; |
|
| 1342 | - $is_IE = $is_IE; |
|
| 1343 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
| 1344 | - //modify the default editor title field with default title. |
|
| 1345 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
| 1346 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - public function add_new_admin_page_global() |
|
| 1352 | - { |
|
| 1353 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
| 1354 | - ?> |
|
| 1279 | + $messages[$post->post_type] = array( |
|
| 1280 | + 0 => '', //Unused. Messages start at index 1. |
|
| 1281 | + 1 => sprintf( |
|
| 1282 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1283 | + $this->_cpt_object->labels->singular_name, |
|
| 1284 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1285 | + '</a>' |
|
| 1286 | + ), |
|
| 1287 | + 2 => __('Custom field updated'), |
|
| 1288 | + 3 => __('Custom field deleted.'), |
|
| 1289 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1290 | + 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
| 1291 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
| 1292 | + : false, |
|
| 1293 | + 6 => sprintf( |
|
| 1294 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
| 1295 | + $this->_cpt_object->labels->singular_name, |
|
| 1296 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1297 | + '</a>' |
|
| 1298 | + ), |
|
| 1299 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
| 1300 | + 8 => sprintf( |
|
| 1301 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
| 1302 | + $this->_cpt_object->labels->singular_name, |
|
| 1303 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1304 | + '</a>' |
|
| 1305 | + ), |
|
| 1306 | + 9 => sprintf( |
|
| 1307 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
| 1308 | + $this->_cpt_object->labels->singular_name, |
|
| 1309 | + '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
| 1310 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1311 | + '</a>' |
|
| 1312 | + ), |
|
| 1313 | + 10 => sprintf( |
|
| 1314 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
| 1315 | + $this->_cpt_object->labels->singular_name, |
|
| 1316 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1317 | + '</a>' |
|
| 1318 | + ), |
|
| 1319 | + ); |
|
| 1320 | + return $messages; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * default method for the 'create_new' route for cpt admin pages. |
|
| 1327 | + * For reference what to include in here, see wp-admin/post-new.php |
|
| 1328 | + * |
|
| 1329 | + * @access protected |
|
| 1330 | + * @return string template for add new cpt form |
|
| 1331 | + */ |
|
| 1332 | + protected function _create_new_cpt_item() |
|
| 1333 | + { |
|
| 1334 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1335 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1336 | + $post_type_object = $this->_cpt_object; |
|
| 1337 | + $title = $post_type_object->labels->add_new_item; |
|
| 1338 | + $editing = true; |
|
| 1339 | + wp_enqueue_script('autosave'); |
|
| 1340 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
| 1341 | + $post_ID = $post->ID; |
|
| 1342 | + $is_IE = $is_IE; |
|
| 1343 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
| 1344 | + //modify the default editor title field with default title. |
|
| 1345 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
| 1346 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + public function add_new_admin_page_global() |
|
| 1352 | + { |
|
| 1353 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
| 1354 | + ?> |
|
| 1355 | 1355 | <script type="text/javascript"> |
| 1356 | 1356 | adminpage = '<?php echo $admin_page; ?>'; |
| 1357 | 1357 | </script> |
| 1358 | 1358 | <?php |
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - |
|
| 1363 | - /** |
|
| 1364 | - * default method for the 'edit' route for cpt admin pages |
|
| 1365 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1366 | - * |
|
| 1367 | - * @access protected |
|
| 1368 | - * @return string template for edit cpt form |
|
| 1369 | - */ |
|
| 1370 | - protected function _edit_cpt_item() |
|
| 1371 | - { |
|
| 1372 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1373 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1374 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1375 | - if (empty ($post)) { |
|
| 1376 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
| 1377 | - } |
|
| 1378 | - if ( ! empty($_GET['get-post-lock'])) { |
|
| 1379 | - wp_set_post_lock($post_id); |
|
| 1380 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
| 1381 | - exit(); |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - // template vars |
|
| 1385 | - $editing = true; |
|
| 1386 | - $post_ID = $post_id; |
|
| 1387 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1388 | - $post_type_object = $this->_cpt_object; |
|
| 1389 | - |
|
| 1390 | - if ( ! wp_check_post_lock($post->ID)) { |
|
| 1391 | - $active_post_lock = wp_set_post_lock($post->ID); |
|
| 1392 | - //wp_enqueue_script('autosave'); |
|
| 1393 | - } |
|
| 1394 | - $title = $this->_cpt_object->labels->edit_item; |
|
| 1395 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1396 | - if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1397 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
| 1398 | - ) { |
|
| 1399 | - $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1400 | - 'create_new', $this); |
|
| 1401 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1402 | - 'action' => $create_new_action, |
|
| 1403 | - 'page' => $this->page_slug, |
|
| 1404 | - ), 'admin.php'); |
|
| 1405 | - } |
|
| 1406 | - if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
| 1407 | - wp_enqueue_script('admin-comments'); |
|
| 1408 | - enqueue_comment_hotkeys_js(); |
|
| 1409 | - } |
|
| 1410 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
| 1411 | - //modify the default editor title field with default title. |
|
| 1412 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
| 1413 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * some getters |
|
| 1420 | - */ |
|
| 1421 | - /** |
|
| 1422 | - * This returns the protected _cpt_model_obj property |
|
| 1423 | - * |
|
| 1424 | - * @return EE_CPT_Base |
|
| 1425 | - */ |
|
| 1426 | - public function get_cpt_model_obj() |
|
| 1427 | - { |
|
| 1428 | - return $this->_cpt_model_obj; |
|
| 1429 | - } |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + |
|
| 1363 | + /** |
|
| 1364 | + * default method for the 'edit' route for cpt admin pages |
|
| 1365 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
| 1366 | + * |
|
| 1367 | + * @access protected |
|
| 1368 | + * @return string template for edit cpt form |
|
| 1369 | + */ |
|
| 1370 | + protected function _edit_cpt_item() |
|
| 1371 | + { |
|
| 1372 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
| 1373 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
| 1374 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
| 1375 | + if (empty ($post)) { |
|
| 1376 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
| 1377 | + } |
|
| 1378 | + if ( ! empty($_GET['get-post-lock'])) { |
|
| 1379 | + wp_set_post_lock($post_id); |
|
| 1380 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
| 1381 | + exit(); |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + // template vars |
|
| 1385 | + $editing = true; |
|
| 1386 | + $post_ID = $post_id; |
|
| 1387 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
| 1388 | + $post_type_object = $this->_cpt_object; |
|
| 1389 | + |
|
| 1390 | + if ( ! wp_check_post_lock($post->ID)) { |
|
| 1391 | + $active_post_lock = wp_set_post_lock($post->ID); |
|
| 1392 | + //wp_enqueue_script('autosave'); |
|
| 1393 | + } |
|
| 1394 | + $title = $this->_cpt_object->labels->edit_item; |
|
| 1395 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
| 1396 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
| 1397 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
| 1398 | + ) { |
|
| 1399 | + $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
| 1400 | + 'create_new', $this); |
|
| 1401 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1402 | + 'action' => $create_new_action, |
|
| 1403 | + 'page' => $this->page_slug, |
|
| 1404 | + ), 'admin.php'); |
|
| 1405 | + } |
|
| 1406 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
| 1407 | + wp_enqueue_script('admin-comments'); |
|
| 1408 | + enqueue_comment_hotkeys_js(); |
|
| 1409 | + } |
|
| 1410 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
| 1411 | + //modify the default editor title field with default title. |
|
| 1412 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
| 1413 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * some getters |
|
| 1420 | + */ |
|
| 1421 | + /** |
|
| 1422 | + * This returns the protected _cpt_model_obj property |
|
| 1423 | + * |
|
| 1424 | + * @return EE_CPT_Base |
|
| 1425 | + */ |
|
| 1426 | + public function get_cpt_model_obj() |
|
| 1427 | + { |
|
| 1428 | + return $this->_cpt_model_obj; |
|
| 1429 | + } |
|
| 1430 | 1430 | |
| 1431 | 1431 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | protected function _register_autosave_containers($ids) |
| 237 | 237 | { |
| 238 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
| 238 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | //filter _autosave_containers |
| 280 | 280 | $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
| 281 | 281 | $this->_autosave_containers, $this); |
| 282 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
| 282 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
| 283 | 283 | $containers, $this); |
| 284 | 284 | |
| 285 | 285 | wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | parent::_load_page_dependencies(); |
| 370 | 370 | //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes. |
| 371 | 371 | global $pagenow; |
| 372 | - do_action('load-' . $pagenow); |
|
| 372 | + do_action('load-'.$pagenow); |
|
| 373 | 373 | $this->modify_current_screen(); |
| 374 | 374 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
| 375 | 375 | //we route REALLY early. |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | 'admin.php?page=espresso_registrations&action=contact_list', |
| 401 | 401 | ), |
| 402 | 402 | 1 => array( |
| 403 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
| 404 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
| 403 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
| 404 | + 'admin.php?page='.$this->_cpt_object->name, |
|
| 405 | 405 | ), |
| 406 | 406 | ); |
| 407 | 407 | foreach ($routes_to_match as $route_matches) { |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
| 430 | 430 | |
| 431 | 431 | //if the installed version of WP is > 4.7 we do some additional checks. |
| 432 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 432 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
| 433 | 433 | $post_templates = wp_get_theme()->get_post_templates(); |
| 434 | 434 | //if there are $post_templates for this cpt, then we return false for this method because |
| 435 | 435 | //that means we aren't going to load our page template manager and leave that up to the native |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | global $post; |
| 453 | 453 | $template = ''; |
| 454 | 454 | |
| 455 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
| 455 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
| 456 | 456 | $page_template_count = count(get_page_templates()); |
| 457 | 457 | } else { |
| 458 | 458 | $page_template_count = count(get_page_templates($post)); |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $post = get_post($id); |
| 490 | 490 | if ('publish' != get_post_status($post)) { |
| 491 | 491 | //include shims for the `get_preview_post_link` function |
| 492 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
| 492 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
| 493 | 493 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
| 494 | 494 | . get_preview_post_link($id) |
| 495 | 495 | . '" class="button button-small">' |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | $template_args['statuses'] = $statuses; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
| 530 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
| 531 | 531 | EEH_Template::display_template($template, $template_args); |
| 532 | 532 | } |
| 533 | 533 | |
@@ -572,13 +572,13 @@ discard block |
||
| 572 | 572 | define('DOING_AUTOSAVE', true); |
| 573 | 573 | } |
| 574 | 574 | //if we made it here then the nonce checked out. Let's run our methods and actions |
| 575 | - if (method_exists($this, '_ee_autosave_' . $this->_current_view)) { |
|
| 576 | - call_user_func(array($this, '_ee_autosave_' . $this->_current_view)); |
|
| 575 | + if (method_exists($this, '_ee_autosave_'.$this->_current_view)) { |
|
| 576 | + call_user_func(array($this, '_ee_autosave_'.$this->_current_view)); |
|
| 577 | 577 | } else { |
| 578 | 578 | $this->_template_args['success'] = true; |
| 579 | 579 | } |
| 580 | 580 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
| 581 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
| 581 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
| 582 | 582 | //now let's return json |
| 583 | 583 | $this->_return_json(); |
| 584 | 584 | } |
@@ -969,7 +969,7 @@ discard block |
||
| 969 | 969 | //global action |
| 970 | 970 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
| 971 | 971 | //class specific action so you can limit hooking into a specific page. |
| 972 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
| 972 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | if ( ! empty($id) && '' != get_option('permalink_structure')) { |
| 1048 | 1048 | $post = get_post($id); |
| 1049 | 1049 | if (isset($post->post_type) && $this->page_slug == $post->post_type) { |
| 1050 | - $shortlink = home_url('?p=' . $post->ID); |
|
| 1050 | + $shortlink = home_url('?p='.$post->ID); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | } |
| 1053 | 1053 | return $shortlink; |
@@ -1082,11 +1082,11 @@ discard block |
||
| 1082 | 1082 | */ |
| 1083 | 1083 | public function cpt_post_form_hidden_input() |
| 1084 | 1084 | { |
| 1085 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
| 1085 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
| 1086 | 1086 | //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
| 1087 | 1087 | echo '<div id="ee-cpt-hidden-inputs">'; |
| 1088 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
| 1089 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
| 1088 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
| 1089 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
| 1090 | 1090 | echo '</div>'; |
| 1091 | 1091 | } |
| 1092 | 1092 | |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | } |
| 1171 | 1171 | $this->_set_model_object($this->_req_data['post'], true); |
| 1172 | 1172 | //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
| 1173 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1173 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
| 1174 | 1174 | |
| 1175 | 1175 | return EE_Admin_Page::add_query_args_and_nonce( |
| 1176 | 1176 | array( |
@@ -1281,39 +1281,39 @@ discard block |
||
| 1281 | 1281 | 1 => sprintf( |
| 1282 | 1282 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
| 1283 | 1283 | $this->_cpt_object->labels->singular_name, |
| 1284 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1284 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
| 1285 | 1285 | '</a>' |
| 1286 | 1286 | ), |
| 1287 | 1287 | 2 => __('Custom field updated'), |
| 1288 | 1288 | 3 => __('Custom field deleted.'), |
| 1289 | 1289 | 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
| 1290 | 1290 | 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
| 1291 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
| 1291 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false)) |
|
| 1292 | 1292 | : false, |
| 1293 | 1293 | 6 => sprintf( |
| 1294 | 1294 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
| 1295 | 1295 | $this->_cpt_object->labels->singular_name, |
| 1296 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
| 1296 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
| 1297 | 1297 | '</a>' |
| 1298 | 1298 | ), |
| 1299 | 1299 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
| 1300 | 1300 | 8 => sprintf( |
| 1301 | 1301 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
| 1302 | 1302 | $this->_cpt_object->labels->singular_name, |
| 1303 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
| 1303 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
| 1304 | 1304 | '</a>' |
| 1305 | 1305 | ), |
| 1306 | 1306 | 9 => sprintf( |
| 1307 | 1307 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
| 1308 | 1308 | $this->_cpt_object->labels->singular_name, |
| 1309 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
| 1310 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
| 1309 | + '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>', |
|
| 1310 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
| 1311 | 1311 | '</a>' |
| 1312 | 1312 | ), |
| 1313 | 1313 | 10 => sprintf( |
| 1314 | 1314 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
| 1315 | 1315 | $this->_cpt_object->labels->singular_name, |
| 1316 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1316 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
| 1317 | 1317 | '</a>' |
| 1318 | 1318 | ), |
| 1319 | 1319 | ); |
@@ -1343,7 +1343,7 @@ discard block |
||
| 1343 | 1343 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
| 1344 | 1344 | //modify the default editor title field with default title. |
| 1345 | 1345 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
| 1346 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1346 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
| 1411 | 1411 | //modify the default editor title field with default title. |
| 1412 | 1412 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
| 1413 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
| 1413 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @since 4.3.2 |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 10 | - exit('No direct script access allowed'); |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -22,735 +22,735 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * constructor. |
|
| 27 | - */ |
|
| 28 | - public function __construct() |
|
| 29 | - { |
|
| 30 | - $this->_caf_hooks(); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
| 36 | - * |
|
| 37 | - * @since 4.3.2 |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - private function _caf_hooks() |
|
| 42 | - { |
|
| 43 | - add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
| 44 | - add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'), |
|
| 45 | - 5, 2); |
|
| 46 | - add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5, |
|
| 47 | - 2); |
|
| 48 | - add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5, |
|
| 49 | - 2); |
|
| 50 | - add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5, |
|
| 51 | - 2); |
|
| 52 | - add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
| 53 | - add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5, |
|
| 54 | - 2); |
|
| 55 | - add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
| 56 | - array($this, 'new_default_templates'), 5, 7); |
|
| 57 | - add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5, |
|
| 58 | - 2); |
|
| 59 | - |
|
| 60 | - //shortcode parsers |
|
| 61 | - add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
| 62 | - add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
| 63 | - add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
| 64 | - array($this, 'additional_recipient_details_shortcodes'), 5, 2); |
|
| 65 | - add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
| 66 | - array($this, 'additional_recipient_details_parser'), 5, 5); |
|
| 67 | - add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
| 68 | - array($this, 'additional_primary_registration_details_shortcodes'), 5, 2); |
|
| 69 | - add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
| 70 | - array($this, 'additional_primary_registration_details_parser'), 5, 5); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @since 4.2.0 |
|
| 74 | - */ |
|
| 75 | - add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
| 76 | - add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @since 4.3.0 |
|
| 80 | - */ |
|
| 81 | - //eat our own dog food! |
|
| 82 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
| 83 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
| 84 | - do_action('EE_Brewing_Regular___messages_caf'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
| 90 | - * messages system. |
|
| 91 | - * |
|
| 92 | - * @param array $dir_ref original array of paths |
|
| 93 | - * |
|
| 94 | - * @return array appended paths |
|
| 95 | - */ |
|
| 96 | - public function messages_autoload_paths($dir_ref) |
|
| 97 | - { |
|
| 98 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
| 99 | - |
|
| 100 | - return $dir_ref; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
| 105 | - { |
|
| 106 | - $validator_config['attendee_list'] = array( |
|
| 107 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
| 108 | - 'required' => array('[ATTENDEE_LIST]') |
|
| 109 | - ); |
|
| 110 | - $validator_config['question_list'] = array( |
|
| 111 | - 'shortcodes' => array('question'), |
|
| 112 | - 'required' => array('[QUESTION_LIST]') |
|
| 113 | - ); |
|
| 114 | - |
|
| 115 | - return $validator_config; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
| 120 | - { |
|
| 121 | - $validator_config['attendee_list'] = array( |
|
| 122 | - 'shortcodes' => array('attendee', 'question_list'), |
|
| 123 | - 'required' => array('[ATTENDEE_LIST]') |
|
| 124 | - ); |
|
| 125 | - $validator_config['question_list'] = array( |
|
| 126 | - 'shortcodes' => array('question'), |
|
| 127 | - 'required' => array('[QUESTION_LIST]') |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - return $validator_config; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
| 135 | - { |
|
| 136 | - $validator_config['attendee_list'] = array( |
|
| 137 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
| 138 | - 'required' => array('[ATTENDEE_LIST]') |
|
| 139 | - ); |
|
| 140 | - $validator_config['question_list'] = array( |
|
| 141 | - 'shortcodes' => array('question'), |
|
| 142 | - 'required' => array('[QUESTION_LIST]') |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - return $validator_config; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
| 150 | - { |
|
| 151 | - $template_fields['extra']['content']['question_list'] = array( |
|
| 152 | - 'input' => 'textarea', |
|
| 153 | - 'label' => '[QUESTION_LIST]', |
|
| 154 | - 'type' => 'string', |
|
| 155 | - 'required' => true, |
|
| 156 | - 'validation' => true, |
|
| 157 | - 'format' => '%s', |
|
| 158 | - 'css_class' => 'large-text', |
|
| 159 | - 'rows' => '5', |
|
| 160 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - return $template_fields; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
| 168 | - { |
|
| 169 | - $template_fields['extra']['content']['question_list'] = array( |
|
| 170 | - 'input' => 'textarea', |
|
| 171 | - 'label' => '[QUESTION_LIST]', |
|
| 172 | - 'type' => 'string', |
|
| 173 | - 'required' => true, |
|
| 174 | - 'validation' => true, |
|
| 175 | - 'format' => '%s', |
|
| 176 | - 'css_class' => 'large-text', |
|
| 177 | - 'rows' => '5', |
|
| 178 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - return $template_fields; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
| 186 | - { |
|
| 187 | - $template_fields['extra']['content']['question_list'] = array( |
|
| 188 | - 'input' => 'textarea', |
|
| 189 | - 'label' => '[QUESTION_LIST]', |
|
| 190 | - 'type' => 'string', |
|
| 191 | - 'required' => true, |
|
| 192 | - 'validation' => true, |
|
| 193 | - 'format' => '%s', |
|
| 194 | - 'css_class' => 'large-text', |
|
| 195 | - 'rows' => '5', |
|
| 196 | - 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - return $template_fields; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - public function new_default_templates( |
|
| 204 | - $contents, |
|
| 205 | - $actual_path, |
|
| 206 | - EE_messenger $messenger, |
|
| 207 | - EE_message_type $message_type, |
|
| 208 | - $field, |
|
| 209 | - $context, |
|
| 210 | - EE_Messages_Template_Pack $template_pack |
|
| 211 | - ) { |
|
| 212 | - |
|
| 213 | - //we're only modifying templates for the default template pack |
|
| 214 | - if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 215 | - return $contents; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - //the template file name we're replacing contents for. |
|
| 219 | - $template_file_prefix = $field . '_' . $context; |
|
| 220 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
| 221 | - |
|
| 222 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
| 223 | - |
|
| 224 | - if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
| 25 | + /** |
|
| 26 | + * constructor. |
|
| 27 | + */ |
|
| 28 | + public function __construct() |
|
| 29 | + { |
|
| 30 | + $this->_caf_hooks(); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
| 36 | + * |
|
| 37 | + * @since 4.3.2 |
|
| 38 | + * |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + private function _caf_hooks() |
|
| 42 | + { |
|
| 43 | + add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
| 44 | + add_filter('FHEE__EE_Email_messenger__get_validator_config', array($this, 'email_messenger_validator_config'), |
|
| 45 | + 5, 2); |
|
| 46 | + add_filter('FHEE__EE_Email_messenger__get_template_fields', array($this, 'email_messenger_template_fields'), 5, |
|
| 47 | + 2); |
|
| 48 | + add_filter('FHEE__EE_Html_messenger__get_template_fields', array($this, 'html_messenger_template_fields'), 5, |
|
| 49 | + 2); |
|
| 50 | + add_filter('FHEE__EE_Html_messenger__get_validator_config', array($this, 'html_messenger_validator_config'), 5, |
|
| 51 | + 2); |
|
| 52 | + add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
| 53 | + add_filter('FHEE__EE_Pdf_messenger__get_validator_config', array($this, 'pdf_messenger_validator_config'), 5, |
|
| 54 | + 2); |
|
| 55 | + add_filter('FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
| 56 | + array($this, 'new_default_templates'), 5, 7); |
|
| 57 | + add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', array($this, 'message_types_valid_shortcodes'), 5, |
|
| 58 | + 2); |
|
| 59 | + |
|
| 60 | + //shortcode parsers |
|
| 61 | + add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
| 62 | + add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
| 63 | + add_filter('FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
| 64 | + array($this, 'additional_recipient_details_shortcodes'), 5, 2); |
|
| 65 | + add_filter('FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
| 66 | + array($this, 'additional_recipient_details_parser'), 5, 5); |
|
| 67 | + add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
| 68 | + array($this, 'additional_primary_registration_details_shortcodes'), 5, 2); |
|
| 69 | + add_filter('FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
| 70 | + array($this, 'additional_primary_registration_details_parser'), 5, 5); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @since 4.2.0 |
|
| 74 | + */ |
|
| 75 | + add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
| 76 | + add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @since 4.3.0 |
|
| 80 | + */ |
|
| 81 | + //eat our own dog food! |
|
| 82 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
| 83 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
| 84 | + do_action('EE_Brewing_Regular___messages_caf'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
| 90 | + * messages system. |
|
| 91 | + * |
|
| 92 | + * @param array $dir_ref original array of paths |
|
| 93 | + * |
|
| 94 | + * @return array appended paths |
|
| 95 | + */ |
|
| 96 | + public function messages_autoload_paths($dir_ref) |
|
| 97 | + { |
|
| 98 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
| 99 | + |
|
| 100 | + return $dir_ref; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
| 105 | + { |
|
| 106 | + $validator_config['attendee_list'] = array( |
|
| 107 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
| 108 | + 'required' => array('[ATTENDEE_LIST]') |
|
| 109 | + ); |
|
| 110 | + $validator_config['question_list'] = array( |
|
| 111 | + 'shortcodes' => array('question'), |
|
| 112 | + 'required' => array('[QUESTION_LIST]') |
|
| 113 | + ); |
|
| 114 | + |
|
| 115 | + return $validator_config; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
| 120 | + { |
|
| 121 | + $validator_config['attendee_list'] = array( |
|
| 122 | + 'shortcodes' => array('attendee', 'question_list'), |
|
| 123 | + 'required' => array('[ATTENDEE_LIST]') |
|
| 124 | + ); |
|
| 125 | + $validator_config['question_list'] = array( |
|
| 126 | + 'shortcodes' => array('question'), |
|
| 127 | + 'required' => array('[QUESTION_LIST]') |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + return $validator_config; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
| 135 | + { |
|
| 136 | + $validator_config['attendee_list'] = array( |
|
| 137 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
| 138 | + 'required' => array('[ATTENDEE_LIST]') |
|
| 139 | + ); |
|
| 140 | + $validator_config['question_list'] = array( |
|
| 141 | + 'shortcodes' => array('question'), |
|
| 142 | + 'required' => array('[QUESTION_LIST]') |
|
| 143 | + ); |
|
| 144 | + |
|
| 145 | + return $validator_config; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
| 150 | + { |
|
| 151 | + $template_fields['extra']['content']['question_list'] = array( |
|
| 152 | + 'input' => 'textarea', |
|
| 153 | + 'label' => '[QUESTION_LIST]', |
|
| 154 | + 'type' => 'string', |
|
| 155 | + 'required' => true, |
|
| 156 | + 'validation' => true, |
|
| 157 | + 'format' => '%s', |
|
| 158 | + 'css_class' => 'large-text', |
|
| 159 | + 'rows' => '5', |
|
| 160 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + return $template_fields; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
| 168 | + { |
|
| 169 | + $template_fields['extra']['content']['question_list'] = array( |
|
| 170 | + 'input' => 'textarea', |
|
| 171 | + 'label' => '[QUESTION_LIST]', |
|
| 172 | + 'type' => 'string', |
|
| 173 | + 'required' => true, |
|
| 174 | + 'validation' => true, |
|
| 175 | + 'format' => '%s', |
|
| 176 | + 'css_class' => 'large-text', |
|
| 177 | + 'rows' => '5', |
|
| 178 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + return $template_fields; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
| 186 | + { |
|
| 187 | + $template_fields['extra']['content']['question_list'] = array( |
|
| 188 | + 'input' => 'textarea', |
|
| 189 | + 'label' => '[QUESTION_LIST]', |
|
| 190 | + 'type' => 'string', |
|
| 191 | + 'required' => true, |
|
| 192 | + 'validation' => true, |
|
| 193 | + 'format' => '%s', |
|
| 194 | + 'css_class' => 'large-text', |
|
| 195 | + 'rows' => '5', |
|
| 196 | + 'shortcodes_required' => array('[QUESTION_LIST]') |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + return $template_fields; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + public function new_default_templates( |
|
| 204 | + $contents, |
|
| 205 | + $actual_path, |
|
| 206 | + EE_messenger $messenger, |
|
| 207 | + EE_message_type $message_type, |
|
| 208 | + $field, |
|
| 209 | + $context, |
|
| 210 | + EE_Messages_Template_Pack $template_pack |
|
| 211 | + ) { |
|
| 212 | + |
|
| 213 | + //we're only modifying templates for the default template pack |
|
| 214 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
| 215 | + return $contents; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + //the template file name we're replacing contents for. |
|
| 219 | + $template_file_prefix = $field . '_' . $context; |
|
| 220 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
| 221 | + |
|
| 222 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
| 223 | + |
|
| 224 | + if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
| 225 | 225 | |
| 226 | - switch ($template_file_prefix) { |
|
| 226 | + switch ($template_file_prefix) { |
|
| 227 | 227 | |
| 228 | - case 'question_list_admin' : |
|
| 229 | - case 'question_list_attendee' : |
|
| 230 | - case 'question_list_primary_attendee' : |
|
| 231 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
| 232 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 233 | - break; |
|
| 228 | + case 'question_list_admin' : |
|
| 229 | + case 'question_list_attendee' : |
|
| 230 | + case 'question_list_primary_attendee' : |
|
| 231 | + $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
| 232 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 233 | + break; |
|
| 234 | 234 | |
| 235 | - case 'attendee_list_primary_attendee' : |
|
| 236 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 237 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 238 | - break; |
|
| 235 | + case 'attendee_list_primary_attendee' : |
|
| 236 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 237 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 238 | + break; |
|
| 239 | 239 | |
| 240 | - case 'attendee_list_admin' : |
|
| 241 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
| 242 | - $contents = EEH_Template::display_template($path, |
|
| 243 | - array(), true); |
|
| 244 | - break; |
|
| 240 | + case 'attendee_list_admin' : |
|
| 241 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
| 242 | + $contents = EEH_Template::display_template($path, |
|
| 243 | + array(), true); |
|
| 244 | + break; |
|
| 245 | 245 | |
| 246 | - case 'attendee_list_attendee' : |
|
| 247 | - $contents = ''; |
|
| 248 | - break; |
|
| 246 | + case 'attendee_list_attendee' : |
|
| 247 | + $contents = ''; |
|
| 248 | + break; |
|
| 249 | 249 | |
| 250 | - case 'event_list_attendee' : |
|
| 251 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
| 252 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 253 | - break; |
|
| 254 | - } |
|
| 255 | - } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
| 256 | - switch ($template_file_prefix) { |
|
| 250 | + case 'event_list_attendee' : |
|
| 251 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
| 252 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 253 | + break; |
|
| 254 | + } |
|
| 255 | + } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
| 256 | + switch ($template_file_prefix) { |
|
| 257 | 257 | |
| 258 | - case 'content_attendee' : |
|
| 259 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
| 260 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 261 | - break; |
|
| 258 | + case 'content_attendee' : |
|
| 259 | + $path = $base_path . $msg_prefix . 'content.template.php'; |
|
| 260 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 261 | + break; |
|
| 262 | 262 | |
| 263 | - case 'newsletter_content_attendee' : |
|
| 264 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
| 265 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 266 | - break; |
|
| 263 | + case 'newsletter_content_attendee' : |
|
| 264 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
| 265 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 266 | + break; |
|
| 267 | 267 | |
| 268 | - case 'newsletter_subject_attendee' : |
|
| 269 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
| 270 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 271 | - break; |
|
| 272 | - } |
|
| 273 | - } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
| 274 | - switch ($template_file_prefix) { |
|
| 275 | - case 'attendee_list_purchaser' : |
|
| 276 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 277 | - $contents = EEH_Template::display_template($path, array(), true); |
|
| 278 | - break; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - return $contents; |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - |
|
| 287 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
| 288 | - { |
|
| 289 | - //make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
| 290 | - $include_with = array( |
|
| 291 | - 'registration', |
|
| 292 | - 'cancelled_registration', |
|
| 293 | - 'declined_registration', |
|
| 294 | - 'not_approved_registration', |
|
| 295 | - 'payment_declined', |
|
| 296 | - 'payment_failed', |
|
| 297 | - 'payment_cancelled', |
|
| 298 | - 'payment', |
|
| 299 | - 'payment_reminder', |
|
| 300 | - 'pending_approval', |
|
| 301 | - 'registration_summary', |
|
| 302 | - 'invoice', |
|
| 303 | - 'receipt' |
|
| 304 | - ); |
|
| 305 | - if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
| 306 | - $contexts = array_keys($msg->get_contexts()); |
|
| 307 | - foreach ($contexts as $context) { |
|
| 308 | - $valid_shortcodes[$context][] = 'question_list'; |
|
| 309 | - $valid_shortcodes[$context][] = 'question'; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $valid_shortcodes; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
| 318 | - { |
|
| 319 | - $shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
| 320 | - 'event_espresso'); |
|
| 321 | - |
|
| 322 | - return $shortcodes; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 327 | - { |
|
| 328 | - |
|
| 329 | - if (strpos($shortcode, |
|
| 330 | - '[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations) |
|
| 331 | - ) { |
|
| 332 | - return $parsed; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - //let's get the question from the code. |
|
| 336 | - $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
| 337 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
| 338 | - |
|
| 339 | - $registration = $data instanceof EE_Registration ? $data : null; |
|
| 340 | - $registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
| 341 | - |
|
| 342 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
| 343 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
| 344 | - |
|
| 345 | - if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
| 346 | - return $parsed; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - //now let's figure out which question has this text. |
|
| 350 | - foreach ($aee->questions as $ansid => $question) { |
|
| 351 | - if ( |
|
| 352 | - $question instanceof EE_Question |
|
| 353 | - && trim($question->display_text()) == trim($shortcode) |
|
| 354 | - && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
| 355 | - ) { |
|
| 356 | - return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value', |
|
| 357 | - 'no_wpautop'); |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - //nothing! |
|
| 362 | - return $parsed; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
| 368 | - * |
|
| 369 | - * @since 4.2 |
|
| 370 | - * |
|
| 371 | - * @param array $shortcodes array of shortcodes and |
|
| 372 | - * descriptions |
|
| 373 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
| 374 | - * |
|
| 375 | - * @return array array of shortcodes and |
|
| 376 | - * descriptions |
|
| 377 | - */ |
|
| 378 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
| 379 | - { |
|
| 380 | - $shortcodes['[DTT_NAME]'] = __('This will be parsed to the Title given for a Datetime', |
|
| 381 | - 'event_espresso'); |
|
| 382 | - $shortcodes['[DTT_DESCRIPTION]'] = __('This will be parsed to the description for a Datetime', |
|
| 383 | - 'event_espresso'); |
|
| 384 | - $shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
| 385 | - 'event_espresso'); |
|
| 386 | - |
|
| 387 | - return $shortcodes; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Callback for additional shortcodes parser filter used for adding parser for new |
|
| 393 | - * Datetime shortcodes |
|
| 394 | - * |
|
| 395 | - * @since 4.2 |
|
| 396 | - * |
|
| 397 | - * @param string $parsed The finished parsed string for the given shortcode. |
|
| 398 | - * @param string $shortcode The shortcode being parsed. |
|
| 399 | - * @param object $data The incoming data object for the Shortcode Parser. |
|
| 400 | - * @param object $extra_data The incoming extra date object for the Shortcode |
|
| 401 | - * Parser. |
|
| 402 | - * @param EE_Datetime_Shortcodes $shortcode_parser |
|
| 403 | - * |
|
| 404 | - * @return string The new parsed string. |
|
| 405 | - */ |
|
| 406 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 407 | - { |
|
| 408 | - |
|
| 409 | - if ( ! $data instanceof EE_Datetime) { |
|
| 410 | - return ''; //get out because we can only parse with the datetime object. |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - switch ($shortcode) { |
|
| 414 | - case '[DTT_NAME]' : |
|
| 415 | - return $data->name(); |
|
| 416 | - break; |
|
| 417 | - case '[DTT_DESCRIPTION]' : |
|
| 418 | - return $data->description(); |
|
| 419 | - break; |
|
| 420 | - case '[DTT_NAME_OR_DATES]' : |
|
| 421 | - return $data->get_dtt_display_name(true); |
|
| 422 | - break; |
|
| 423 | - default : |
|
| 424 | - return $parsed; |
|
| 425 | - break; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
| 431 | - { |
|
| 432 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
| 433 | - 'event_espresso'); |
|
| 434 | - |
|
| 435 | - return $shortcodes; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
| 441 | - * |
|
| 442 | - * @param string $parsed The original parsed content for the shortcode |
|
| 443 | - * @param string $shortcode The shortcode being parsed |
|
| 444 | - * @param array $data The shortcode parser data array |
|
| 445 | - * @param array $extra_data The shortcode parser extra data array |
|
| 446 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
| 447 | - * |
|
| 448 | - * @return string |
|
| 449 | - */ |
|
| 450 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 451 | - { |
|
| 452 | - |
|
| 453 | - if (array($data) && ! isset($data['data'])) { |
|
| 454 | - return $parsed; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
| 458 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
| 459 | - |
|
| 460 | - if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
| 461 | - return $parsed; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - switch ($shortcode) { |
|
| 465 | - case '[RECIPIENT_QUESTION_LIST]' : |
|
| 466 | - $att = $recipient->att_obj; |
|
| 467 | - $registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array(); |
|
| 468 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
| 469 | - $answers = array(); |
|
| 268 | + case 'newsletter_subject_attendee' : |
|
| 269 | + $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
| 270 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 271 | + break; |
|
| 272 | + } |
|
| 273 | + } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
| 274 | + switch ($template_file_prefix) { |
|
| 275 | + case 'attendee_list_purchaser' : |
|
| 276 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 277 | + $contents = EEH_Template::display_template($path, array(), true); |
|
| 278 | + break; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + return $contents; |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + |
|
| 287 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
| 288 | + { |
|
| 289 | + //make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
| 290 | + $include_with = array( |
|
| 291 | + 'registration', |
|
| 292 | + 'cancelled_registration', |
|
| 293 | + 'declined_registration', |
|
| 294 | + 'not_approved_registration', |
|
| 295 | + 'payment_declined', |
|
| 296 | + 'payment_failed', |
|
| 297 | + 'payment_cancelled', |
|
| 298 | + 'payment', |
|
| 299 | + 'payment_reminder', |
|
| 300 | + 'pending_approval', |
|
| 301 | + 'registration_summary', |
|
| 302 | + 'invoice', |
|
| 303 | + 'receipt' |
|
| 304 | + ); |
|
| 305 | + if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
| 306 | + $contexts = array_keys($msg->get_contexts()); |
|
| 307 | + foreach ($contexts as $context) { |
|
| 308 | + $valid_shortcodes[$context][] = 'question_list'; |
|
| 309 | + $valid_shortcodes[$context][] = 'question'; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $valid_shortcodes; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
| 318 | + { |
|
| 319 | + $shortcodes['[ANSWER_*]'] = __('This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
| 320 | + 'event_espresso'); |
|
| 321 | + |
|
| 322 | + return $shortcodes; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 327 | + { |
|
| 328 | + |
|
| 329 | + if (strpos($shortcode, |
|
| 330 | + '[ANSWER_*') === false || ! isset($extra_data['data']->questions) || ! isset($extra_data['data']->registrations) |
|
| 331 | + ) { |
|
| 332 | + return $parsed; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + //let's get the question from the code. |
|
| 336 | + $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
| 337 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
| 338 | + |
|
| 339 | + $registration = $data instanceof EE_Registration ? $data : null; |
|
| 340 | + $registration = ! $registration instanceof EE_Registration && is_array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
| 341 | + |
|
| 342 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
| 343 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array($extra_data) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
| 344 | + |
|
| 345 | + if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
| 346 | + return $parsed; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + //now let's figure out which question has this text. |
|
| 350 | + foreach ($aee->questions as $ansid => $question) { |
|
| 351 | + if ( |
|
| 352 | + $question instanceof EE_Question |
|
| 353 | + && trim($question->display_text()) == trim($shortcode) |
|
| 354 | + && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
| 355 | + ) { |
|
| 356 | + return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value', |
|
| 357 | + 'no_wpautop'); |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + //nothing! |
|
| 362 | + return $parsed; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
| 368 | + * |
|
| 369 | + * @since 4.2 |
|
| 370 | + * |
|
| 371 | + * @param array $shortcodes array of shortcodes and |
|
| 372 | + * descriptions |
|
| 373 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
| 374 | + * |
|
| 375 | + * @return array array of shortcodes and |
|
| 376 | + * descriptions |
|
| 377 | + */ |
|
| 378 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
| 379 | + { |
|
| 380 | + $shortcodes['[DTT_NAME]'] = __('This will be parsed to the Title given for a Datetime', |
|
| 381 | + 'event_espresso'); |
|
| 382 | + $shortcodes['[DTT_DESCRIPTION]'] = __('This will be parsed to the description for a Datetime', |
|
| 383 | + 'event_espresso'); |
|
| 384 | + $shortcodes['[DTT_NAME_OR_DATES]'] = __('When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
| 385 | + 'event_espresso'); |
|
| 386 | + |
|
| 387 | + return $shortcodes; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Callback for additional shortcodes parser filter used for adding parser for new |
|
| 393 | + * Datetime shortcodes |
|
| 394 | + * |
|
| 395 | + * @since 4.2 |
|
| 396 | + * |
|
| 397 | + * @param string $parsed The finished parsed string for the given shortcode. |
|
| 398 | + * @param string $shortcode The shortcode being parsed. |
|
| 399 | + * @param object $data The incoming data object for the Shortcode Parser. |
|
| 400 | + * @param object $extra_data The incoming extra date object for the Shortcode |
|
| 401 | + * Parser. |
|
| 402 | + * @param EE_Datetime_Shortcodes $shortcode_parser |
|
| 403 | + * |
|
| 404 | + * @return string The new parsed string. |
|
| 405 | + */ |
|
| 406 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 407 | + { |
|
| 408 | + |
|
| 409 | + if ( ! $data instanceof EE_Datetime) { |
|
| 410 | + return ''; //get out because we can only parse with the datetime object. |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + switch ($shortcode) { |
|
| 414 | + case '[DTT_NAME]' : |
|
| 415 | + return $data->name(); |
|
| 416 | + break; |
|
| 417 | + case '[DTT_DESCRIPTION]' : |
|
| 418 | + return $data->description(); |
|
| 419 | + break; |
|
| 420 | + case '[DTT_NAME_OR_DATES]' : |
|
| 421 | + return $data->get_dtt_display_name(true); |
|
| 422 | + break; |
|
| 423 | + default : |
|
| 424 | + return $parsed; |
|
| 425 | + break; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
| 431 | + { |
|
| 432 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __('This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
| 433 | + 'event_espresso'); |
|
| 434 | + |
|
| 435 | + return $shortcodes; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
| 441 | + * |
|
| 442 | + * @param string $parsed The original parsed content for the shortcode |
|
| 443 | + * @param string $shortcode The shortcode being parsed |
|
| 444 | + * @param array $data The shortcode parser data array |
|
| 445 | + * @param array $extra_data The shortcode parser extra data array |
|
| 446 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
| 447 | + * |
|
| 448 | + * @return string |
|
| 449 | + */ |
|
| 450 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
| 451 | + { |
|
| 452 | + |
|
| 453 | + if (array($data) && ! isset($data['data'])) { |
|
| 454 | + return $parsed; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
| 458 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
| 459 | + |
|
| 460 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
| 461 | + return $parsed; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + switch ($shortcode) { |
|
| 465 | + case '[RECIPIENT_QUESTION_LIST]' : |
|
| 466 | + $att = $recipient->att_obj; |
|
| 467 | + $registrations_on_attendee = $att instanceof EE_Attendee ? $recipient->attendees[$att->ID()]['reg_objs'] : array(); |
|
| 468 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
| 469 | + $answers = array(); |
|
| 470 | 470 | |
| 471 | - $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
| 472 | - $valid_shortcodes = array('question'); |
|
| 471 | + $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
| 472 | + $valid_shortcodes = array('question'); |
|
| 473 | 473 | |
| 474 | - //if the context is main_content then get all answers for all registrations on this attendee |
|
| 475 | - if ($data['data'] instanceof EE_Messages_Addressee) { |
|
| 474 | + //if the context is main_content then get all answers for all registrations on this attendee |
|
| 475 | + if ($data['data'] instanceof EE_Messages_Addressee) { |
|
| 476 | 476 | |
| 477 | - foreach ($registrations_on_attendee as $reg) { |
|
| 478 | - if ($reg instanceof EE_Registration) { |
|
| 479 | - $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
| 480 | - foreach ($anss as $ans) { |
|
| 481 | - if ($ans instanceof EE_Answer) { |
|
| 482 | - $answers[$ans->ID()] = $ans; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - } |
|
| 477 | + foreach ($registrations_on_attendee as $reg) { |
|
| 478 | + if ($reg instanceof EE_Registration) { |
|
| 479 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
| 480 | + foreach ($anss as $ans) { |
|
| 481 | + if ($ans instanceof EE_Answer) { |
|
| 482 | + $answers[$ans->ID()] = $ans; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - //if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
| 490 | - if ($data['data'] instanceof EE_Event) { |
|
| 491 | - $event = $data['data']; |
|
| 492 | - foreach ($registrations_on_attendee as $reg) { |
|
| 493 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
| 494 | - $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
| 495 | - foreach ($anss as $ans) { |
|
| 496 | - if ($ans instanceof EE_Answer) { |
|
| 497 | - $answers[$ans->ID()] = $ans; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 489 | + //if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
| 490 | + if ($data['data'] instanceof EE_Event) { |
|
| 491 | + $event = $data['data']; |
|
| 492 | + foreach ($registrations_on_attendee as $reg) { |
|
| 493 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
| 494 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) ? $recipient->registrations[$reg->ID()]['ans_objs'] : array(); |
|
| 495 | + foreach ($anss as $ans) { |
|
| 496 | + if ($ans instanceof EE_Answer) { |
|
| 497 | + $answers[$ans->ID()] = $ans; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
| 504 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
| 505 | 505 | |
| 506 | - //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
| 507 | - //object on it. |
|
| 508 | - if ( ! isset( $extra_data['data'] ) ) { |
|
| 509 | - $extra_data['data'] = $recipient; |
|
| 510 | - } |
|
| 506 | + //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
| 507 | + //object on it. |
|
| 508 | + if ( ! isset( $extra_data['data'] ) ) { |
|
| 509 | + $extra_data['data'] = $recipient; |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
| 513 | - $shortcode_parser, |
|
| 514 | - $questions, |
|
| 515 | - $answers, |
|
| 516 | - $template, |
|
| 517 | - $valid_shortcodes, |
|
| 518 | - $extra_data |
|
| 519 | - ); |
|
| 520 | - break; |
|
| 512 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
| 513 | + $shortcode_parser, |
|
| 514 | + $questions, |
|
| 515 | + $answers, |
|
| 516 | + $template, |
|
| 517 | + $valid_shortcodes, |
|
| 518 | + $extra_data |
|
| 519 | + ); |
|
| 520 | + break; |
|
| 521 | 521 | |
| 522 | - default : |
|
| 523 | - return $parsed; |
|
| 524 | - break; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
| 530 | - { |
|
| 531 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
| 532 | - 'event_espresso'); |
|
| 533 | - |
|
| 534 | - return $shortcodes; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
| 540 | - * |
|
| 541 | - * @param string $parsed The original parsed content for the shortcode |
|
| 542 | - * @param string $shortcode The shortcode being parsed |
|
| 543 | - * @param array $data The shortcode parser data array |
|
| 544 | - * @param array $extra_data The shortcode parser extra data array |
|
| 545 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
| 546 | - * |
|
| 547 | - * @return string |
|
| 548 | - */ |
|
| 549 | - public function additional_primary_registration_details_parser( |
|
| 550 | - $parsed, |
|
| 551 | - $shortcode, |
|
| 552 | - $data, |
|
| 553 | - $extra_data, |
|
| 554 | - $shortcode_parser |
|
| 555 | - ) { |
|
| 556 | - if (array($data) && ! isset($data['data'])) { |
|
| 557 | - return $parsed; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
| 561 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
| 562 | - |
|
| 563 | - if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
| 564 | - return $parsed; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - switch ($shortcode) { |
|
| 568 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]' : |
|
| 569 | - if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
| 570 | - return ''; |
|
| 571 | - } |
|
| 572 | - $registration = $recipient->primary_reg_obj; |
|
| 573 | - $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
| 574 | - ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
| 575 | - : array(); |
|
| 576 | - if (empty($answers)) { |
|
| 577 | - return ''; |
|
| 578 | - } |
|
| 579 | - $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
| 580 | - $valid_shortcodes = array('question'); |
|
| 581 | - $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
| 582 | - $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
| 583 | - //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
| 584 | - //object on it. |
|
| 585 | - if ( ! isset( $extra_data['data'] ) ){ |
|
| 586 | - $extra_data['data'] = $recipient; |
|
| 587 | - } |
|
| 588 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
| 589 | - $shortcode_parser, |
|
| 590 | - $questions, |
|
| 591 | - $answers, |
|
| 592 | - $template, |
|
| 593 | - $valid_shortcodes, |
|
| 594 | - $extra_data |
|
| 595 | - ); |
|
| 596 | - break; |
|
| 522 | + default : |
|
| 523 | + return $parsed; |
|
| 524 | + break; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
| 530 | + { |
|
| 531 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __('This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
| 532 | + 'event_espresso'); |
|
| 533 | + |
|
| 534 | + return $shortcodes; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
| 540 | + * |
|
| 541 | + * @param string $parsed The original parsed content for the shortcode |
|
| 542 | + * @param string $shortcode The shortcode being parsed |
|
| 543 | + * @param array $data The shortcode parser data array |
|
| 544 | + * @param array $extra_data The shortcode parser extra data array |
|
| 545 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
| 546 | + * |
|
| 547 | + * @return string |
|
| 548 | + */ |
|
| 549 | + public function additional_primary_registration_details_parser( |
|
| 550 | + $parsed, |
|
| 551 | + $shortcode, |
|
| 552 | + $data, |
|
| 553 | + $extra_data, |
|
| 554 | + $shortcode_parser |
|
| 555 | + ) { |
|
| 556 | + if (array($data) && ! isset($data['data'])) { |
|
| 557 | + return $parsed; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
| 561 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
| 562 | + |
|
| 563 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
| 564 | + return $parsed; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + switch ($shortcode) { |
|
| 568 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]' : |
|
| 569 | + if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
| 570 | + return ''; |
|
| 571 | + } |
|
| 572 | + $registration = $recipient->primary_reg_obj; |
|
| 573 | + $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
| 574 | + ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
| 575 | + : array(); |
|
| 576 | + if (empty($answers)) { |
|
| 577 | + return ''; |
|
| 578 | + } |
|
| 579 | + $template = is_array($data['template']) && isset($data['template']['question_list']) ? $data['template']['question_list'] : $extra_data['template']['question_list']; |
|
| 580 | + $valid_shortcodes = array('question'); |
|
| 581 | + $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
| 582 | + $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
| 583 | + //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
| 584 | + //object on it. |
|
| 585 | + if ( ! isset( $extra_data['data'] ) ){ |
|
| 586 | + $extra_data['data'] = $recipient; |
|
| 587 | + } |
|
| 588 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
| 589 | + $shortcode_parser, |
|
| 590 | + $questions, |
|
| 591 | + $answers, |
|
| 592 | + $template, |
|
| 593 | + $valid_shortcodes, |
|
| 594 | + $extra_data |
|
| 595 | + ); |
|
| 596 | + break; |
|
| 597 | 597 | |
| 598 | - default : |
|
| 599 | - return $parsed; |
|
| 600 | - break; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * Takes care of registering the message types that are only available in caffeinated EE. |
|
| 607 | - * |
|
| 608 | - * @since 4.3.2 |
|
| 609 | - * |
|
| 610 | - * @return void |
|
| 611 | - */ |
|
| 612 | - public function register_caf_message_types() |
|
| 613 | - { |
|
| 614 | - //register newsletter message type |
|
| 615 | - $setup_args = array( |
|
| 616 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
| 617 | - 'autoloadpaths' => array( |
|
| 618 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
| 619 | - ), |
|
| 620 | - 'messengers_to_activate_with' => array('email'), |
|
| 621 | - 'messengers_to_validate_with' => array('email'), |
|
| 622 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 623 | - ); |
|
| 624 | - EE_Register_Message_Type::register('newsletter', $setup_args); |
|
| 625 | - |
|
| 626 | - //register payment reminder message type |
|
| 627 | - $setup_args = array( |
|
| 628 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
| 629 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
| 630 | - 'messengers_to_activate_with' => array('email'), |
|
| 631 | - 'messengers_to_validate_with' => array('email'), |
|
| 632 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 633 | - ); |
|
| 634 | - EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
| 635 | - |
|
| 636 | - //register payment declined message type |
|
| 637 | - $setup_args = array( |
|
| 638 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
| 639 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
| 640 | - 'messengers_to_activate_with' => array('email'), |
|
| 641 | - 'messengers_to_validate_with' => array('email'), |
|
| 642 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 643 | - ); |
|
| 644 | - EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
| 645 | - |
|
| 646 | - //register registration declined message type |
|
| 647 | - $setup_args = array( |
|
| 648 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
| 649 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
| 650 | - 'messengers_to_activate_with' => array('email'), |
|
| 651 | - 'messengers_to_validate_with' => array('email'), |
|
| 652 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 653 | - ); |
|
| 654 | - EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
| 655 | - |
|
| 656 | - //register registration cancelled message type |
|
| 657 | - $setup_args = array( |
|
| 658 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
| 659 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
| 660 | - 'messengers_to_activate_with' => array('email'), |
|
| 661 | - 'messengers_to_validate_with' => array('email'), |
|
| 662 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 663 | - ); |
|
| 664 | - EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
| 665 | - |
|
| 666 | - |
|
| 667 | - //register payment failed message type |
|
| 668 | - $setup_args = array( |
|
| 669 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
| 670 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
| 671 | - 'messengers_to_activate_with' => array('email'), |
|
| 672 | - 'messengers_to_validate_with' => array('email'), |
|
| 673 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 674 | - ); |
|
| 675 | - EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
| 676 | - |
|
| 677 | - //register payment declined message type |
|
| 678 | - $setup_args = array( |
|
| 679 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
| 680 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
| 681 | - 'messengers_to_activate_with' => array('email'), |
|
| 682 | - 'messengers_to_validate_with' => array('email'), |
|
| 683 | - 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 684 | - ); |
|
| 685 | - EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
| 691 | - * |
|
| 692 | - * @since 4.3.2 |
|
| 693 | - * |
|
| 694 | - * @return void |
|
| 695 | - */ |
|
| 696 | - public function register_caf_shortcodes() |
|
| 697 | - { |
|
| 698 | - $setup_args = array( |
|
| 699 | - 'autoloadpaths' => array( |
|
| 700 | - EE_CAF_LIBRARIES . 'shortcodes/' |
|
| 701 | - ), |
|
| 702 | - 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
| 703 | - 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
| 704 | - 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]') |
|
| 705 | - ); |
|
| 706 | - EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * Parses a question list shortcode using given data and template |
|
| 712 | - * |
|
| 713 | - * @param \EE_Shortcodes $shortcode_parser |
|
| 714 | - * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
| 715 | - * @param EE_Answer[] $answers An array of answer objects |
|
| 716 | - * @param string $template Template content to be parsed. |
|
| 717 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
| 718 | - * @param array $extra_data Extra data that might be used when parsing the template. |
|
| 719 | - */ |
|
| 720 | - protected function _parse_question_list_for_primary_or_recipient_registration( |
|
| 721 | - $shortcode_parser, |
|
| 722 | - $questions, |
|
| 723 | - $answers, |
|
| 724 | - $template, |
|
| 725 | - $valid_shortcodes, |
|
| 726 | - $extra_data |
|
| 727 | - ) { |
|
| 728 | - $question_list = ''; |
|
| 729 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
| 730 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
| 731 | - foreach ($answers as $answer) { |
|
| 732 | - if ($answer instanceof EE_Answer) { |
|
| 733 | - //first see if the question is in our $questions array. If not then try to get from answer object. |
|
| 734 | - $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
| 735 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
| 736 | - if ( |
|
| 737 | - ! $question instanceof EE_Question |
|
| 738 | - || ( |
|
| 739 | - $question instanceof EE_Question |
|
| 740 | - && $question->admin_only() |
|
| 741 | - ) |
|
| 742 | - ) { |
|
| 743 | - continue; |
|
| 744 | - } |
|
| 745 | - $question_list .= $shortcode_helper->parse_question_list_template( |
|
| 746 | - $template, |
|
| 747 | - $answer, |
|
| 748 | - $valid_shortcodes, |
|
| 749 | - $extra_data |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - return $question_list; |
|
| 755 | - } |
|
| 598 | + default : |
|
| 599 | + return $parsed; |
|
| 600 | + break; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * Takes care of registering the message types that are only available in caffeinated EE. |
|
| 607 | + * |
|
| 608 | + * @since 4.3.2 |
|
| 609 | + * |
|
| 610 | + * @return void |
|
| 611 | + */ |
|
| 612 | + public function register_caf_message_types() |
|
| 613 | + { |
|
| 614 | + //register newsletter message type |
|
| 615 | + $setup_args = array( |
|
| 616 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
| 617 | + 'autoloadpaths' => array( |
|
| 618 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
| 619 | + ), |
|
| 620 | + 'messengers_to_activate_with' => array('email'), |
|
| 621 | + 'messengers_to_validate_with' => array('email'), |
|
| 622 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 623 | + ); |
|
| 624 | + EE_Register_Message_Type::register('newsletter', $setup_args); |
|
| 625 | + |
|
| 626 | + //register payment reminder message type |
|
| 627 | + $setup_args = array( |
|
| 628 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
| 629 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
| 630 | + 'messengers_to_activate_with' => array('email'), |
|
| 631 | + 'messengers_to_validate_with' => array('email'), |
|
| 632 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 633 | + ); |
|
| 634 | + EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
| 635 | + |
|
| 636 | + //register payment declined message type |
|
| 637 | + $setup_args = array( |
|
| 638 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
| 639 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
| 640 | + 'messengers_to_activate_with' => array('email'), |
|
| 641 | + 'messengers_to_validate_with' => array('email'), |
|
| 642 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 643 | + ); |
|
| 644 | + EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
| 645 | + |
|
| 646 | + //register registration declined message type |
|
| 647 | + $setup_args = array( |
|
| 648 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
| 649 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
| 650 | + 'messengers_to_activate_with' => array('email'), |
|
| 651 | + 'messengers_to_validate_with' => array('email'), |
|
| 652 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 653 | + ); |
|
| 654 | + EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
| 655 | + |
|
| 656 | + //register registration cancelled message type |
|
| 657 | + $setup_args = array( |
|
| 658 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
| 659 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
| 660 | + 'messengers_to_activate_with' => array('email'), |
|
| 661 | + 'messengers_to_validate_with' => array('email'), |
|
| 662 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 663 | + ); |
|
| 664 | + EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
| 665 | + |
|
| 666 | + |
|
| 667 | + //register payment failed message type |
|
| 668 | + $setup_args = array( |
|
| 669 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
| 670 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
| 671 | + 'messengers_to_activate_with' => array('email'), |
|
| 672 | + 'messengers_to_validate_with' => array('email'), |
|
| 673 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 674 | + ); |
|
| 675 | + EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
| 676 | + |
|
| 677 | + //register payment declined message type |
|
| 678 | + $setup_args = array( |
|
| 679 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
| 680 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
| 681 | + 'messengers_to_activate_with' => array('email'), |
|
| 682 | + 'messengers_to_validate_with' => array('email'), |
|
| 683 | + 'messengers_supporting_default_template_pack_with' => array('email') |
|
| 684 | + ); |
|
| 685 | + EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
| 691 | + * |
|
| 692 | + * @since 4.3.2 |
|
| 693 | + * |
|
| 694 | + * @return void |
|
| 695 | + */ |
|
| 696 | + public function register_caf_shortcodes() |
|
| 697 | + { |
|
| 698 | + $setup_args = array( |
|
| 699 | + 'autoloadpaths' => array( |
|
| 700 | + EE_CAF_LIBRARIES . 'shortcodes/' |
|
| 701 | + ), |
|
| 702 | + 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
| 703 | + 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
| 704 | + 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]') |
|
| 705 | + ); |
|
| 706 | + EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * Parses a question list shortcode using given data and template |
|
| 712 | + * |
|
| 713 | + * @param \EE_Shortcodes $shortcode_parser |
|
| 714 | + * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
| 715 | + * @param EE_Answer[] $answers An array of answer objects |
|
| 716 | + * @param string $template Template content to be parsed. |
|
| 717 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
| 718 | + * @param array $extra_data Extra data that might be used when parsing the template. |
|
| 719 | + */ |
|
| 720 | + protected function _parse_question_list_for_primary_or_recipient_registration( |
|
| 721 | + $shortcode_parser, |
|
| 722 | + $questions, |
|
| 723 | + $answers, |
|
| 724 | + $template, |
|
| 725 | + $valid_shortcodes, |
|
| 726 | + $extra_data |
|
| 727 | + ) { |
|
| 728 | + $question_list = ''; |
|
| 729 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
| 730 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
| 731 | + foreach ($answers as $answer) { |
|
| 732 | + if ($answer instanceof EE_Answer) { |
|
| 733 | + //first see if the question is in our $questions array. If not then try to get from answer object. |
|
| 734 | + $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
| 735 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
| 736 | + if ( |
|
| 737 | + ! $question instanceof EE_Question |
|
| 738 | + || ( |
|
| 739 | + $question instanceof EE_Question |
|
| 740 | + && $question->admin_only() |
|
| 741 | + ) |
|
| 742 | + ) { |
|
| 743 | + continue; |
|
| 744 | + } |
|
| 745 | + $question_list .= $shortcode_helper->parse_question_list_template( |
|
| 746 | + $template, |
|
| 747 | + $answer, |
|
| 748 | + $valid_shortcodes, |
|
| 749 | + $extra_data |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + return $question_list; |
|
| 755 | + } |
|
| 756 | 756 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function messages_autoload_paths($dir_ref) |
| 97 | 97 | { |
| 98 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
| 98 | + $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/'; |
|
| 99 | 99 | |
| 100 | 100 | return $dir_ref; |
| 101 | 101 | } |
@@ -216,10 +216,10 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | //the template file name we're replacing contents for. |
| 219 | - $template_file_prefix = $field . '_' . $context; |
|
| 220 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
| 219 | + $template_file_prefix = $field.'_'.$context; |
|
| 220 | + $msg_prefix = $messenger->name.'_'.$message_type->name.'_'; |
|
| 221 | 221 | |
| 222 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
| 222 | + $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/'; |
|
| 223 | 223 | |
| 224 | 224 | if ($messenger->name == 'email' && $message_type->name == 'registration') { |
| 225 | 225 | |
@@ -228,17 +228,17 @@ discard block |
||
| 228 | 228 | case 'question_list_admin' : |
| 229 | 229 | case 'question_list_attendee' : |
| 230 | 230 | case 'question_list_primary_attendee' : |
| 231 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
| 231 | + $path = $base_path.$msg_prefix.'question_list.template.php'; |
|
| 232 | 232 | $contents = EEH_Template::display_template($path, array(), true); |
| 233 | 233 | break; |
| 234 | 234 | |
| 235 | 235 | case 'attendee_list_primary_attendee' : |
| 236 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 236 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
| 237 | 237 | $contents = EEH_Template::display_template($path, array(), true); |
| 238 | 238 | break; |
| 239 | 239 | |
| 240 | 240 | case 'attendee_list_admin' : |
| 241 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
| 241 | + $path = $base_path.$msg_prefix.'attendee_list_admin.template.php'; |
|
| 242 | 242 | $contents = EEH_Template::display_template($path, |
| 243 | 243 | array(), true); |
| 244 | 244 | break; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | break; |
| 249 | 249 | |
| 250 | 250 | case 'event_list_attendee' : |
| 251 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
| 251 | + $path = $base_path.$msg_prefix.'event_list_attendee.template.php'; |
|
| 252 | 252 | $contents = EEH_Template::display_template($path, array(), true); |
| 253 | 253 | break; |
| 254 | 254 | } |
@@ -256,24 +256,24 @@ discard block |
||
| 256 | 256 | switch ($template_file_prefix) { |
| 257 | 257 | |
| 258 | 258 | case 'content_attendee' : |
| 259 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
| 259 | + $path = $base_path.$msg_prefix.'content.template.php'; |
|
| 260 | 260 | $contents = EEH_Template::display_template($path, array(), true); |
| 261 | 261 | break; |
| 262 | 262 | |
| 263 | 263 | case 'newsletter_content_attendee' : |
| 264 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
| 264 | + $path = $base_path.$msg_prefix.'newsletter_content.template.php'; |
|
| 265 | 265 | $contents = EEH_Template::display_template($path, array(), true); |
| 266 | 266 | break; |
| 267 | 267 | |
| 268 | 268 | case 'newsletter_subject_attendee' : |
| 269 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
| 269 | + $path = $base_path.$msg_prefix.'subject.template.php'; |
|
| 270 | 270 | $contents = EEH_Template::display_template($path, array(), true); |
| 271 | 271 | break; |
| 272 | 272 | } |
| 273 | 273 | } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
| 274 | 274 | switch ($template_file_prefix) { |
| 275 | 275 | case 'attendee_list_purchaser' : |
| 276 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
| 276 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
| 277 | 277 | $contents = EEH_Template::display_template($path, array(), true); |
| 278 | 278 | break; |
| 279 | 279 | } |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | |
| 506 | 506 | //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
| 507 | 507 | //object on it. |
| 508 | - if ( ! isset( $extra_data['data'] ) ) { |
|
| 508 | + if ( ! isset($extra_data['data'])) { |
|
| 509 | 509 | $extra_data['data'] = $recipient; |
| 510 | 510 | } |
| 511 | 511 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
| 570 | 570 | return ''; |
| 571 | 571 | } |
| 572 | - $registration = $recipient->primary_reg_obj; |
|
| 572 | + $registration = $recipient->primary_reg_obj; |
|
| 573 | 573 | $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
| 574 | 574 | ? $recipient->registrations[$registration->ID()]['ans_objs'] |
| 575 | 575 | : array(); |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | $questions = isset($recipient->questions) ? $recipient->questions : array(); |
| 583 | 583 | //if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
| 584 | 584 | //object on it. |
| 585 | - if ( ! isset( $extra_data['data'] ) ){ |
|
| 585 | + if ( ! isset($extra_data['data'])) { |
|
| 586 | 586 | $extra_data['data'] = $recipient; |
| 587 | 587 | } |
| 588 | 588 | return $this->_parse_question_list_for_primary_or_recipient_registration( |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | $setup_args = array( |
| 616 | 616 | 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
| 617 | 617 | 'autoloadpaths' => array( |
| 618 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/' |
|
| 618 | + EE_CAF_LIBRARIES.'messages/message_type/newsletter/' |
|
| 619 | 619 | ), |
| 620 | 620 | 'messengers_to_activate_with' => array('email'), |
| 621 | 621 | 'messengers_to_validate_with' => array('email'), |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | //register payment reminder message type |
| 627 | 627 | $setup_args = array( |
| 628 | 628 | 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
| 629 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
| 629 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'), |
|
| 630 | 630 | 'messengers_to_activate_with' => array('email'), |
| 631 | 631 | 'messengers_to_validate_with' => array('email'), |
| 632 | 632 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | //register payment declined message type |
| 637 | 637 | $setup_args = array( |
| 638 | 638 | 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
| 639 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
| 639 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'), |
|
| 640 | 640 | 'messengers_to_activate_with' => array('email'), |
| 641 | 641 | 'messengers_to_validate_with' => array('email'), |
| 642 | 642 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | //register registration declined message type |
| 647 | 647 | $setup_args = array( |
| 648 | 648 | 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
| 649 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
| 649 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'), |
|
| 650 | 650 | 'messengers_to_activate_with' => array('email'), |
| 651 | 651 | 'messengers_to_validate_with' => array('email'), |
| 652 | 652 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | //register registration cancelled message type |
| 657 | 657 | $setup_args = array( |
| 658 | 658 | 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
| 659 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
| 659 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'), |
|
| 660 | 660 | 'messengers_to_activate_with' => array('email'), |
| 661 | 661 | 'messengers_to_validate_with' => array('email'), |
| 662 | 662 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | //register payment failed message type |
| 668 | 668 | $setup_args = array( |
| 669 | 669 | 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
| 670 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
| 670 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'), |
|
| 671 | 671 | 'messengers_to_activate_with' => array('email'), |
| 672 | 672 | 'messengers_to_validate_with' => array('email'), |
| 673 | 673 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | //register payment declined message type |
| 678 | 678 | $setup_args = array( |
| 679 | 679 | 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
| 680 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
| 680 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'), |
|
| 681 | 681 | 'messengers_to_activate_with' => array('email'), |
| 682 | 682 | 'messengers_to_validate_with' => array('email'), |
| 683 | 683 | 'messengers_supporting_default_template_pack_with' => array('email') |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | { |
| 698 | 698 | $setup_args = array( |
| 699 | 699 | 'autoloadpaths' => array( |
| 700 | - EE_CAF_LIBRARIES . 'shortcodes/' |
|
| 700 | + EE_CAF_LIBRARIES.'shortcodes/' |
|
| 701 | 701 | ), |
| 702 | 702 | 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
| 703 | 703 | 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |