'ASC'); // default order public function __construct() { parent::__construct(); $this->array = []; } /* * Return main query for datatable */ private function _get_datatables_query($data_source,$event_schedule_id,$type){ $_search = ""; $_ordey_by = ""; $data = array(); $_query = ""; switch ($type) { case 1: $_query = $this->query_table($event_schedule_id); break; case 0 : $_query = $this->query_table_waitlist($event_schedule_id); break; } // if datatable send POST for search if($data_source['search']['value']) { $i = 0; foreach ($this->column_search as $item) {// loop column if($i===0){ // first loop array_push($data, "%".$data_source['search']['value']."%"); $_search .= " AND ( ".$this->db->escape_str($item)." LIKE ? "; } else { array_push($data, "%".$data_source['search']['value']."%"); $_search .= " OR ".$this->db->escape_str($item)." LIKE ? "; } $i++; } $_search .= ")"; } if(isset($data_source['order'])) { // here order processing if(isset($data_source['order']['0']['dir'])) { $_ordey_by .= " ORDER BY ".$this->db->escape_str($this->column_order[$data_source['order']['0']['column']])." ".$this->db->escape_str($data_source['order']['0']['dir']); } } else if(isset($this->order)) { $_ordey_by .= " ORDER BY ".$this->db->escape_str(key($this->order))." ".$this->db->escape_str($this->order[key($this->order)]); }else{ $_ordey_by=""; } return array("query"=>$_query["query"].$_search.$_query["groupby"].$_ordey_by, "data" =>$data); } public function get_datatables($data_source, $event_schedule_id,$type){ $_query = $this->_get_datatables_query($data_source, $event_schedule_id,$type); if($data_source['length'] != -1){ $_query["query"] .= " LIMIT ".$this->db->escape_str($data_source['start']).", ".$this->db->escape_str($data_source['length']); } $data = $this->db->query($_query["query"], $_query["data"]); return $data->result(); } public function count_filtered($data_source, $event_schedule_id, $type){ $_query = $this->_get_datatables_query($data_source, $event_schedule_id, $type); return $this->db->query($_query["query"], $_query["data"])->num_rows(); } public function count_all($data_source, $event_schedule_id, $type){ $_query = $this->_get_datatables_query($data_source, $event_schedule_id, $type); return $this->db->query($_query["query"], $_query["data"])->num_rows(); } public function extra_people($event_schedule_id) { $query = $this->query_table($event_schedule_id); $result = $this->db->query(" SELECT walk_in_id, first_name, last_name, email_address, note FROM event_attendance_walk_in WHERE event_schedule_id = ? ", array($event_schedule_id)); return $result->result(); } public function confirmed($event_schedule_id) { $query = $this->query_table($event_schedule_id); $result = $this->db->query( $query['query']); return $result->result(); } public function waitlist($event_schedule_id) { $query = $this->query_table_waitlist($event_schedule_id); $result = $this->db->query( $query['query']); return $result->result(); } public function check_has_registration_id($registration_id) { $this->db->select("registration_id"); $this->db->where('registration_id', $registration_id); $result = $this->db->get("event_registration"); if($result->num_rows() > 0) { return true; } } public function check_has_wait_list_id($waitlist_id) { $this->db->select("wait_list_id"); $this->db->where('wait_list_id', $waitlist_id); $result = $this->db->get("event_wait_list"); if($result->num_rows() > 0) { return true; } } public function check_has_remaining_seats($event_schedule_id) { $result = $this->db->query("SELECT (CASE WHEN e.seat_feature = 2 THEN e.remaining_combined_seat ELSE es.remaining_seat END) as remaining_seat from event_schedule es left join event e ON e.event_id = es.event_id where es.back_office_status NOT IN(0,7,6) and es.event_schedule_id = ? limit 1 ", array($event_schedule_id)); if($result->num_rows() > 0) { $ret = $result->row(); return $ret->remaining_seat; } return false; } private function query_table($event_schedule_id) { return array("query" =>" SELECT ( SELECT ev.title FROM event ev LEFT JOIN event_schedule evs ON ev.event_id = evs.event_id WHERE evs.event_schedule_id = ".$this->db->escape($event_schedule_id)." ) as event_name, er.registration_id as registration_id, er.date_time as reservation_date, (CASE WHEN er.status = 1 THEN 'Confirmed' WHEN er.status = 0 THEN 'Withdrawn' END) AS type, CONCAT(u.first_name,' ',u.last_name) as users_name, (er.number_of_guest + 1) as no_of_place, ( SELECT ea.note FROM event_attendance ea WHERE ea.registration_id = er.registration_id ) as comment, ( SELECT ea.is_attended FROM event_attendance ea WHERE ea.registration_id = er.registration_id ) as no_show_type, ( SELECT ea.attendance_id FROM event_attendance ea WHERE ea.registration_id = er.registration_id ) as attendance_id FROM event_registration er LEFT JOIN user u ON er.subscriber = u.user_id WHERE er.status = 1 AND er.event_schedule_id = ".$this->db->escape($event_schedule_id)." " ,"groupby" => "" ); } private function query_table_waitlist($event_schedule_id) { return array("query" =>" SELECT ( SELECT ev.title FROM event ev LEFT JOIN event_schedule evs ON ev.event_id = evs.event_id WHERE evs.event_schedule_id = ".$this->db->escape($event_schedule_id)." ) as event_name, ewl.wait_list_id as registration_id, ewl.date_time as reservation_date, (CASE WHEN ewl.status = 1 THEN 'Waitlist' WHEN ewl.status = 0 THEN 'Cancelled' END) AS type, CONCAT(u.first_name,' ',u.last_name) as users_name, ewl.number_of_places as no_of_place, ( SELECT ea.note FROM event_attendance ea WHERE ea.registration_id = ewl.wait_list_id ) as comment, ( SELECT ea.is_attended FROM event_attendance ea WHERE ea.registration_id = ewl.wait_list_id ) as no_show_type FROM event_wait_list ewl LEFT JOIN user u ON ewl.wait_list_subscriber = u.user_id WHERE ewl.status = 1 AND ewl.event_schedule_id = ".$this->db->escape($event_schedule_id)." " ,"groupby" => "" ); } public function get_event_name_by_schedule_id($event_schedule_id) { $query = "SELECT ev.title, DATE_FORMAT(evs.start_date_time, '%e/%m/%Y') AS date_month, DATE_FORMAT(evs.end_date_time, '%Hh%i') AS hour FROM event ev LEFT JOIN event_schedule evs ON ev.event_id = evs.event_id WHERE evs.event_schedule_id = ".$this->db->escape($event_schedule_id)." AND evs.back_office_status NOT IN(6) AND ev.status = 1 "; $result = $this->db->query($query); if($result->num_rows() > 0){ $ret = $result->row(); return [ "title" =>$ret->title, "date_month" => $ret->date_month, "hour" => $ret->hour ]; } else { return false; } } public function check_exist_walkin($walkinid){ $this->db->select("walk_in_id"); $this->db->where('walk_in_id', $walkinid); $result = $this->db->get("event_attendance_walk_in"); if($result->num_rows() > 0){ return "true"; } } public function insert_walkin($event_schedule_id, $walkinid,$name,$last,$email,$comment) { $this->db->insert("event_attendance_walk_in", array( 'event_schedule_id' => $event_schedule_id, "first_name" => $name, 'last_name' => $last, 'email_address' => $email, 'note' => $comment, 'date_time' => date('Y-m-d h:m:s') )); } public function update_walkin($event_schedule_id, $walkinid,$name,$last,$email,$comment) { $this->db->where('walk_in_id', $walkinid); $this->db->update("event_attendance_walk_in", array( "first_name" => $name, 'last_name' => $last, 'email_address' => $email, 'note' => $comment, 'date_time' => date('Y-m-d h:m:s') )); } public function save_import_confirmed_waitlist($type, $author,$registration_id,$no_show,$note, $added_via=1) { if( strtolower( $type ) == "confirmed") $type = 1; else if( strtolower($type) == "waitlist") $type = 0; if( !is_numeric($no_show) ){ $is_attended = 0; }else{ $is_attended = $no_show; } if( $this->check_exist_attendance($registration_id) == "true"){ $this->db->where('registration_id', $registration_id); $this->db->update("event_attendance", array( 'is_attended' => $is_attended, 'note' => $note, 'date_attended' => date('Y-m-d h:m:s'), 'added_via' => $added_via, 'author' => $author, 'date_created' => date('Y-m-d h:m:s') )); }else{ $this->db->insert("event_attendance", array( 'registration_id' => $registration_id, "attendance_type" => $type, 'is_attended' => $is_attended, 'note' => $note, 'date_attended' => date('Y-m-d h:m:s'), 'added_via' => $added_via, 'author' => $author, 'date_created' => date('Y-m-d h:m:s') )); } } public function update_noshows($author) { $arr = []; $note = ""; $is_attended = null; $registration_id = null; $validated = false; $type = null; foreach ($_POST as $key => $params) { if( $key != 'no_show_list_length'){ $post = explode('_', $key); $registration_id = is_numeric( $post[1] ) ? $post[1] : ''; if( $post[0] == "isattended" ) { if( !is_numeric($params) ){ $is_attended = 0; }else{ $is_attended = $params; } } if( !empty( strtolower($post[2]))) $type = strtolower($post[2]) == "confirmed" ? 1 : 0; $note = $post[0] == "notes" ? $params : ''; if( $this->greater_no_place_single("event_registration","registration_id",$is_attended, $type, $registration_id) || $this->greater_no_place_single("event_wait_list","wait_list_id",$is_attended, $type, $registration_id) ){ output_to_json($this,array( "_input" => "#".$registration_id, "mtype" => "error", "message" => $this->lang->line("invalid_place") )) ; break; }else{ if( $this->check_exist_attendance($registration_id) == "true"){ $this->db->where('registration_id', $registration_id); $this->db->update("event_attendance", array( 'attendance_type' => $type, 'is_attended' => $is_attended, 'note' => $note, 'date_attended' => date('Y-m-d h:m:s'), 'added_via' => 2, 'author' => $author, 'date_created' => date('Y-m-d h:m:s') )); }else{ $this->db->insert("event_attendance", array( 'registration_id' => $registration_id, 'attendance_type' => $type, 'is_attended' => $is_attended, 'note' => $note, 'date_attended' => date('Y-m-d h:m:s'), 'added_via' => 2, 'author' => $author, 'date_created' => date('Y-m-d h:m:s') )); } } } } } private function check_exist_attendance($registration_id){ $this->db->select("registration_id"); $this->db->where('registration_id', $registration_id); $result = $this->db->get("event_attendance"); if($result->num_rows() > 0){ return "true"; } } public function greater_no_place_single($table,$id,$no_show, $type, $registration_id) { $this->db->select(( $id=="registration_id") ? "number_of_guest" : "number_of_places"); $this->db->where($id, $registration_id); $result = $this->db->get($table); if($result->num_rows() > 0){ $ret = $result->row(); $greater = ( $id=="registration_id") ? ( $ret->number_of_guest + 1) : ( $ret->number_of_places); if( $no_show > $greater ){ return true; }else{ return false; } } } public function greater_no_place($no_show, $type, $registration_id) { if($type=="confirmed") { $this->db->select("number_of_guest"); $this->db->where('registration_id', $registration_id); $result = $this->db->get("event_registration"); if($result->num_rows() > 0){ $ret = $result->row(); if( $no_show > ( $ret->number_of_guest + 1) ){ return true; } } } else if( $type=="waitlist") { $this->db->select("number_of_places"); $this->db->where('wait_list_id', $registration_id); $result = $this->db->get("event_wait_list"); if($result->num_rows() > 0){ $ret = $result->row(); if( $no_show > ( $ret->number_of_places) ){ return true; } } } } public function count_walkin($event_schedule_id) { $this->db->select("*"); $this->db->where('event_schedule_id', $event_schedule_id); $result = $this->db->get("event_attendance_walk_in"); return $result->num_rows(); } }