statuses = array( 'all' => array('label'=>__('All','dbem'), 'search'=>false), 'pending' => array('label'=>__('Pending','dbem'), 'search'=>0), 'confirmed' => array('label'=>__('Confirmed','dbem'), 'search'=>1), 'cancelled' => array('label'=>__('Cancelled','dbem'), 'search'=>2), 'rejected' => array('label'=>__('Rejected','dbem'), 'search'=>3), 'needs-attention' => array('label'=>__('Needs Attention','dbem'), 'search'=>array(0)), 'incomplete' => array('label'=>__('Incomplete Bookings','dbem'), 'search'=>array(0)) ); if( !get_option('dbem_bookings_approval') ){ unset($this->statuses['pending']); unset($this->statuses['incomplete']); $this->statuses['confirmed']['search'] = array(0,1); } //Set basic vars $this->order = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'ASC'; $this->orderby = ( !empty($_REQUEST ['order']) ) ? $_REQUEST ['order']:'booking_name'; $this->limit = ( !empty($_REQUEST['limit']) ) ? $_REQUEST['limit'] : 20;//Default limit $this->page = ( !empty($_REQUEST['pno']) ) ? $_REQUEST['pno']:1; $this->offset = ( $this->page > 1 ) ? ($this->page-1)*$this->limit : 0; $this->scope = ( !empty($_REQUEST['scope']) && array_key_exists($_REQUEST ['scope'], em_get_scopes()) ) ? $_REQUEST ['scope']:get_option('dbem_default_bookings_search','future'); $this->status = ( !empty($_REQUEST['status']) && array_key_exists($_REQUEST['status'], $this->statuses) ) ? $_REQUEST['status']:get_option('dbem_default_bookings_search','needs-attention'); //build template of possible collumns $this->cols_template = apply_filters('em_bookings_table_cols_template', array( 'user_name'=>__('Name','dbem'), 'event_name'=>__('Event','dbem'), 'event_date'=>__('Event Date(s)','dbem'), 'event_time'=>__('Event Time(s)','dbem'), 'user_email'=>__('E-mail','dbem'), 'dbem_phone'=>__('Phone Number','dbem'), 'booking_spaces'=>__('Spaces','dbem'), 'booking_status'=>__('Status','dbem'), 'booking_date'=>__('Booking Date','dbem'), 'booking_price'=>__('Total','dbem'), 'booking_id'=>__('Booking ID','dbem') ), $this); $this->cols_tickets_template = apply_filters('em_bookings_table_cols_tickets_template', array( 'ticket_name'=>__('Ticket Name','dbem'), 'ticket_description'=>__('Ticket Description','dbem'), 'ticket_price'=>__('Ticket Price','dbem'), 'ticket_id'=>__('Ticket ID','dbem') ), $this); //add tickets to template if we're showing rows by booking-ticket if( $show_tickets ){ $this->show_tickets = true; $this->cols = array('user_name','event_name','ticket_name','ticket_price','booking_spaces','booking_status','actions'); $this->cols_template = array_merge( $this->cols_template, $this->cols_tickets_template); } $this->cols_template['actions'] = __('Actions','dbem'); //calculate collumns if post requests if( !empty($_REQUEST ['cols']) && !is_array($_REQUEST ['cols']) ){ $this->cols = explode(',',$_REQUEST['cols']); }elseif( !empty($_REQUEST ['cols']) ){ $this->cols = $_REQUEST['cols']; } //load collumn view settings if( $this->get_person() !== false ){ $this->cols_view = $this->get_person(); }elseif( $this->get_ticket() !== false ){ $this->cols_view = $this->get_ticket(); }elseif( $this->get_event() !== false ){ $this->cols_view = $this->get_event(); } foreach($this->cols as $col_key){ if( !array_key_exists($col_key, $this->cols_template)){ unset($this->cols[$col_key]); } } //save collumns depending on context and user preferences if( empty($_REQUEST['cols']) ){ if(!empty($this->cols_view) && is_object($this->cols_view)){ //check if user has settings for object type $settings = get_user_meta(get_current_user_id(), 'em_bookings_view-'.get_class($this->cols_view), true ); }else{ $settings = get_user_meta(get_current_user_id(), 'em_bookings_view', true ); } if( !empty($settings) ){ $this->cols = $settings; } }elseif( !empty($_REQUEST['cols']) && empty($_REQUEST['no_save']) ){ //save view settings for next time if( !empty($this->cols_view) && is_object($this->cols_view) ){ update_user_meta(get_current_user_id(), 'em_bookings_view-'.get_class($this->cols_view), $this->cols ); }else{ update_user_meta(get_current_user_id(), 'em_bookings_view', $this->cols ); } } do_action('em_bookings_table', $this); } /** * @return EM_Person|false */ function get_person(){ global $EM_Person; if( !empty($this->person) && is_object($this->person) ){ return $this->person; }elseif( !empty($_REQUEST['person_id']) && !empty($EM_Person) && is_object($EM_Person) ){ return $EM_Person; } return false; } /** * @return EM_Ticket|false */ function get_ticket(){ global $EM_Ticket; if( !empty($this->ticket) && is_object($this->ticket) ){ return $this->ticket; }elseif( !empty($EM_Ticket) && is_object($EM_Ticket) ){ return $EM_Ticket; } return false; } /** * @return $EM_Event|false */ function get_event(){ global $EM_Event; if( !empty($this->event) && is_object($this->event) ){ return $this->event; }elseif( !empty($EM_Event) && is_object($EM_Event) ){ return $EM_Event; } return false; } function get_bookings($force_refresh = true){ if( empty($this->bookings) || $force_refresh ){ $this->events = array(); $EM_Ticket = $this->get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); if( $EM_Person !== false ){ $args = array('person'=>$EM_Person->ID,'scope'=>$this->scope,'status'=>$this->get_status_search(),'order'=>$this->order,'orderby'=>$this->orderby); $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); foreach($this->bookings->bookings as $EM_Booking){ //create event if( !array_key_exists($EM_Booking->event_id,$this->events) ){ $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } }elseif( $EM_Ticket !== false ){ //searching bookings with a specific ticket $this->bookings = $EM_Ticket->get_bookings(); $this->bookings_count = (is_array($this->bookings->bookings)) ? count($this->bookings->bookings):0; $this->events[$EM_Ticket->event_id] = $EM_Ticket->get_event(); }elseif( $EM_Event !== false ){ //bookings for an event $args = array('event'=>$EM_Event->event_id,'scope'=>false,'status'=>$this->get_status_search(),'order'=>$this->order,'orderby'=>$this->orderby); $args['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id() : false; $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); $this->events[$EM_Event->event_id] = $EM_Event; }else{ //all bookings for a status $args = array('status'=>$this->get_status_search(),'scope'=>$this->scope,'order'=>$this->order,'orderby'=>$this->orderby); $args['owner'] = !current_user_can('manage_others_bookings') ? get_current_user_id() : false; $this->bookings_count = EM_Bookings::count($args); $this->bookings = EM_Bookings::get(array_merge($args, array('limit'=>$this->limit,'offset'=>$this->offset))); //Now let's create events and bookings for this instead of giving each booking an event foreach($this->bookings->bookings as $EM_Booking){ //create event if( !array_key_exists($EM_Booking->event_id,$this->events) ){ $this->events[$EM_Booking->event_id] = new EM_Event($EM_Booking->event_id); } } } } return $this->bookings; } function get_count(){ return $this->bookings_count; } function get_status_search(){ if(is_array($this->statuses[$this->status]['search'])){ return implode(',',$this->statuses[$this->status]['search']); } return $this->statuses[$this->status]['search']; } function output(){ do_action('em_bookings_table_header',$this); //won't be overwritten by JS $this->output_overlays(); $this->output_table(); do_action('em_bookings_table_footer',$this); //won't be overwritten by JS } function output_overlays(){ $EM_Ticket = $this->get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); ?>
get_ticket(); $EM_Event = $this->get_event(); $EM_Person = $this->get_person(); $this->get_bookings(true); //get bookings and refresh ?>
/wp-admin/edit.php'>
: name; ?> get_name(); ?>
bookings_count >= $this->limit ) { $bookings_nav = em_admin_paginate( $this->bookings_count, $this->limit, $this->page, array(),'#%#%','#'); echo $bookings_nav; } ?>
*/ ?> bookings_count > 0 ): ?> bookings->bookings as $EM_Booking) { ?> */ /* @var $EM_Booking EM_Booking */ /* @var $EM_Ticket_Booking EM_Ticket_Booking */ if( $this->show_tickets ){ foreach($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking){ ?>
", $this->get_headers()); ?>
', $this->get_row($EM_Ticket_Booking)); ?>', $this->get_row($EM_Booking)); ?>
bookings_count >= $this->limit ) : ?>
cols as $col){ if( $col == 'actions' ){ if( !$csv ) $headers[$col] = ' '; }elseif(array_key_exists($col, $this->cols_template)){ /* for later - col ordering! if($this->orderby == $col){ if($this->order == 'ASC'){ $headers[] = ''.$this->cols_template[$col].' (^)'; }else{ $headers[] = ''.$this->cols_template[$col].' (d)'; } }else{ $headers[] = ''.$this->cols_template[$col].''; } */ $headers[$col] = $this->cols_template[$col]; } } return $headers; } function get_table(){ } /** * @param Object $object * @return array() */ function get_row( $object, $csv = false ){ /* @var $EM_Ticket EM_Ticket */ /* @var $EM_Ticket_Booking EM_Ticket_Booking */ /* @var $EM_Booking EM_Booking */ if( get_class($object) == 'EM_Ticket_Booking' ){ $EM_Ticket_Booking = $object; $EM_Ticket = $EM_Ticket_Booking->get_ticket(); $EM_Booking = $EM_Ticket_Booking->get_booking(); }else{ $EM_Booking = $object; } $cols = array(); foreach($this->cols as $col){ //is col a user col or else? //TODO fix urls so this works in all pages in front as well if( $col == 'user_email' ){ $cols[] = $EM_Booking->get_person()->user_email; }elseif($col == 'dbem_phone'){ $cols[] = $EM_Booking->get_person()->phone; }elseif($col == 'user_name'){ if( $csv ){ $cols[] = $EM_Booking->get_person()->get_name(); }else{ $cols[] = ''. $EM_Booking->person->get_name() .''; } }elseif($col == 'event_name'){ if( $csv ){ $cols[] = $EM_Booking->get_event()->event_name; }else{ $cols[] = ''. $this->events[$EM_Booking->event_id]->name .''; } }elseif($col == 'event_date'){ $cols[] = $EM_Booking->get_event()->output('#_EVENTDATES'); }elseif($col == 'event_time'){ $cols[] = $EM_Booking->get_event()->output('#_EVENTTIMES'); }elseif($col == 'booking_price'){ $cols[] = ($this->show_tickets && !empty($EM_Ticket)) ? $EM_Ticket_Booking->get_price(false,true,true):$EM_Booking->get_price(false,true,true); }elseif($col == 'booking_status'){ $cols[] = $EM_Booking->get_status(true); }elseif($col == 'booking_date'){ $cols[] = date_i18n(get_option('dbem_date_format').' '. get_option('dbem_time_format'), $EM_Booking->timestamp); }elseif($col == 'actions' ){ if( !$csv ) $cols[] = implode(' | ', $this->get_booking_actions($EM_Booking)); }elseif( $col == 'booking_spaces' ){ $cols[] = ($this->show_tickets && !empty($EM_Ticket)) ? $EM_Ticket_Booking->get_spaces() : $EM_Booking->get_spaces(); }elseif( $col == 'booking_id' ){ $cols[] = $EM_Booking->booking_id; }elseif( $col == 'ticket_name' && $this->show_tickets && !empty($EM_Ticket) ){ $cols[] = $EM_Ticket->$col; }elseif( $col == 'ticket_description' && $this->show_tickets && !empty($EM_Ticket) ){ $cols[] = $EM_Ticket->$col; }elseif( $col == 'ticket_price' && $this->show_tickets && !empty($EM_Ticket) ){ $cols[] = $EM_Ticket->get_price(true); }elseif( $col == 'ticket_id' && $this->show_tickets && !empty($EM_Ticket) ){ $cols[] = $EM_Ticket->ticket_id; }else{ $val = apply_filters('em_bookings_table_rows_col_'.$col, '', $EM_Booking, $this, $csv); $cols[] = apply_filters('em_bookings_table_rows_col', $val, $col, $EM_Booking, $this, $csv); } } return $cols; } function get_row_csv($EM_Booking){ return $this->get_row($EM_Booking, true); } /** * @param EM_Booking $EM_Booking * @return mixed */ function get_booking_actions($EM_Booking){ $booking_actions = array(); switch($EM_Booking->booking_status){ case 0: if( get_option('dbem_bookings_approval') ){ $booking_actions = array( 'approve' => ''.__('Approve','dbem').'', 'reject' => ''.__('Reject','dbem').'', 'delete' => ''.__('Delete','dbem').'', 'edit' => ''.__('Edit/View','dbem').'', ); break; }//if approvals are off, treat as a 1 case 1: $booking_actions = array( 'unapprove' => ''.__('Unpprove','dbem').'', 'reject' => ''.__('Reject','dbem').'', 'delete' => ''.__('Delete','dbem').'', 'edit' => ''.__('Edit/View','dbem').'', ); break; case 2: $booking_actions = array( 'unapprove' => ''.__('Unpprove','dbem').'', 'approve' => ''.__('Approve','dbem').'', 'delete' => ''.__('Delete','dbem').'', 'edit' => ''.__('Edit/View','dbem').'', ); break; case 3: $booking_actions = array( 'unapprove' => ''.__('Unpprove','dbem').'', 'approve' => ''.__('Approve','dbem').'', 'delete' => ''.__('Delete','dbem').'', 'edit' => ''.__('Edit/View','dbem').'', ); break; case 4: $booking_actions = apply_filters('em_bookings_table_booking_actions_4',array( 'delete' => ''.__('Delete','dbem').'', ), $EM_Booking); break; case 5: $booking_actions = apply_filters('em_bookings_table_booking_actions_5',array( 'delete' => ''.__('Delete','dbem').'', ), $EM_Booking); break; default: $booking_actions = apply_filters('em_bookings_table_booking_actions_'.$EM_Booking->booking_status ,array(), $EM_Booking); break; } if( !get_option('dbem_bookings_approval') ) unset($booking_actions['unapprove']); return apply_filters('em_bookings_table_cols_col_action', $booking_actions, $EM_Booking); } } ?>