You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
308 lines
14 KiB
308 lines
14 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
use app\core\auth\User as UserAuth;
|
|
use app\core\utils\Response;
|
|
|
|
class Reservations extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
$this->my_parent_controller();
|
|
$this->load->model("event_model");
|
|
}
|
|
|
|
public function filter_reservations($res_type)
|
|
{
|
|
Response::handleSessionTimeout("fo");
|
|
|
|
/*
|
|
* Check if input is safe from xss attack
|
|
*/
|
|
if (
|
|
!$this->security->xss_clean($this->input->get('month'), TRUE) ||
|
|
!$this->security->xss_clean($this->input->get('type'), TRUE) ||
|
|
!$this->security->xss_clean($this->input->get('city'), TRUE) ||
|
|
!$this->security->xss_clean($this->input->get('page'), TRUE) ||
|
|
!$this->security->xss_clean($this->input->get('search'), TRUE)
|
|
) {
|
|
show_404();
|
|
}
|
|
|
|
$month = $this->input->get('month');
|
|
$type = (int)$this->input->get('type');
|
|
$city = $this->input->get('city');
|
|
$page = (int)$this->input->get('page');
|
|
$search = $this->input->get('search');
|
|
|
|
$logged_in = UserAuth::isAuth();
|
|
|
|
$filter = 'all';
|
|
|
|
$query = $this->event_model->filter_event_reservations($filter, $page, $month, $type, $city, $this->data['logged_in']['user_id'], false, $res_type, $search);
|
|
|
|
/*
|
|
* Embed event status info in every events
|
|
* The event schedule where you will depend the status to be displayed on the front is in $query['data'][even_index]['bostatus']
|
|
* Split the bostatus, the third index is the event_schedule_id which is 2 [0,1,2]
|
|
*/
|
|
$eventIndex = 0;
|
|
foreach ($query['data'] as $event ) {
|
|
/* Get the event schedule id where bo status will be based */
|
|
$event_schedule_id = $event->event_schedule_id;
|
|
// $event_schedule_id = (explode('_', $event->bostatus))[2];
|
|
$status_details = $this->getMyResEventStatusDetails($event_schedule_id, $res_type);
|
|
/* Merge status event details and status info*/
|
|
$query['data'][$eventIndex] = array_merge((array) $event, $status_details);
|
|
$eventIndex++;
|
|
}
|
|
|
|
$result = array(
|
|
"mtype" => "success",
|
|
"mdata" => array(
|
|
'details' => $query['data'],
|
|
'pages' => $query['pagination'],
|
|
'result_count' => $query['result_count'],
|
|
'logged_in' => $query['logged_in']
|
|
)
|
|
);
|
|
|
|
output_to_json($this, $result);
|
|
}
|
|
|
|
protected function getMyResEventStatusDetails($event_schedule_id, $res_type)
|
|
{
|
|
$query_id = $event_schedule_id;
|
|
$page = 1;
|
|
|
|
$event_status = $this->event_model->check_bo_status_mres( $query_id, $page);
|
|
$is_user_active = UserAuth::isAuth();
|
|
|
|
//check weather a user can still register more than one date per event
|
|
$allowed_to_book = ($is_user_active === 1 && isset($event_status[0]->event_id))?$this->event_schedule_model->continue_registration($event_status[0]->event_id, $this->data['logged_in']['user_id'], "register", 1):true;
|
|
//check weather a user can still register for waitinglist more than one date per event
|
|
$allowed_to_book_for_wl = ($is_user_active === 1 && isset($event_status[0]->event_id))?$this->event_schedule_model->continue_registration($event_status[0]->event_id, $this->data['logged_in']['user_id'], "register", 2):true;
|
|
|
|
$checkStats = array('2FULL', '3FULL', '2AVAILABLE', '3AVAILABLE');
|
|
|
|
//get all event schedule statuses
|
|
foreach($event_status as $key=>$value){
|
|
|
|
$book_waiting_list = 0;
|
|
$subscription = array("booking_type" => 0, "seats_reserved" => 0);
|
|
|
|
if($value->back_office_status<=7 && $value->back_office_status>=1) {
|
|
if(($page == 2 && $is_user_active) || ($page == 1 && $is_user_active)){
|
|
$subscription = $this->check_subscription($value->event_schedule_id, $value->event_id, $res_type);
|
|
|
|
//display the exact date in the HP
|
|
if($page == 1 && isset($subscription["event_date"]) && !empty($subscription["event_date"])) {
|
|
if($subscription["event_date"]){
|
|
$event_status[$key] = (object) array_merge((array) $value, (array) $subscription["event_date"]);
|
|
$value = $event_status[$key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//if event is not closed
|
|
if($value->back_office_status<4 && $value->back_office_status>=2) {
|
|
|
|
if($value->back_office_status.$value->event_status == '2FULL'){
|
|
if($value->remaining_seat >= 0 && $value->quota_waiting_list_seat > 0) {
|
|
$book_waiting_list = 1;
|
|
} else {
|
|
//complete but bo status is open
|
|
$book_waiting_list = 0;
|
|
$value->back_office_status = 3;
|
|
}
|
|
}
|
|
//to make the button complete when when there's no remaining seats and waiting list seat
|
|
elseif($value->remaining_seat == 0 && $value->quota_waiting_list_seat==0 && $value->back_office_status<4 && $value->back_office_status>1 ){
|
|
|
|
$book_waiting_list = 0;
|
|
$value->back_office_status = 3;
|
|
|
|
}else{
|
|
$book_waiting_list = ( in_array($value->back_office_status.$value->event_status, $checkStats) && $value->remaining_seat <= 0 && $value->quota_waiting_list_seat >0 && $value->back_office_status<3 && $value->back_office_status>1)?1:0;
|
|
}
|
|
}
|
|
|
|
$event_status[$key]->{"book_waiting_list"} = $book_waiting_list;
|
|
$event_status[$key]->{"booking_type"} = $subscription["booking_type"];
|
|
$event_status[$key]->{"seats_reserved"} = $subscription["seats_reserved"];
|
|
$event_status[$key]->{"is_user_active"} = $is_user_active;
|
|
}
|
|
|
|
return array("event_status"=> $event_status, "allowed_to_book"=>$allowed_to_book, "allowed_to_book_for_wl" => $allowed_to_book_for_wl);
|
|
}
|
|
|
|
public function get_reservations_info($res_type)
|
|
{
|
|
Response::handleSessionTimeout("fo");
|
|
|
|
$month = $this->input->get('month');
|
|
$type = $this->input->get('type');
|
|
$city = $this->input->get('city');
|
|
$page = $this->input->get('page');
|
|
$search = $this->input->get('search');
|
|
|
|
$logged_in = UserAuth::isAuth();
|
|
|
|
if($month == 0){
|
|
if($type == 0){
|
|
if($city == 0) $filter = '_default_';
|
|
else $filter = 'city';
|
|
}
|
|
else {
|
|
if($city == 0) $filter = 'type';
|
|
else $filter = 'type_city';
|
|
}
|
|
}
|
|
else {
|
|
if($type == 0) {
|
|
if($city == 0) $filter = 'month';
|
|
else $filter = 'month_city';
|
|
}
|
|
else {
|
|
if($city == 0) $filter = 'month_type';
|
|
else $filter = 'all';
|
|
}
|
|
}
|
|
|
|
$resdata = $this->event_model->get_reservations_info($filter, $page, $month, $type, $city, $this->data['logged_in']['user_id'], false, $res_type);
|
|
|
|
$result = array(
|
|
"mtype" => "success",
|
|
"subscriber_id" => $this->data['logged_in']['user_id'],
|
|
"mdata" => array(
|
|
'normal_res' => (int) $resdata['normal_res'],
|
|
'waitlist_res' => (int) $resdata['waitlist_res'],
|
|
'total_res' => $resdata['normal_res'] + $resdata['waitlist_res'],
|
|
'nr_total_events' => (int) $resdata['nr_total_events'],
|
|
'wl_total_events' => (int) $resdata['wl_total_events'],
|
|
'mh_total_events' => (int) $resdata['mh_total_events'],
|
|
'logged_in' => $resdata['logged_in'],
|
|
'total_waitlist_active_res' => $resdata['total_waitlist_active_res'],
|
|
'total_waitlist_cancel_res' => $resdata['total_waitlist_cancel_res'],
|
|
'total_moderated_waitlist_res_events' => $resdata['total_moderated_waitlist_res_events']
|
|
)
|
|
);
|
|
|
|
output_to_json($this, $result);
|
|
}
|
|
|
|
public function check_bo_status_mres($res_type = 0)
|
|
{
|
|
$event_status = $this->event_model->check_bo_status_mres( $this->input->post('query_id'), $this->input->post('page'));
|
|
$is_user_active = UserAuth::isAuth();
|
|
|
|
//check weather a user can still register more than one date per event
|
|
$allowed_to_book = ($is_user_active === 1 && isset($event_status[0]->event_id))?$this->event_schedule_model->continue_registration($event_status[0]->event_id, $this->data['logged_in']['user_id'], "register", 1):true;
|
|
//check weather a user can still register for waitinglist more than one date per event
|
|
$allowed_to_book_for_wl = ($is_user_active === 1 && isset($event_status[0]->event_id))?$this->event_schedule_model->continue_registration($event_status[0]->event_id, $this->data['logged_in']['user_id'], "register", 2):true;
|
|
|
|
$checkStats = array('2FULL', '3FULL', '2AVAILABLE', '3AVAILABLE');
|
|
|
|
//get all event schedule statuses
|
|
foreach($event_status as $key=>$value){
|
|
|
|
$book_waiting_list = 0;
|
|
$subscription = array("booking_type" => 0, "seats_reserved" => 0);
|
|
|
|
if($value->back_office_status<=7 && $value->back_office_status>=1) {
|
|
if(($this->input->post('page') == 2 && $is_user_active) || ($this->input->post('page') == 1 && $is_user_active)){
|
|
$subscription = $this->check_subscription($value->event_schedule_id, $value->event_id, $res_type);
|
|
|
|
//display the exact date in the HP
|
|
if($this->input->post('page') == 1 && isset($subscription["event_date"]) && !empty($subscription["event_date"])) {
|
|
if($subscription["event_date"]){
|
|
$event_status[$key] = (object) array_merge((array) $value, (array) $subscription["event_date"]);
|
|
$value = $event_status[$key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//if event is not closed
|
|
if($value->back_office_status<4 && $value->back_office_status>=2) {
|
|
|
|
if($value->back_office_status.$value->event_status == '2FULL'){
|
|
if($value->remaining_seat >= 0 && $value->quota_waiting_list_seat > 0) {
|
|
$book_waiting_list = 1;
|
|
} else {
|
|
//complete but bo status is open
|
|
$book_waiting_list = 0;
|
|
$value->back_office_status = 3;
|
|
}
|
|
}
|
|
//to make the button complete when when there's no remaining seats and waiting list seat
|
|
elseif($value->remaining_seat == 0 && $value->quota_waiting_list_seat==0 && $value->back_office_status<4 && $value->back_office_status>1 ){
|
|
|
|
$book_waiting_list = 0;
|
|
$value->back_office_status = 3;
|
|
|
|
}else{
|
|
$book_waiting_list = ( in_array($value->back_office_status.$value->event_status, $checkStats) && $value->remaining_seat <= 0 && $value->quota_waiting_list_seat >0 && $value->back_office_status<3 && $value->back_office_status>1)?1:0;
|
|
}
|
|
}
|
|
|
|
$event_status[$key]->{"book_waiting_list"} = $book_waiting_list;
|
|
$event_status[$key]->{"booking_type"} = $subscription["booking_type"];
|
|
$event_status[$key]->{"seats_reserved"} = $subscription["seats_reserved"];
|
|
$event_status[$key]->{"is_user_active"} = $is_user_active;
|
|
}
|
|
|
|
output_to_json($this, array("event_status"=> $event_status, "allowed_to_book"=>$allowed_to_book, "allowed_to_book_for_wl" => $allowed_to_book_for_wl));
|
|
}
|
|
|
|
public function check_subscription($event_schedule_id, $event_id, $res_type=0)
|
|
{
|
|
$this->load->model('event_registration_model');
|
|
$this->load->model('event_wait_list_model');
|
|
$this->load->model('event_schedule_model');
|
|
|
|
$user_id = $this->data['logged_in']['user_id'];
|
|
|
|
$subscribed = $this->event_registration_model->count_all_event_subscription_for_my_reservations($user_id, $event_schedule_id, $event_id);
|
|
|
|
/*
|
|
* If the user is subscribed to normal reservation and res type is 0(reservations) OR
|
|
* If the user is subscribed and res_type is 1 (get my reservations history)
|
|
* get reservations info
|
|
* else get reservations in waitlist
|
|
*/
|
|
if(($subscribed && $res_type == 0) || ($subscribed && $res_type == 1)) {
|
|
$event_date = $this->event_schedule_model->get_date_of_reservation_for_my_reservations($event_schedule_id, $event_id, $user_id, 1, $res_type);
|
|
return array("booking_type" => 1, "seats_reserved" => (($event_date)?$event_date->seats_reserved:$subscribed), "event_date" => $event_date); //Booked in normal registration
|
|
} else {
|
|
$subscribed_waitlist = $this->event_wait_list_model->count_all_waitlist_subscription_for_myres_history($user_id, $event_schedule_id, $event_id);
|
|
if($subscribed_waitlist){
|
|
//check if event is re-opened and has seats available if yes then, must changed button to reserver
|
|
$booking_type = 2;
|
|
if($this->event_model->check_seats($event_schedule_id, 1)){
|
|
$booking_type = 0;
|
|
}
|
|
$event_date = $this->event_schedule_model->get_date_of_reservation_for_my_reservations($event_schedule_id, $event_id, $user_id, 2, 2);
|
|
return array("booking_type" => $booking_type, "seats_reserved" => (($event_date)?$event_date->seats_reserved:$subscribed_waitlist), "event_date" => $event_date); //booked in waiting list
|
|
}
|
|
}
|
|
return array("booking_type" => 0, "seats_reserved" => 0);
|
|
}
|
|
|
|
public function get_reservation_start_date($id = null)
|
|
{
|
|
$message['msg'] ="Ouverture des descriptions <br>".$this->event_model->reservation_start_date(true,$id)->reservation_start_date;
|
|
|
|
output_to_json($this,$message);
|
|
}
|
|
|
|
public function check_all_sched(){
|
|
$event_status = $this->event_model->check_all_sched($this->input->post('event_id'));
|
|
output_to_json($this,$event_status);
|
|
}
|
|
|
|
public function check_all_end_sched(){
|
|
$event_status = $this->event_model->check_all_end_sched($this->input->post('event_id'));
|
|
output_to_json($this,$event_status);
|
|
}
|
|
}
|
|
|