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.
1440 lines
60 KiB
1440 lines
60 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
use app\core\auth\User as UserAuth;
|
|
|
|
class Event_schedule_model extends CI_Model {
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$this->load->model("user_activity_log_model");
|
|
$this->load->model("event_wait_list_model");
|
|
}
|
|
|
|
public function get_event_schedule($event_id) {
|
|
return $this->db
|
|
->select('es.*')
|
|
->from('event_schedule as es')
|
|
->join("event as e", "e.event_id = es.event_id")
|
|
->where('es.event_id', $event_id)
|
|
->get()
|
|
->result();
|
|
}
|
|
|
|
public function get_all_event_schedule($event_id){
|
|
$this->db->select("*");
|
|
$this->db->select("(CASE
|
|
WHEN e.seat_feature = 2 THEN e.total_combined_seat
|
|
ELSE es.total_available_seat
|
|
END) AS avl_seats", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.reservation_start_date, '%e/%m/%Y %Hh%i') AS reservation_start_date", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.reservation_end_date IS NULL
|
|
THEN \"\"
|
|
ELSE DATE_FORMAT(es.reservation_end_date, '%e/%m/%Y %Hh%i')
|
|
END) as reservation_end_date", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.address IS NULL
|
|
THEN \"\"
|
|
ELSE es.address
|
|
END) as address", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.city_location IS NULL
|
|
THEN \"\"
|
|
ELSE es.city_location
|
|
END) as city_location", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.code_postal IS NULL
|
|
THEN \"\"
|
|
ELSE es.code_postal
|
|
END) as code_postal", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.location IS NULL
|
|
THEN \"\"
|
|
ELSE es.location
|
|
END) as location", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.city_name IS NULL
|
|
THEN \"\"
|
|
ELSE es.city_name
|
|
END) as city_name", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.event_url IS NULL
|
|
THEN \"\"
|
|
ELSE es.event_url
|
|
END) as event_url", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.start_date_time, '%e/%m/%Y %Hh%i') AS start_date_time", FALSE);
|
|
$this->db->select("e.seat_feature AS seat_feature", FALSE);
|
|
$this->db->select("e.date_feature AS date_feature", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.end_date_time, '%e/%m/%Y %Hh%i') AS end_date_time", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
|
|
ELSE es.remaining_seat
|
|
END) AS rem_seats", FALSE);
|
|
$this->db->where("es.back_office_status NOT IN(6)");
|
|
$this->db->where("es.event_id", $event_id);
|
|
$this->db->from("event_schedule es");
|
|
$this->db->join("event e", "e.event_id = es.event_id");
|
|
return $this->db->get()->result();
|
|
}
|
|
|
|
public function preview_get_all_event_schedule($event_id){
|
|
$this->db->select("*");
|
|
$this->db->select("(CASE
|
|
WHEN e.seat_feature = 2 THEN e.total_combined_seat
|
|
ELSE es.total_available_seat
|
|
END) AS avl_seats", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.reservation_start_date, '%e/%m/%Y %Hh%i') AS reservation_start_date", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.reservation_end_date IS NULL
|
|
THEN \"\"
|
|
ELSE DATE_FORMAT(es.reservation_end_date, '%e/%m/%Y %Hh%i')
|
|
END) as reservation_end_date", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.address IS NULL
|
|
THEN \"\"
|
|
ELSE es.address
|
|
END) as address", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.city_location IS NULL
|
|
THEN \"\"
|
|
ELSE es.city_location
|
|
END) as city_location", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.code_postal IS NULL
|
|
THEN \"\"
|
|
ELSE es.code_postal
|
|
END) as code_postal", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.location IS NULL
|
|
THEN \"\"
|
|
ELSE es.location
|
|
END) as location", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN es.city_name IS NULL
|
|
THEN \"\"
|
|
ELSE es.city_name
|
|
END) as city_name", FALSE);
|
|
//$this->db->select("DATE_FORMAT(es.start_date_time, '%e/%m/%Y %Hh%i') AS start_date_time", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.start_date_time, '%Hh%i') AS start_date_hour", FALSE);
|
|
$this->db->select("e.seat_feature AS seat_feature", FALSE);
|
|
$this->db->select("e.date_feature AS date_feature", FALSE);
|
|
//$this->db->select("DATE_FORMAT(es.end_date_time, '%e/%m/%Y %Hh%i') AS end_date_time", FALSE);
|
|
$this->db->select("DATE_FORMAT(es.end_date_time, '%Hh%i') AS end_date_hour", FALSE);
|
|
$this->db->select("(CASE
|
|
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
|
|
ELSE es.remaining_seat
|
|
END) AS rem_seats", FALSE);
|
|
$this->db->where("es.back_office_status NOT IN(6)");
|
|
$this->db->where("es.event_id", $event_id);
|
|
$this->db->from("event_schedule es");
|
|
$this->db->join("event e", "e.event_id = es.event_id");
|
|
return $this->db->get()->result();
|
|
}
|
|
|
|
public function change_seat_feature($user_id, $seat_feature, $event_id){
|
|
|
|
if($seat_feature == 2){
|
|
$this->db->where("event_id", $event_id);
|
|
$this->db->update("event_schedule", array("total_available_seat" => 0, "remaining_seat" => 0));
|
|
} else if($seat_feature == 1) {
|
|
$this->db->where("event_id", $event_id);
|
|
$this->db->update("event", array("total_combined_seat" => 0, "remaining_combined_seat" =>0));
|
|
}
|
|
}
|
|
|
|
|
|
public function add_event_schedule($user_id, $event_id, $event_schedules, $event_data) {
|
|
$this->load->model('event_moderation_model');
|
|
$this->load->model('event_registration_paid_event_model');
|
|
|
|
//lets insert them one by one
|
|
$errors = array();
|
|
foreach ($event_schedules as $index => $event_sched) {
|
|
/*
|
|
* holds variable for event_schedule_moderation_settings
|
|
* reset moderation variables per event schedule
|
|
*/
|
|
$moderationVariables = [];
|
|
|
|
if($event_sched){
|
|
//filter event dates
|
|
$event_sched = $this->filter_event_dates((array)$event_sched);
|
|
//for reservation date formatting
|
|
$event_sched['reservation_end_date'] = $this->filter_event_date($event_data['reservation_end_date']);
|
|
$event_sched['reservation_start_date'] = $this->filter_event_date($event_data['reservation_start_date']);
|
|
//add event_id
|
|
$event_sched["event_id"] = $event_id;
|
|
//add author
|
|
$event_sched["author"] = $user_id;
|
|
$event_sched["city_location"] = $event_data["city_location"];
|
|
$event_sched["address"] = $event_data["address"];
|
|
$event_sched["rate"] = empty($event_data["rate"]) ? "0" : $event_data["rate"];
|
|
//postal code
|
|
$event_sched["code_postal"] = (int) ($event_data["code_postal"] ?? 0);
|
|
|
|
|
|
//set the total available seats as remaining seats
|
|
$event_sched["total_available_seat"] = (int) ($event_data["total_available_seat"] ?? 0);
|
|
|
|
$event_sched["remaining_seat"] = (int) ($event_data["total_available_seat"] ?? 0);
|
|
|
|
$event_sched["seats_per_subscriber"] = (int) ($event_data["seats_per_subscriber"] ?? 0);
|
|
|
|
$event_sched["event_status"] = !isset($event_data["event_status"]) ? 'AVAILABLE' : $event_data["event_status"];
|
|
|
|
$event_sched["quota_waiting_list_seat"] = (int) ($event_data["total_quota_waiting_list_seat"] ?? 0);
|
|
|
|
$event_sched["total_quota_waiting_list_seat"] = (int) ($event_data["total_quota_waiting_list_seat"] ?? 0);
|
|
|
|
// status: complete
|
|
if(
|
|
$event_data["event_status"] == 'FULL' &&
|
|
(
|
|
$event_sched["back_office_status"] == 0 ||
|
|
$event_sched["back_office_status"] == 1 ||
|
|
$event_sched["back_office_status"] == 7 ||
|
|
empty($event_sched["back_office_status"] )
|
|
)
|
|
) {
|
|
$event_sched["back_office_status"] = 2;
|
|
$event_sched["event_status"] = "FULL";
|
|
} elseif ($event_data["event_status"] == 'FULL') {
|
|
$event_sched["event_status"] = "FULL";
|
|
}
|
|
// status: being created
|
|
if($event_data["back_office_status"] == 0 || !isset($event_data["back_office_status"])) {
|
|
$event_sched["back_office_status"] = 0;
|
|
$event_sched["event_status"] = "AVAILABLE";
|
|
}
|
|
|
|
|
|
//checking for past event
|
|
$event_sched["back_office_status"] = $this->recheck_bo_status($event_data);
|
|
|
|
//changing status of 2 to 4
|
|
if($event_sched["back_office_status"] >1 && $event_sched["back_office_status"] <4) {
|
|
|
|
$seat_feature = isset($event_data['seat_feature']) ? $event_data['seat_feature'] : 0;
|
|
$event_sched['rem_seats'] = ($seat_feature == 2) ? $event_data['remaining_combined_seat'] : 0;
|
|
$event_sched['seat_feature'] = $seat_feature;
|
|
|
|
$event_sched = $this->revalidate_bo_status_by_seat_avl($event_sched);
|
|
|
|
unset($event_sched['rem_seats'], $event_sched['seat_feature']);
|
|
}
|
|
if (isset($event_sched['total_available_remaining_seat'])) {
|
|
unset($event_sched['total_available_remaining_seat']);
|
|
}
|
|
|
|
|
|
/**
|
|
* This condition will store first the actual value and unset after storing to avoid conflict
|
|
* - prepare list of collection for event_schedule_moderation_settings
|
|
*/
|
|
//Unset 'Activer la Modération'
|
|
if (isAvailablePostKey($event_data, 'adapt_cur_mod_settings')) {
|
|
$moderationVariables['adapt_cur_mod_settings'] = ($event_data['adapt_cur_mod_settings'] == 'on' ? 1: 0);
|
|
unset($event_sched['adapt_cur_mod_settings']);
|
|
}
|
|
if (isAvailablePostKey($event_sched, 'moderationSwitchBtn')) {
|
|
$moderationVariables['mod_stat'] = ($event_sched['moderationSwitchBtn'] == 'on' ? 1: 0);
|
|
unset($event_sched['moderationSwitchBtn']);
|
|
}
|
|
|
|
//Unset 'Modération Flexible'
|
|
if (isAvailablePostKey($event_sched, 'moderationSwitchFlexibleBtn')) {
|
|
$moderationVariables['flex_mod_stat'] = ($event_sched['moderationSwitchFlexibleBtn'] == 'on' ? 1: 0);
|
|
unset($event_sched['moderationSwitchFlexibleBtn']);
|
|
}
|
|
|
|
//Unset 'Désactivation de la modération [] heures '
|
|
if (isAvailablePostKey($event_sched, 'flex_no_of_hours')) {
|
|
$moderationVariables['hrs_bef_event_closes'] = ($event_sched['flex_no_of_hours']?:0);
|
|
unset($event_sched['flex_no_of_hours']);
|
|
} else {
|
|
// code...
|
|
}
|
|
|
|
//Unset 'avant la date de fin de la réservation S'il reste % de places vacantes.'
|
|
if (isAvailablePostKey($event_data, 'flex_places_to_lift_moderation')) {
|
|
$moderationVariables['places_volume'] = ($event_data['flex_places_to_lift_moderation']?:0);
|
|
unset($event_sched['flex_places_to_lift_moderation']);
|
|
} else {
|
|
// code...
|
|
}
|
|
|
|
unset($event_sched['noshow']);
|
|
/**
|
|
* End of collection for event_moderation_settings
|
|
*/
|
|
|
|
|
|
$this->db->insert("event_schedule", $event_sched);
|
|
$event_schedule_id = $this->db->insert_id();
|
|
|
|
/**
|
|
* Insert new Moderation settings for event schedule created
|
|
*/
|
|
// addEventScheduleModerationForm($event_schedule_id,$moderationVariables);
|
|
|
|
if ($event_schedule_id) {
|
|
// Get event_category
|
|
$event_category = $this->event_registration_paid_event_model->get_event_category($event_sched['event_id']);
|
|
|
|
// Only regular events will get moderation settings
|
|
if ($event_category && $event_category === 'REGULAR_EVENT') {
|
|
$this->event_moderation_model->saveEvSchedModSettings($event_schedule_id, $moderationVariables);
|
|
}
|
|
|
|
// Add event template by default
|
|
$this->add_event_email_schedule_status($event_schedule_id, $event_id);
|
|
} else{
|
|
$errors[] = $index;
|
|
}
|
|
} else {
|
|
$errors[] = $index;
|
|
}
|
|
}
|
|
return (sizeof($errors) > 0)?false:true;
|
|
}
|
|
|
|
public function update_event_schedule($user_id, $event_id, $event_schedules, $event_data) {
|
|
//lets insert them one by one
|
|
$errors = array();
|
|
foreach ($event_schedules as $index => $event_sched) {
|
|
|
|
if($event_sched){
|
|
//filter event dates
|
|
$event_sched = $this->filter_event_dates((array)$event_sched);
|
|
//for reservation date formatting
|
|
$event_sched['reservation_end_date'] = $this->filter_event_date($event_data['reservation_end_date']);
|
|
$event_sched['reservation_start_date'] = $this->filter_event_date($event_data['reservation_start_date']);
|
|
//add event_id
|
|
$event_sched["event_id"] = $event_id;
|
|
//add author
|
|
$event_sched["author"] = $user_id;
|
|
$event_sched["city_location"] = $event_data["city_location"];
|
|
$event_sched["address"] = $event_data["address"];
|
|
$event_sched["rate"] = $event_data["rate"];
|
|
//postal code
|
|
$event_sched["code_postal"] = (int) ($event_data["code_postal"] ?? 0);
|
|
|
|
|
|
//set the total available seats as remaining seats
|
|
$event_sched["total_available_seat"] = (int) ($event_data["total_available_seat"] ?? 0);
|
|
|
|
$event_sched["remaining_seat"] = (int) ($event_data["total_available_seat"] ?? 0);
|
|
|
|
$event_sched["seats_per_subscriber"] = (int) ($event_data["seats_per_subscriber"] ?? 0);
|
|
|
|
$event_sched["event_status"] = !isset($event_data["event_status"]) ? 'AVAILABLE' : $event_data["event_status"];
|
|
|
|
$event_sched["quota_waiting_list_seat"] = (int) ($event_data["total_quota_waiting_list_seat"] ?? 0);
|
|
|
|
$event_sched["total_quota_waiting_list_seat"] = (int) ($event_data["total_quota_waiting_list_seat"] ?? 0);
|
|
|
|
|
|
//checking for past event
|
|
$event_sched["back_office_status"] = $this->recheck_bo_status($event_data);
|
|
$this->db->insert("event_schedule", $event_sched);
|
|
$event_schedule_id = $this->db->insert_id();
|
|
} else {
|
|
$errors[] = $index;
|
|
}
|
|
}
|
|
return (sizeof($errors) > 0)?false:true;
|
|
}
|
|
|
|
public function multi_update_evsched_status($user_id, $target_status, $ev_sched_ids){
|
|
$all_updated = true;
|
|
if(count($ev_sched_ids) > 0){
|
|
$this->db->trans_begin();
|
|
foreach ($ev_sched_ids as $key => $id) {
|
|
$this->db->where("event_schedule_id", $id);
|
|
$update = $this->db->update("event_schedule", array("back_office_status" => $target_status));
|
|
if (!$update) {
|
|
$all_updated = false;
|
|
$this->db->trans_rollback();
|
|
return false;
|
|
}
|
|
}
|
|
$this->db->trans_commit();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*For wl reservation*/
|
|
public function check_quota_wl($event_schedule_id, $total_quota_waiting_list_seat){
|
|
$this->load->model('event_wait_list_model');
|
|
$count_registration = $this->event_wait_list_model->count_wl_registration_by_event_schedule($event_schedule_id);
|
|
|
|
if($count_registration){
|
|
if($total_quota_waiting_list_seat >= $count_registration){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public function retrieve_combined_event_seats_from_cancelled($event_schedule_id){
|
|
// get total consumed seats in canceled event
|
|
$count_registration = $this->event_registration_model->count_registration_by_event_schedule($event_schedule_id);
|
|
// re add the total consumed seats in cancelled event schedule to the event
|
|
$event_id = ($this->db->query("
|
|
SELECT event_id
|
|
FROM event_schedule
|
|
WHERE event_schedule_id = ?
|
|
LIMIT 1
|
|
", array($event_schedule_id))->row())->event_id;
|
|
|
|
$event_seats = $this->get_event_sched_combined_seats_info($event_id);
|
|
// total seats
|
|
$avl_com_seats = $event_seats['avl_com_seats'];
|
|
|
|
// new remaining seats after cancellation
|
|
$rem_com_seats = $event_seats['rem_com_seats'] + $count_registration;
|
|
|
|
|
|
// update seats
|
|
$result = $this->db->query("
|
|
UPDATE event e
|
|
SET e.remaining_combined_seat = ?
|
|
WHERE event_id =?", array($rem_com_seats, $event_id));
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
// return;
|
|
}
|
|
|
|
/*For normal reservation */
|
|
public function check_available_places($event_schedule_id, $total_available_seat, $seat_feature = 1){
|
|
$this->load->model('event_registration_model');
|
|
if ($seat_feature == 1) {
|
|
$count_registration = $this->event_registration_model->count_registration_by_event_schedule($event_schedule_id);
|
|
|
|
if($count_registration){
|
|
if($total_available_seat >= $count_registration){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
} else {
|
|
$event_id = ($this->db->query("
|
|
SELECT event_id
|
|
FROM event_schedule
|
|
WHERE event_schedule_id = ?
|
|
LIMIT 1
|
|
", array($event_schedule_id))->row())->event_id;
|
|
|
|
$event_seats = $this->get_event_sched_combined_seats_info($event_id);
|
|
// total seats
|
|
$avl_com_seats = $event_seats['avl_com_seats'];
|
|
$rem_com_seats = $event_seats['rem_com_seats'];
|
|
$seats_occupied = $avl_com_seats - $rem_com_seats;
|
|
if ($avl_com_seats >= $seats_occupied) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private function recalculate_event_seats($event_schedule_id, $input_seats, $event_sched, $type=1){
|
|
$seats_info = $this->get_event_sched_seats_info($event_schedule_id, $type);
|
|
$seats_adjustment = (int) $input_seats - (int) $seats_info["avl_com_seats"];
|
|
$new_total = $seats_info["avl_com_seats"] + $seats_adjustment;
|
|
$new_rem = $seats_info["rem_com_seats"] + $seats_adjustment;
|
|
|
|
$event_sched[(($type==1)?'total_available_seat':'total_quota_waiting_list_seat')] = $new_total ?? 0;
|
|
$event_sched[(($type==1)?'remaining_seat':'quota_waiting_list_seat')] = $new_rem ?? 0;
|
|
|
|
$new_total = $new_total?? 0;
|
|
if ($seats_info["avl_com_seats"] != $new_total) {
|
|
if ($type == 1) {
|
|
$event_sched['seats_changed_msg'] = isset($new_total)? "Available seats changed from {$seats_info["avl_com_seats"]} to {$new_total}.":'';
|
|
} else {
|
|
if (!isset($event_sched['seats_changed_msg'])) {
|
|
$event_sched['seats_changed_msg'] = isset($new_total)? "Available WL seats changed from {$seats_info["avl_com_seats"]} to {$new_total}.":'';
|
|
} else {
|
|
$event_sched['seats_changed_msg'] .= isset($new_total)? " Available WL seats changed from {$seats_info["avl_com_seats"]} to {$new_total}.":'';
|
|
}
|
|
}
|
|
} else {
|
|
if (!isset($event_sched['seats_changed_msg'])) {
|
|
$event_sched['seats_changed_msg'] ='';
|
|
}
|
|
}
|
|
|
|
return $event_sched;
|
|
}
|
|
|
|
public function get_event_sched_seats_info($event_schedule_id, $type=1){
|
|
$selectType = array("total_available_seat, remaining_seat",
|
|
"total_quota_waiting_list_seat, quota_waiting_list_seat");
|
|
$result = $this->db->query("
|
|
SELECT ".$selectType[($type-1)]."
|
|
FROM event_schedule
|
|
WHERE event_schedule_id = ?
|
|
LIMIT 1
|
|
", array($event_schedule_id))->row();
|
|
|
|
if($type==1){
|
|
return array(
|
|
"avl_com_seats" => $result->total_available_seat,
|
|
"rem_com_seats" => $result->remaining_seat);
|
|
} else {
|
|
return array(
|
|
"avl_com_seats" => $result->total_quota_waiting_list_seat,
|
|
"rem_com_seats" => $result->quota_waiting_list_seat);
|
|
}
|
|
}
|
|
|
|
public function get_event_sched_combined_seats_info($event_id){
|
|
$result = $this->db->query("
|
|
SELECT total_combined_seat, remaining_combined_seat
|
|
FROM event
|
|
WHERE event_id = ?
|
|
LIMIT 1
|
|
", array($event_id))->row();
|
|
|
|
return array("avl_com_seats" => $result->total_combined_seat,
|
|
"rem_com_seats" => $result->remaining_combined_seat);
|
|
}
|
|
|
|
/*Validate back office status by seat available*/
|
|
private function revalidate_bo_status_by_seat_avl($event_sched){
|
|
// $event_sched["avl_wl_seats"], $event_sched["rem_wl_seats"],
|
|
//extract remaining seats
|
|
$rem_seats = ($event_sched["seat_feature"] <= 1) ? $event_sched["remaining_seat"]:$event_sched["rem_seats"];
|
|
$rem_wl_seats = ($event_sched["seat_feature"] <= 1) ? $event_sched["remaining_seat"]:$event_sched["rem_seats"];
|
|
if($event_sched["event_status"] !== 'FULL' || (isset($event_sched["remaining_seat"]) && ($event_sched["remaining_seat"] > $event_sched['rem_seats'])) ||
|
|
($event_sched["event_status"] == 'FULL')) {
|
|
|
|
if (
|
|
$event_sched["event_status"] == "CANCEL" &&
|
|
(
|
|
$event_sched["back_office_status"] == 2
|
|
|| $event_sched["back_office_status"] == 3
|
|
|| $event_sched["back_office_status"] == 5
|
|
)
|
|
) {
|
|
$event_sched["event_status"] = "CANCEL";
|
|
} else {
|
|
if (
|
|
$event_sched["event_status"] == 'FULL' &&
|
|
(
|
|
$event_sched["back_office_status"] == 0 ||
|
|
$event_sched["back_office_status"] == 1 ||
|
|
$event_sched["back_office_status"] == 7 ||
|
|
empty($event_sched["back_office_status"] )
|
|
)
|
|
) {
|
|
$event_sched["back_office_status"] = 2;
|
|
// $event_sched["event_status"] = "FULL";
|
|
|
|
} else if(((
|
|
$rem_seats <= 0 || $event_sched['event_status'] =='FULL') &&
|
|
$event_sched["quota_waiting_list_seat"] > 0 &&
|
|
$event_sched["back_office_status"]==3) /* prev => 2*/ || $event_sched["event_status"] == "AVAILABLE") {
|
|
|
|
$event_sched["back_office_status"] = 2; //event is open for WL reservation
|
|
// $event_sched["event_status"] = "FULL";
|
|
} elseif((($rem_seats <= 0 || $event_sched['event_status'] =='FULL') &&
|
|
$event_sched["quota_waiting_list_seat"] <= 0 && ($event_sched["back_office_status"]==2))){
|
|
|
|
$event_sched["back_office_status"] = 3; //event is open for Regular reservation1
|
|
// $event_sched["event_status"] = "AVAILABLE";
|
|
|
|
} else if($rem_seats <= 0 && $event_sched["quota_waiting_list_seat"] <= 0){
|
|
|
|
$event_sched["back_office_status"] = 3; //event is Locked
|
|
// $event_sched["event_status"] = "FULL";
|
|
|
|
} else if($rem_seats <= 0 && $event_sched["quota_waiting_list_seat"] > 0 && ($event_sched["back_office_status"]==3 /* prev => 2*/) ) {
|
|
|
|
$event_sched["back_office_status"] = 2; //event is open for WL reservation
|
|
// $event_sched["event_status"] = "FULL";
|
|
}
|
|
|
|
if (!isset($event_sched['reservation_start_date']) && $event_sched["back_office_status"] == 1) {
|
|
$event_sched["back_office_status"] = 2;
|
|
}
|
|
}
|
|
}
|
|
return $event_sched;
|
|
}
|
|
|
|
private function recheck_bo_status($event_sched)
|
|
{
|
|
//checking for past event
|
|
if (
|
|
$event_sched["event_status"] == "CANCEL" &&
|
|
(
|
|
in_array($event_sched["back_office_status"], array(0,1,2,3,4,5,7))
|
|
)
|
|
) {
|
|
return $event_sched["back_office_status"];
|
|
}
|
|
if(!empty($event_sched["start_date_time"]) && empty($event_sched["end_date_time"])) {
|
|
if (strtotime(date("Y-m-d H:i:s")) > strtotime(date($event_sched["start_date_time"]))) {
|
|
if(!in_array($event_sched["back_office_status"], array(5,0))) { //not yet archived/encours
|
|
return 4; //closed event
|
|
}
|
|
}
|
|
}else if(!empty($event_sched["end_date_time"])){
|
|
if (strtotime(date("Y-m-d H:i:s")) > strtotime(date($event_sched["end_date_time"]))) {
|
|
if(!in_array($event_sched["back_office_status"], array(5,0))) { //not yet archived/encours
|
|
return 4; //closed event
|
|
}
|
|
}
|
|
}
|
|
|
|
return $event_sched["back_office_status"];
|
|
}
|
|
|
|
public function get_event_sched_details($event_schedule_id=0){
|
|
$this->db->select('*');
|
|
$this->db->from('event_schedule');
|
|
$this->db->where("event_schedule_id", $event_schedule_id);
|
|
$query = $this->db->get();
|
|
return $query->row();
|
|
}
|
|
|
|
public function delete_event_schedule($event_schedule_id=0){
|
|
//update also all event schedule status to deleted
|
|
$this->db->where("event_schedule_id", $event_schedule_id);
|
|
$this->db->update("event_schedule", array("back_office_status" => 6));
|
|
return $this->db->affected_rows();
|
|
}
|
|
|
|
public function delete_event_schedules_by_event_id($event_id, $where=[]) {
|
|
$this->db
|
|
->where(['event_id' => $event_id])
|
|
->where($where)
|
|
->delete('event_schedule');
|
|
|
|
return $this->db->affected_rows();
|
|
}
|
|
|
|
private function defer_sending_of_on_queue_emails($event_schedule_id){
|
|
$this->db->where("event_schedule_id", $event_schedule_id);
|
|
$this->db->where_in("email_status", array(0,2,3));
|
|
$this->db->update("event_email_recipient", array("email_status" => 5, "email_date_time" => date('Y-m-d H:i:s')));
|
|
|
|
//email schedules must be set to pass
|
|
$this->db->where("event_schedule_id", $event_schedule_id);
|
|
$this->db->where_in("email_schedule_status", array(1));
|
|
$this->db->update("event_email_schedule", array("email_schedule_status" => 2, "email_schedule_date_added" => date('Y-m-d H:i:s')));
|
|
}
|
|
|
|
//filter event dates input
|
|
private function filter_event_dates($event_sched){
|
|
$filter = ["start_date_time", "end_date_time"];
|
|
foreach($event_sched as $key => $value){
|
|
|
|
if(in_array($key, $filter)){
|
|
if($value && !empty($value)) {
|
|
$new_date = date_create($value);
|
|
$event_sched[$key] = date_format($new_date, 'Y-m-d H:i:s');
|
|
} else{
|
|
$event_sched[$key] = null;
|
|
}
|
|
}
|
|
}
|
|
return $event_sched;
|
|
}
|
|
|
|
private function filter_event_date($date){
|
|
$new_date = date_create($date);
|
|
return date_format($new_date, 'Y-m-d H:i:s');
|
|
}
|
|
|
|
public function add_event_email_schedule_status($event_schedule_id, $event_id){
|
|
$this->db->query("INSERT INTO event_schedule_email_status(event_schedule_id, email_type_id, status, event_id)
|
|
(SELECT ?, eett.email_type_id, 1, ?
|
|
FROM event_email_template_type eett
|
|
WHERE eett.email_type_status = 1 )",
|
|
array($event_schedule_id, $event_id)
|
|
);
|
|
}
|
|
|
|
public function update_combined_feature_event_dates($event_id, $remaining_combined_seat){
|
|
|
|
if($remaining_combined_seat > 0){
|
|
//make all locked or for waiting list event dates open if not open
|
|
$this->db->query(" UPDATE event_schedule
|
|
SET back_office_status = 2, event_status='AVAILABLE'
|
|
WHERE back_office_status IN (2,3)
|
|
AND event_status = 'FULL'
|
|
AND auto_event_status != 0
|
|
AND
|
|
(CASE
|
|
WHEN reservation_end_date IS NULL THEN start_date_time
|
|
ELSE reservation_end_date
|
|
END) > NOW()
|
|
AND event_id = ?
|
|
", array($event_id)); //events are open for reservation
|
|
} else {
|
|
//make all locked or for waiting list event dates open if not open
|
|
$this->db->query(" UPDATE event_schedule
|
|
SET back_office_status = (CASE
|
|
WHEN quota_waiting_list_seat > 0 THEN 2
|
|
ELSE 3
|
|
END),
|
|
event_status = 'FULL'
|
|
WHERE back_office_status = 2
|
|
AND event_status = 'AVAILABLE'
|
|
AND
|
|
(CASE
|
|
WHEN reservation_end_date IS NULL THEN start_date_time
|
|
ELSE reservation_end_date
|
|
END) > NOW()
|
|
AND event_id = ?
|
|
", array($event_id)); //events full
|
|
}
|
|
}
|
|
|
|
public function use_diffent_address(){
|
|
return "(CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = es.city_location AND ecl.status =1)
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = e.city_location AND ecl.status =1)
|
|
END)
|
|
END) as event_venue,
|
|
(CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.address IS NULL THEN \"\"
|
|
ELSE es.address
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.address IS NULL THEN \"\"
|
|
ELSE e.address
|
|
END)
|
|
END) as event_address,
|
|
|
|
(CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.location IS NULL THEN \"\"
|
|
ELSE es.location
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.location IS NULL THEN \"\"
|
|
ELSE e.location
|
|
END)
|
|
END) as event_place_name,
|
|
|
|
(CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.code_postal IS NULL OR es.code_postal < 1 THEN \"\"
|
|
ELSE es.code_postal
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.code_postal IS NULL OR e.code_postal < 1 THEN \"\"
|
|
ELSE e.code_postal
|
|
END)
|
|
END) as event_postal_code,
|
|
|
|
(CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.city_name IS NULL THEN \"\"
|
|
ELSE es.city_name
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.city_name IS NULL THEN \"\"
|
|
ELSE e.city_name
|
|
END)
|
|
END) as city,";
|
|
}
|
|
|
|
public function query_date($alias = "es"){
|
|
return ", (CASE
|
|
WHEN ".$alias.".reservation_start_date IS NULL THEN \"\"
|
|
ELSE ".$alias.".reservation_start_date
|
|
END) as reservation_start_date,
|
|
(CASE
|
|
WHEN ".$alias.".reservation_end_date IS NULL THEN \"\"
|
|
ELSE ".$alias.".reservation_end_date
|
|
END) as reservation_end_date,
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%e/%m/%Y')
|
|
END) AS start_date,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".end_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%e/%m/%Y')
|
|
END) AS end_date,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DAYNAME(".$alias.".start_date_time)
|
|
END) AS day,
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DAYNAME(".$alias.".end_date_time)
|
|
END) AS endday,
|
|
|
|
(CASE
|
|
WHEN DATE_FORMAT(".$alias.".start_date_time, '%Hh%i') = '00h00' THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%Hh%i')
|
|
END) AS start_date_hour,
|
|
|
|
(CASE
|
|
WHEN DATE_FORMAT(".$alias.".end_date_time, '%Hh%i') = '00h00' THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%Hh%i')
|
|
END) AS end_date_hour,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%e')
|
|
END) AS start_day,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".end_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%e')
|
|
END) AS end_day,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%m')
|
|
END) AS start_month,
|
|
|
|
(CASE
|
|
WHEN DATE_FORMAT(".$alias.".end_date_time, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%M')
|
|
END) AS end_month,
|
|
|
|
(CASE
|
|
WHEN DATE_FORMAT(".$alias.".reservation_start_date, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".reservation_start_date, '%M')
|
|
END) AS reservation_start_month,
|
|
|
|
(CASE
|
|
WHEN DATE_FORMAT(".$alias.".reservation_end_date, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".reservation_end_date, '%M')
|
|
END) AS end_reservation_month,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%Y')
|
|
END) AS start_year,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".end_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%Y')
|
|
END) AS end_year,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%e %M %Y')
|
|
END) AS start_date_day,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%e %M')
|
|
END) AS start_date_month,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".end_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".end_date_time, '%e %M')
|
|
END) AS end_date_month,
|
|
|
|
".$alias.".start_date_time AS event_start_date_time,
|
|
|
|
".$alias.".end_date_time AS event_end_date_time,
|
|
|
|
(CASE
|
|
WHEN ".$alias.".start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(".$alias.".start_date_time, '%M')
|
|
END) AS event_start_month_name ";
|
|
}
|
|
|
|
public function list_event_schedule($event_id = 0, $preview = 0, $include_archived_events = false)
|
|
{
|
|
if ($event_id) {
|
|
$include_being_created = '';
|
|
$include_archived_event = '5,';
|
|
|
|
if ($preview == 0) {
|
|
$include_being_created = '0, ';
|
|
}
|
|
if ($include_archived_events) {
|
|
$include_archived_event = '';
|
|
}
|
|
|
|
return $this->db->query("SELECT es.event_schedule_id,
|
|
es.start_date_time,
|
|
es.end_date_time,
|
|
es.total_available_seat,
|
|
es.seats_per_subscriber,
|
|
es.quota_waiting_list_seat,
|
|
es.remaining_seat, es.event_status, es.back_office_status,
|
|
(
|
|
CASE
|
|
WHEN es.start_date_time >= NOW()
|
|
THEN 'coming_soon'
|
|
ELSE ''
|
|
END
|
|
) as is_coming_soon,
|
|
(CASE
|
|
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
|
|
ELSE es.remaining_seat
|
|
END) as remaining_seat,
|
|
".$this->use_diffent_address()."
|
|
e.seat_feature,
|
|
(CASE WHEN e.rate > 0 THEN e.rate ELSE \"\" END) as event_rate,
|
|
e.event_category,
|
|
es.event_url,
|
|
es.item_code,
|
|
e.is_favorite,
|
|
e.is_multiple_reservation,
|
|
e.is_multiple_waitlist_reservation
|
|
".$this->query_date().",
|
|
(CASE WHEN gsv.gm_mod_stat = 0 THEN 0 ELSE ges.mod_stat END) AS mod_stat
|
|
FROM event_schedule es
|
|
LEFT JOIN event e ON e.event_id = es.event_id
|
|
LEFT JOIN gm_evsched_setting ges USING(event_schedule_id)
|
|
LEFT JOIN gm_settings_view gsv USING(gm_id)
|
|
WHERE
|
|
es.event_id = ?
|
|
AND
|
|
es.back_office_status NOT IN({$include_being_created} {$include_archived_event} 6)
|
|
AND
|
|
e.status != 0
|
|
ORDER BY
|
|
es.start_date_time ASC
|
|
", $event_id)->result();
|
|
}
|
|
return array();
|
|
}
|
|
|
|
public function event_schedule_details($event_id, $request_type=0){
|
|
|
|
$select = "title";
|
|
|
|
if($request_type === "cancel"){
|
|
$select = "back_office_status ";
|
|
} else {
|
|
$select ="title, remaining_combined_seat as remaining_seat,
|
|
seat_feature,
|
|
date_feature,
|
|
is_multiple_reservation,
|
|
is_multiple_waitlist_reservation,
|
|
event_status,
|
|
(CASE
|
|
WHEN reservation_start_date IS NULL THEN \"\"
|
|
ELSE reservation_start_date
|
|
END) as reservation_start_date,
|
|
(CASE
|
|
WHEN reservation_end_date IS NULL THEN \"\"
|
|
ELSE reservation_end_date
|
|
END) as reservation_end_date,
|
|
(CASE
|
|
WHEN start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(start_date_time, '%M')
|
|
END) AS event_start_month_name,
|
|
(CASE
|
|
WHEN DATE_FORMAT(end_date_time, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(end_date_time, '%M')
|
|
END) AS end_month,
|
|
(CASE
|
|
WHEN DATE_FORMAT(reservation_end_date, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(reservation_end_date, '%M')
|
|
END) AS end_reservation_month,
|
|
end_date_time,
|
|
start_date_time,
|
|
back_office_status,
|
|
event_id";
|
|
}
|
|
|
|
return $this->db->query("select ".$select."
|
|
from event
|
|
where status = 1
|
|
and event_id = ?
|
|
limit 1", array($event_id))->row();
|
|
}
|
|
|
|
public function event_schedule_information($event_schedule_id){
|
|
|
|
$select ="es.event_id,
|
|
es.quota_waiting_list_seat,
|
|
es.event_status,
|
|
(CASE
|
|
WHEN es.reservation_start_date IS NULL THEN \"\"
|
|
ELSE es.reservation_start_date
|
|
END) as reservation_start_date,
|
|
(CASE
|
|
WHEN es.reservation_end_date IS NULL THEN \"\"
|
|
ELSE es.reservation_end_date
|
|
END) as reservation_end_date,
|
|
(CASE
|
|
WHEN es.start_date_time IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(es.start_date_time, '%M')
|
|
END) AS event_start_month_name,
|
|
(CASE
|
|
WHEN DATE_FORMAT(es.end_date_time, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(es.end_date_time, '%M')
|
|
END) AS end_month,
|
|
(CASE
|
|
WHEN DATE_FORMAT(es.reservation_end_date, '%M') IS NULL THEN \"\"
|
|
ELSE DATE_FORMAT(es.reservation_end_date, '%M')
|
|
END) AS end_reservation_month,
|
|
es.end_date_time,
|
|
es.start_date_time,
|
|
es.back_office_status,
|
|
es.event_schedule_id,
|
|
es.seats_per_subscriber
|
|
";
|
|
|
|
return $this->db->query("select ".$select."
|
|
from event_schedule es
|
|
where es.event_schedule_id = ?", array($event_schedule_id))->row();
|
|
}
|
|
|
|
public function list_register_event_schedule($event_id = 0, $subscriber){
|
|
if($event_id){
|
|
return $this->db->query("SELECT es.event_schedule_id, es.start_date_time, es.end_date_time, es.total_available_seat, es.seats_per_subscriber, es.quota_waiting_list_seat,
|
|
es.remaining_seat, es.event_status, es.back_office_status,
|
|
(CASE
|
|
WHEN es.back_office_status = 2 AND es.event_status ='AVAILABLE' THEN CONCAT('a - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 2 AND es.event_status ='FULL' THEN CONCAT('b - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 3 AND es.event_status ='FULL' THEN CONCAT('c - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 3 THEN CONCAT('d - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 1 THEN CONCAT('e - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 7 THEN CONCAT('f - ',es.start_date_time,' ')
|
|
WHEN es.back_office_status = 4 THEN CONCAT('g - ',es.start_date_time,' ')
|
|
ELSE CONCAT('h - ',es.start_date_time,' ')
|
|
END) as bostatus
|
|
".$this->query_date()."
|
|
FROM event_schedule es
|
|
LEFT JOIN event e ON e.event_id = es.event_id
|
|
LEFT JOIN event_registration er ON es.event_schedule_id = er.event_schedule_id
|
|
WHERE
|
|
es.event_id = ?
|
|
AND
|
|
es.back_office_status NOT IN(0,5,6)
|
|
AND
|
|
e.status != 0
|
|
AND
|
|
er.status != 0
|
|
AND
|
|
er.subscriber = $subscriber
|
|
ORDER BY
|
|
bostatus ASC,
|
|
es.start_date_time ASC
|
|
", $event_id)->result();
|
|
}
|
|
return array();
|
|
}
|
|
|
|
public function get_all_registration_details($event_id, $event_schedule_id, $reg_type, $user_id)
|
|
{
|
|
$query = false;
|
|
if (UserAuth::isLoggedInAsSubscriber()) {
|
|
$inclusions = [
|
|
BO_STAT['en_c'],
|
|
BO_STAT['pub'],
|
|
BO_STAT['ouv'],
|
|
BO_STAT['ver'],
|
|
BO_STAT['fer'],
|
|
BO_STAT['arc'],
|
|
// BO_STAT['del'],
|
|
BO_STAT['ter']
|
|
];
|
|
} else {
|
|
$inclusions = [
|
|
BO_STAT['ouv'],
|
|
BO_STAT['ver'],
|
|
];
|
|
}
|
|
if($reg_type == 1){ // regular reservation
|
|
$query = $this->db->query("
|
|
SELECT e.title, es.event_id, es.event_schedule_id,es.start_date_time,
|
|
es.back_office_status, e.status,
|
|
(CASE
|
|
WHEN er.number_of_guest = 0 OR er.number_of_guest IS NULL THEN 1
|
|
ELSE (er.number_of_guest + 1)
|
|
END) as seats_reserved,
|
|
1 as reg_type
|
|
from event_schedule es
|
|
left join event e ON e.event_id = es.event_id
|
|
left join event_registration er ON er.event_schedule_id = es.event_schedule_id
|
|
where es.event_id = ".$event_id."
|
|
AND e.event_id = ".$event_id."
|
|
AND es.event_schedule_id = ".$event_schedule_id."
|
|
AND er.subscriber = ".$user_id."
|
|
AND er.status = 1
|
|
AND e.status = 1
|
|
AND es.back_office_status IN ?", [$inclusions]);
|
|
|
|
} else if($reg_type == 2) { //waitling list reservation
|
|
|
|
$query = $this->db->query("
|
|
SELECT e.title, es.event_id, es.event_schedule_id,es.start_date_time,
|
|
es.back_office_status, e.status,
|
|
(CASE
|
|
WHEN ewl.number_of_places = 0 OR ewl.number_of_places IS NULL THEN 1
|
|
ELSE number_of_places
|
|
END) as seats_reserved,
|
|
2 as reg_type
|
|
from event_schedule es
|
|
left join event e ON e.event_id = es.event_id
|
|
left join event_wait_list ewl ON ewl.event_schedule_id = es.event_schedule_id
|
|
where es.event_id = ".$event_id."
|
|
AND e.event_id = ".$event_id."
|
|
AND ewl.wait_list_subscriber = ".$user_id."
|
|
AND es.event_schedule_id = ".$event_schedule_id."
|
|
AND ewl.status = 1
|
|
AND e.status = 1
|
|
AND es.back_office_status IN ?", [$inclusions]);
|
|
}
|
|
|
|
if(!$query && $query->num_rows() > 0){
|
|
return false;
|
|
} else {
|
|
return $query->row();
|
|
}
|
|
}
|
|
|
|
public function continue_registration($event_id, $user_id, $action, $reg_type){
|
|
if($reg_type == 1){
|
|
return $this->can_register_to_event($event_id, $user_id, $action, $reg_type);
|
|
} else if($reg_type == 2){
|
|
return $this->can_register_to_waiting_list($event_id, $user_id, $action, $reg_type);
|
|
}else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* Check if can still reserve more than 1 date per event schedule? */
|
|
public function can_register_to_event($event_id, $user_id, $action, $reg_type){
|
|
|
|
if($action=="modify" || $action=="cancel") {
|
|
return true;
|
|
} else {
|
|
|
|
$restrict = $this->get_event_registration_restriction($event_id, $reg_type);
|
|
|
|
if($restrict){
|
|
|
|
$this->load->model("event_registration_model");
|
|
// get total reservation per event
|
|
$total_reg = $this->event_registration_model->count_all_user_registration_per_event($event_id, $user_id);
|
|
|
|
if($restrict->is_multiple_reservation == 0 && $total_reg>=1){
|
|
return false; //not allowed to register, the limit has been reached already
|
|
} else {
|
|
return true;
|
|
}
|
|
} else{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Check if can still reserve more than 1 date per event schedule? */
|
|
public function can_register_to_waiting_list($event_id, $user_id, $action, $reg_type){
|
|
|
|
if($action=="modify" || $action=="cancel") {
|
|
return true;
|
|
} else {
|
|
|
|
$restrict = $this->get_event_registration_restriction($event_id, $reg_type);
|
|
|
|
if($restrict){
|
|
|
|
$this->load->model("event_wait_list_model");
|
|
// get total reservation per event
|
|
$total_reg = $this->event_wait_list_model->count_all_waitlist_user_registration_per_event($event_id, $user_id);
|
|
|
|
if( $restrict->date_feature == 2 && $restrict->is_multiple_waitlist_reservation == 0 && $total_reg >= 1 ){
|
|
return false; //not allowed to register, the limit has been reached already
|
|
} else {
|
|
return true;
|
|
}
|
|
} else{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function get_event_registration_restriction($event_id, $reg_type){
|
|
|
|
$result= $this->db->select((($reg_type == 1)?'is_multiple_reservation':'is_multiple_waitlist_reservation'))
|
|
->select('date_feature')
|
|
->from('event')
|
|
->where('event_id',$event_id)
|
|
->where_not_in('event_category', ['ONLINE_EVENT'])
|
|
->where('status',1)
|
|
->limit(1)
|
|
->get()
|
|
->row();
|
|
if($result){
|
|
return $result;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function reset_address_per_date($event_id){
|
|
$this->db->where("event_id", $event_id);
|
|
$this->db->set('city_location', 'NULL', false);
|
|
$this->db->set('address', 'NULL', false);
|
|
$this->db->set('code_postal', 'NULL', false);
|
|
$this->db->set('city_name', 'NULL', false);
|
|
$this->db->update("event_schedule");
|
|
}
|
|
|
|
public function get_date_of_reservation($event_id, $user_id, $reg_type, $page){
|
|
if($page == 1){ //on HP only
|
|
$select = "es.quota_waiting_list_seat,
|
|
es.seats_per_subscriber,
|
|
es.event_status,
|
|
(CASE
|
|
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
|
|
ELSE es.remaining_seat
|
|
END) as remaining_seat,
|
|
es.back_office_status, (CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = es.city_location AND ecl.status =1)
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = e.city_location AND ecl.status =1)
|
|
END)
|
|
END) as event_venue";
|
|
if($reg_type == 1){ //normal registration
|
|
$result = $this->db->query(
|
|
"SELECT ".$select." ".$this->query_date().
|
|
",(CASE
|
|
WHEN er.number_of_guest = 0 OR er.number_of_guest IS NULL THEN 1
|
|
ELSE (er.number_of_guest + 1)
|
|
END) as seats_reserved,
|
|
DATE_FORMAT(er.date_time, '%W') date_reserved_w,
|
|
DATE_FORMAT(er.date_time, '%d') date_reserved_d,
|
|
DATE_FORMAT(er.date_time, '%M') date_reserved_m,
|
|
DATE_FORMAT(er.date_time, '%Y') date_reserved_y,
|
|
DATE_FORMAT(er.date_time, '%Hh%i') date_reserved_time
|
|
|
|
FROM event_registration er
|
|
LEFT JOIN event_schedule es
|
|
ON es.event_schedule_id = er.event_schedule_id
|
|
LEFT JOIN event e
|
|
ON e.event_id = es.event_id
|
|
WHERE er.status =1
|
|
AND er.subscriber = ?
|
|
AND e.status = 1
|
|
AND es.event_status != 'CANCEL'
|
|
AND es.event_id = ?
|
|
AND es.back_office_status IN(1,2,3)
|
|
GROUP BY es.event_id
|
|
ORDER BY es.start_date_time ASC
|
|
LIMIT 1
|
|
", array($user_id, $event_id));
|
|
if($result->num_rows() > 0){
|
|
return $result->row();
|
|
}
|
|
return false;
|
|
|
|
} else if($reg_type == 2){ //waiting list registration
|
|
$result = $this->db->query(
|
|
"SELECT ".$select." ".$this->query_date().
|
|
", (CASE
|
|
WHEN ewl.number_of_places = 0 OR ewl.number_of_places IS NULL THEN 1
|
|
ELSE number_of_places
|
|
END) as seats_reserved,
|
|
DATE_FORMAT(ewl.date_time, '%W') date_reserved_w,
|
|
DATE_FORMAT(ewl.date_time, '%d') date_reserved_d,
|
|
DATE_FORMAT(ewl.date_time, '%M') date_reserved_m,
|
|
DATE_FORMAT(ewl.date_time, '%Y') date_reserved_y,
|
|
DATE_FORMAT(ewl.date_time, '%Hh%i') date_reserved_time
|
|
FROM event_wait_list ewl
|
|
LEFT JOIN event_schedule es
|
|
ON es.event_schedule_id = ewl.event_schedule_id
|
|
LEFT JOIN event e
|
|
ON e.event_id = es.event_id
|
|
WHERE ewl.status =1
|
|
AND ewl.wait_list_subscriber = ?
|
|
AND e.status = 1
|
|
AND es.event_status != 'CANCEL'
|
|
AND es.event_id = ?
|
|
AND es.back_office_status IN(1,2,3)
|
|
GROUP BY es.event_id
|
|
ORDER BY es.start_date_time ASC
|
|
LIMIT 1
|
|
", array($user_id, $event_id));
|
|
if($result->num_rows() > 0){
|
|
return $result->row();
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function get_date_of_reservation_for_my_reservations($event_schedule_id, $event_id, $user_id, $reg_type, $res_type){
|
|
$q_part ='';
|
|
switch ($res_type) {
|
|
case 1:
|
|
/*GET HISTORY */
|
|
$q_part = "AND (es.back_office_status NOT IN(0,6,3,1,2,7) AND es.event_status != 'CANCEL')";
|
|
break;
|
|
default:
|
|
/*Get only open events when in my reservation and waitlist tab*/
|
|
$q_part = "AND es.back_office_status NOT IN(0,5,6,4)";
|
|
break;
|
|
}
|
|
$select = "es.quota_waiting_list_seat,
|
|
es.seats_per_subscriber,
|
|
es.event_status,
|
|
(CASE
|
|
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
|
|
ELSE es.remaining_seat
|
|
END) as remaining_seat,
|
|
es.back_office_status, (CASE
|
|
WHEN e.use_different_address_per_date = 1 THEN
|
|
(CASE
|
|
WHEN es.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = es.city_location AND ecl.status =1)
|
|
END)
|
|
ELSE (CASE
|
|
WHEN e.city_location IS NULL THEN \"\"
|
|
ELSE (SELECT ecl.city FROM event_city_location ecl WHERE ecl.city_location_id = e.city_location AND ecl.status =1)
|
|
END)
|
|
END) as event_venue";
|
|
if($reg_type == 1){ //normal registration
|
|
$result = $this->db->query(
|
|
"SELECT ".$select." ".$this->query_date().
|
|
",(CASE
|
|
WHEN er.number_of_guest = 0 OR er.number_of_guest IS NULL THEN 1
|
|
ELSE (er.number_of_guest + 1)
|
|
END) as seats_reserved,
|
|
DATE_FORMAT(er.date_time, '%W') date_reserved_w,
|
|
DATE_FORMAT(er.date_time, '%d') date_reserved_d,
|
|
DATE_FORMAT(er.date_time, '%M') date_reserved_m,
|
|
DATE_FORMAT(er.date_time, '%Y') date_reserved_y,
|
|
DATE_FORMAT(er.date_time, '%Hh%i') date_reserved_time,
|
|
er.registration_id
|
|
FROM event_registration er
|
|
LEFT JOIN event_schedule es
|
|
ON es.event_schedule_id = er.event_schedule_id
|
|
LEFT JOIN event e
|
|
ON e.event_id = es.event_id
|
|
WHERE er.status =1
|
|
AND er.subscriber = ?
|
|
AND e.status = 1
|
|
AND es.event_schedule_id = ?
|
|
AND es.event_id = ?
|
|
$q_part
|
|
GROUP BY es.event_schedule_id
|
|
ORDER BY er.registration_id DESC
|
|
LIMIT 1
|
|
", array($user_id, $event_schedule_id, $event_id));
|
|
if($result->num_rows() > 0){
|
|
return $result->row();
|
|
}
|
|
return false;
|
|
|
|
} else if($reg_type == 2){ //waiting list registration
|
|
$result = $this->db->query(
|
|
"SELECT ".$select." ".$this->query_date().
|
|
", (CASE
|
|
WHEN ewl.number_of_places = 0 OR ewl.number_of_places IS NULL THEN 1
|
|
ELSE number_of_places
|
|
END) as seats_reserved,
|
|
DATE_FORMAT(ewl.date_time, '%W') date_reserved_w,
|
|
DATE_FORMAT(ewl.date_time, '%d') date_reserved_d,
|
|
DATE_FORMAT(ewl.date_time, '%M') date_reserved_m,
|
|
DATE_FORMAT(ewl.date_time, '%Y') date_reserved_y,
|
|
DATE_FORMAT(ewl.date_time, '%Hh%i') date_reserved_time,
|
|
ewl.wait_list_id
|
|
FROM event_wait_list ewl
|
|
LEFT JOIN event_schedule es
|
|
ON es.event_schedule_id = ewl.event_schedule_id
|
|
LEFT JOIN event e
|
|
ON e.event_id = es.event_id
|
|
WHERE ewl.status =1
|
|
AND ewl.wait_list_subscriber = ?
|
|
AND e.status = 1
|
|
AND es.event_schedule_id = ?
|
|
AND es.event_id = ?
|
|
GROUP BY es.event_schedule_id
|
|
ORDER BY ewl.wait_list_id DESC
|
|
LIMIT 1
|
|
", array($user_id, $event_schedule_id, $event_id));
|
|
if($result->num_rows() > 0){
|
|
return $result->row();
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function get_scheds(){
|
|
|
|
return $this->db->query("select event_schedule_id from event_schedule where back_office_status!=6")->result();
|
|
}
|
|
|
|
/**
|
|
* Check if event is an online event
|
|
* Make sure to not allow subscriber to reserver on this event
|
|
*
|
|
* @param {integer} $event_id
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_online_event($event_id) {
|
|
$this->db->select('event_id');
|
|
$this->db->from('event');
|
|
$this->db->where('event_id', $event_id);
|
|
$this->db->where_in('event_category', array('ONLINE_EVENT'));
|
|
$count = $this->db->count_all_results();
|
|
return $count ?? 0;
|
|
}
|
|
|
|
/**
|
|
* Check if event is an paid event
|
|
* Make sure to not allow subscriber to reserver on this event directly in event detailed page
|
|
*
|
|
* @param {integer} $event_id
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function is_paid_event($event_id) {
|
|
$this->db->select('event_id');
|
|
$this->db->from('event');
|
|
$this->db->where('event_id', $event_id);
|
|
$this->db->where_in('event_category', array('PAID_EVENT'));
|
|
$count = $this->db->count_all_results();
|
|
return $count ?? 0;
|
|
}
|
|
|
|
public function validate_code_selection($item_code, $event_schedule_id = 0) {
|
|
$this->db->select('es.event_schedule_id');
|
|
$this->db->from('event_schedule es');
|
|
$this->db->join('event e', 'e.event_id = es.event_id AND e.event_category = "PAID_EVENT"', 'left');
|
|
if ($event_schedule_id) {
|
|
$this->db->where('es.event_schedule_id !=', $event_schedule_id);
|
|
}
|
|
$this->db->where('es.item_code', $item_code);
|
|
$this->db->where('e.event_category', "PAID_EVENT");
|
|
$this->db->limit('1');
|
|
$count = $this->db->count_all_results();
|
|
return $count ?? 0;
|
|
}
|
|
}
|
|
|