load->model("user_activity_log_model"); } public function deregister_waitlist($cancellation, $update_status = true) { $deregisteredWLSubcriber = false; // Get number of reserved seats $reserved_seats = $this->db->select('wait_list_id, number_of_places') ->from('event_wait_list') ->where('event_id', $cancellation['event_id']) ->where('wait_list_subscriber', $cancellation['user_id']) ->where('status', 1) ->get() ->row(); $deregStatus = 1; if($reserved_seats->number_of_places == $cancellation['seats_cancelled']){ $deregStatus = 0; } // Change subscriber status $this->db->query(" UPDATE event_wait_list SET number_of_places = (CASE WHEN (number_of_places - ?) <= 0 THEN 0 ELSE (number_of_places- ?) END), status = ? WHERE event_schedule_id =? AND wait_list_subscriber = ? AND status =1", array($cancellation['seats_cancelled'], $cancellation['seats_cancelled'], $deregStatus, $cancellation['event_schedule_id'], $cancellation['user_id'])); $this->db->insert('event_wait_list_deregistration', array( 'wait_list_id' => $reserved_seats->wait_list_id, 'event_schedule_id' => $cancellation['event_schedule_id'], 'wait_list_subscriber' => $cancellation['user_id'], // 'seats_reserve' => $cancellation['seats_cancelled'], 'seats_reserve' => $reserved_seats->number_of_places, 'number_of_place' => $cancellation['seats_cancelled'], 'user_agent' => $cancellation['user_agent'] ) ); //get the deregistration id $deregisteredWLSubcriber = $this->db->insert_id(); // Cancel Guests // $this->db->where('inviter_id', $cancellation['user_id']); // $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); // $this->db->update('event_subscriber_guest', array('status' => 0)); if ($update_status) { // Free reserved seats from taken seats $freed_seats = 'quota_waiting_list_seat+'.$cancellation['seats_cancelled']; $this->db->set('quota_waiting_list_seat', $freed_seats, FALSE); $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); $this->db->update('event_schedule'); // Update event_status $check_seats = $this->db->select('quota_waiting_list_seat') ->from('event_schedule') ->where('event_schedule_id', $cancellation['event_schedule_id']) ->limit(1) ->get() ->row(); $current_remaining_seats = $this->get_remaining_seats($cancellation['event_id'], $cancellation['event_schedule_id']); if($current_remaining_seats > 0){ if(!empty($cancellation['seat_feature']) && $cancellation['seat_feature']==1){ //single date $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); $this->db->where('auto_event_status', 1); } else if(!empty($cancellation['seat_feature']) && $cancellation['seat_feature']==2){ //combined date $this->db->where('event_id', $cancellation['event_id']); $this->db->where('auto_event_status', 1); } $this->db->update('event_schedule', array('event_status' => "AVAILABLE", 'back_office_status' => 2)); $event_schedule_id = $cancellation['event_schedule_id']; $log_desc = "User {$cancellation['user_id']} cancelled subscription. The event schedule is reopened for normal registration. Event status changed from Full to Available."; $act_log = $this->user_activity_log_model->add_activity_log(array( "description" => $log_desc." - event_schedule_id : ".$this->db->escape($event_schedule_id), "user_id" => $_SESSION["logged_in"]["user_id"], "action" => "EDIT", "table_origin" => "event_schedule", "reference_id" => $event_schedule_id )); } else if($check_seats->quota_waiting_list_seat > 0){ $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); $this->db->update('event_schedule', array('event_status' => "FULL", 'back_office_status' => 2)); $event_schedule_id = $cancellation['event_schedule_id']; $log_desc = "User {$cancellation['user_id']} cancelled subscription. The event schedule is reopened for waitlist registration. Backoffice status changed from locked to open."; $act_log = $this->user_activity_log_model->add_activity_log(array( "description" => $log_desc." - event_schedule_id : ".$this->db->escape($event_schedule_id), "user_id" => $_SESSION["logged_in"]["user_id"], "action" => "EDIT", "table_origin" => "event_schedule", "reference_id" => $event_schedule_id )); } } // Update event concurrent process $this->db->set('process_status', 0); $this->db->where('login_id', $cancellation['login_id']); $this->db->where('process_type', $cancellation['process_type']); $this->db->update('event_concurrent_process'); return $deregisteredWLSubcriber; } private function get_remaining_seats($event_id, $event_schedule_id){ $query = $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 e.status = 1 and es.event_id = ? and es.event_schedule_id = ? limit 1 ", array($event_id, $event_schedule_id)); $row = $query->row(); if($row){ return $row->remaining_seat; }return 0; } }