load->model("user_activity_log_model"); } public function deregister($cancellation, $update_status = true) { $deregisteredSubcriber = false; // Get number of guest $subscriber_details = $this->db->select('registration_id, number_of_guest') ->from('event_registration') ->where('event_schedule_id', $cancellation['event_schedule_id']) ->where('subscriber', $cancellation['user_id']) ->where('status', 1) ->get() ->row(); $deregStatus = 1; if(($subscriber_details->number_of_guest+1) == $cancellation['seats_cancelled']){ $deregStatus = 0; } // Change registered subscriber status $this->db->query(" UPDATE event_registration SET number_of_guest = (CASE WHEN (number_of_guest - ?) <= 0 THEN 0 ELSE (number_of_guest- ?) END), status = ? WHERE event_schedule_id =? AND subscriber = ? AND status =1", array($cancellation['seats_cancelled'], $cancellation['seats_cancelled'], $deregStatus, $cancellation['event_schedule_id'], $cancellation['user_id'])); // Insert deregistration record - Client $this->db->insert('event_deregistration', array( 'registration_id' => $subscriber_details->registration_id, 'event_schedule_id' => $cancellation['event_schedule_id'], 'subscriber' => $cancellation['user_id'], 'seats_reserve' => $subscriber_details->number_of_guest+1, 'number_of_place' => $cancellation['seats_cancelled'], 'user_agent' => $cancellation['user_agent'] ) ); //get the deregistration id $deregisteredSubcriber = $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)); //ibalik so seats if($cancellation['seat_feature'] == SEAT_FEATURE['per_date']){ $this->revert_seats_to_event_table($cancellation, $update_status); } else if($cancellation['seat_feature'] == SEAT_FEATURE['combined']){ $this->revert_seats_to_event_schedule_table($cancellation, $update_status); } // 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 $deregisteredSubcriber; } private function revert_seats_to_event_table($cancellation, $update_status = true){ // Free seats taken up by canceled clients $reserved_seats = 'remaining_seat+'.$cancellation['seats_cancelled']; $this->db->set('remaining_seat', $reserved_seats, FALSE); $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); $this->db->update('event_schedule'); if ($update_status) { // Update event_status $check_seats = $this->db->select('remaining_seat, event_status') ->from('event_schedule') ->where('event_schedule_id', $cancellation['event_schedule_id']) ->limit(1) ->get() ->row(); if($check_seats->remaining_seat > 0 /*&& $check_seats->event_status != 'FULL'*/){ if($check_seats->event_status == 'FULL') { $this->load->model('event_wait_list_model'); /** * If the seat feature is combined, make sure to update the affected records in the WL * reset the moderation of the subscribers in the WL so that once the event * becomes available again the subscriber who are already * in the WL can now reserve in the event regardless of the moderation */ $this->event_wait_list_model->resetModeratedReservationsFronWaitingListByEventSchedule($cancellation['event_schedule_id']); } $this->db->where('event_schedule_id', $cancellation['event_schedule_id']); $this->db->where("auto_event_status !=", 0); $this->db->update('event_schedule', array('event_status' => "AVAILABLE", 'back_office_status' => BO_STAT['ouv'])); $event_schedule_id = $cancellation['event_schedule_id']; $log_desc = "User {$cancellation['user_id']} cancelled registration. Event is reopened for 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 )); } } } private function revert_seats_to_event_schedule_table($cancellation, $update_status = true){ //get free remaining seat $pastRecord = $this->countCombinedRemainingSeat($cancellation['event_id']); // Free seats taken up by canceled clients $reserved_seats = 'remaining_combined_seat+'.$cancellation['seats_cancelled']; $this->db->set('remaining_combined_seat', $reserved_seats, FALSE); $this->db->where('event_id', $cancellation['event_id']); $this->db->update('event'); if ($update_status) { // Update event_status $check_seats = $this->db->select('remaining_combined_seat') ->from('event') ->where('event_id', $cancellation['event_id']) ->limit(1) ->get() ->row(); if($check_seats->remaining_combined_seat > 0){ if($pastRecord->remaining_combined_seat <=0) { $this->load->model('event_wait_list_model'); /** * If the seat feature is combined, make sure to update the affected records in the WL * reset the moderation of the subscribers in the WL so that once the event * becomes available again the subscriber who are already * in the WL can now reserve in the event regardless of the moderation */ $this->event_wait_list_model->resetModeratedReservationsFronWaitingListByEvent($cancellation['event_id']); } $this->db->where('event_id', $cancellation['event_id']); $this->db->where("event_status = 'FULL'"); $this->db->where_in('back_office_status', [ BO_STAT['ouv'], BO_STAT['ver'] ]); $this->db->where("auto_event_status !=", 0); $this->db->update('event_schedule', array('event_status' => "AVAILABLE", 'back_office_status' => BO_STAT['ouv'])); $event_schedule_id = $cancellation['event_schedule_id']; $log_desc = "User {$cancellation['user_id']} cancelled registration. Event is reopened for 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 )); } } } /** * Get the remaining seat for combined date feature * @method countCombinedRemainingSeat * @param int $eventId * @return sdtClass */ private function countCombinedRemainingSeat(int $eventId) :stdClass { // Update event_status return $this->db->select('remaining_combined_seat') ->from('event') ->where('event_id', $eventId) ->limit(1) ->get() ->row(); } }