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.
968 lines
34 KiB
968 lines
34 KiB
<?php
|
|
/*
|
|
* @Author: Jino Lacson
|
|
* @Date: 2018-10-30 09:44:40
|
|
* @Last Modified by: jlacson@wylog.com
|
|
* @Last Modified time: 2019-01-22 16:21:16
|
|
*/
|
|
|
|
if (! defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Nshow_model extends CI_Model
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Get Booking List(s)
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function bookList(int $eventScheduleId)
|
|
{
|
|
if (is_null($eventScheduleId)) {
|
|
return false;
|
|
}
|
|
|
|
$query = $this->queryBookList($eventScheduleId);
|
|
$result = $this->db->query($query['query']);
|
|
return $result->result();
|
|
}
|
|
/**
|
|
* Get Waiting List(s)
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function waitList(int $eventScheduleId)
|
|
{
|
|
if (is_null($eventScheduleId)) {
|
|
return false;
|
|
}
|
|
|
|
$query = $this->queryWaitList($eventScheduleId);
|
|
$result = $this->db->query($query['query']);
|
|
return $result->result();
|
|
}
|
|
/**
|
|
* Get Extrapeoples
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function extraPeople(int $eventScheduleId)
|
|
{
|
|
if (is_null($eventScheduleId)) {
|
|
return false;
|
|
}
|
|
|
|
$result = $this->db->query("
|
|
SELECT
|
|
'' as user_id,
|
|
eawi.walk_in_id AS registration_id,
|
|
'Walk in' AS type,
|
|
'2' AS no_show_type,
|
|
eawi.gender AS civility,
|
|
eawi.last_name AS last_name,
|
|
eawi.first_name AS first_name,
|
|
eawi.email_address AS email_address,
|
|
'n/a' AS no_of_place,
|
|
eawi.attendance AS attendance,
|
|
eawi.note AS comment
|
|
FROM
|
|
event_attendance_walk_in as eawi
|
|
WHERE
|
|
eawi.event_schedule_id = ".$eventScheduleId."
|
|
ORDER BY type DESC, last_name ASC
|
|
");
|
|
return $result->result();
|
|
}
|
|
/**
|
|
* Query string for confirmed/bookings
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access private member
|
|
*/
|
|
private function queryBookList(int $eventScheduleId)
|
|
{
|
|
return array("query" =>"
|
|
SELECT
|
|
u.user_id as user_id,
|
|
er.registration_id as registration_id,
|
|
(CASE
|
|
WHEN er.status = 1 THEN 'Booking'
|
|
WHEN er.status = 0 THEN 'Withdrawn'
|
|
END) AS type,
|
|
(SELECT us.civility
|
|
FROM user_subscriber us
|
|
WHERE us.subscriber = er.subscriber
|
|
) AS civility,
|
|
(SELECT u.last_name
|
|
FROM user u
|
|
WHERE u.user_id = er.subscriber
|
|
)AS last_name,
|
|
(SELECT u.first_name
|
|
FROM user u
|
|
WHERE u.user_id = er.subscriber
|
|
) AS first_name,
|
|
(SELECT u.email_address
|
|
FROM user u
|
|
WHERE u.user_id = er.subscriber
|
|
) AS email_address,
|
|
(SELECT ev.title
|
|
FROM event ev
|
|
LEFT JOIN event_schedule evs
|
|
ON ev.event_id = evs.event_id
|
|
WHERE evs.event_schedule_id = ".$eventScheduleId."
|
|
) as event_name,
|
|
er.date_time as reservation_date,
|
|
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
|
|
AND ea.attendance_type = 0
|
|
) as comment,
|
|
(
|
|
SELECT ea.is_attended
|
|
FROM event_attendance ea
|
|
WHERE ea.registration_id = er.registration_id
|
|
AND ea.attendance_type = 0
|
|
) as no_show_type,
|
|
(
|
|
SELECT ea.attendance_id
|
|
FROM event_attendance ea
|
|
WHERE ea.registration_id = er.registration_id
|
|
AND ea.attendance_type = 0
|
|
) as attendance_id,
|
|
(SELECT
|
|
etn.attendance
|
|
FROM event_attendance_noshow etn
|
|
WHERE etn.user_id = er.subscriber
|
|
AND event_schedule_id = {$eventScheduleId}
|
|
) as attendance
|
|
|
|
FROM event_registration er
|
|
LEFT JOIN user u
|
|
ON er.subscriber = u.user_id
|
|
WHERE er.status = 1
|
|
AND er.event_schedule_id = ".$eventScheduleId."
|
|
ORDER BY type DESC, last_name ASC
|
|
"
|
|
,"groupby" => ""
|
|
);
|
|
}
|
|
/**
|
|
* Query strring for Waiting List(s)
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
*/
|
|
private function queryWaitList(int $eventScheduleId)
|
|
{
|
|
return array("query" =>"
|
|
SELECT
|
|
u.user_id as user_id,
|
|
ewl.wait_list_id as registration_id,
|
|
(CASE
|
|
WHEN ewl.status = 1 THEN 'Waiting'
|
|
WHEN ewl.status = 0 THEN 'Cancelled'
|
|
END) AS type,
|
|
(SELECT us.civility
|
|
FROM user_subscriber us
|
|
WHERE us.subscriber = ewl.wait_list_subscriber
|
|
) AS civility,
|
|
(SELECT u.last_name
|
|
FROM user u
|
|
WHERE u.user_id = ewl.wait_list_subscriber
|
|
) AS last_name,
|
|
(SELECT u.first_name
|
|
FROM user u
|
|
WHERE u.user_id = ewl.wait_list_subscriber
|
|
) AS first_name,
|
|
(SELECT u.email_address
|
|
FROM user u
|
|
WHERE u.user_id = ewl.wait_list_subscriber
|
|
) AS email_address,
|
|
(SELECT ev.title
|
|
FROM event ev
|
|
LEFT JOIN event_schedule evs
|
|
ON ev.event_id = evs.event_id
|
|
WHERE evs.event_schedule_id = ".$eventScheduleId."
|
|
) AS event_name,
|
|
ewl.date_time as reservation_date,
|
|
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
|
|
AND ea.attendance_type = 1
|
|
) as comment,
|
|
(
|
|
SELECT ea.is_attended
|
|
FROM event_attendance ea
|
|
WHERE ea.registration_id = ewl.wait_list_id
|
|
AND ea.attendance_type = 1
|
|
) as no_show_type,
|
|
(SELECT
|
|
etn.attendance
|
|
FROM event_attendance_noshow etn
|
|
WHERE etn.user_id = ewl.wait_list_subscriber
|
|
AND event_schedule_id = {$eventScheduleId}
|
|
) as attendance
|
|
|
|
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 = ".$eventScheduleId."
|
|
ORDER BY type DESC, last_name ASC
|
|
"
|
|
,"groupby" => ""
|
|
);
|
|
}
|
|
/**
|
|
* Get event schedule details "Event ID, Title, Date months and hour"
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access private member
|
|
*/
|
|
public function getEventScheduleDetails(int $eventScheduleId)
|
|
{
|
|
$query = "
|
|
SELECT
|
|
evs.event_id as event_id,
|
|
ev.title,
|
|
DATE_FORMAT(evs.start_date_time, '%e/%m/%Y') AS date_month,
|
|
DATE_FORMAT(evs.end_date_time, '%Hh%i') AS hour ,
|
|
( CASE
|
|
WHEN evs.start_date_time IS NULL THEN ''
|
|
ELSE CONCAT(' - ',DATE_FORMAT(evs.start_date_time, '%e/%m/%Y %Hh%i'))
|
|
END) as start_date_time_hour,
|
|
(CASE
|
|
WHEN DATE_FORMAT(evs.start_date_time, '%Y/%m/%e %H:%i') < DATE_FORMAT(NOW(), '%Y/%m/%e %H:%i') OR evs.back_office_status NOT IN(0,5,6,1,2)
|
|
THEN 1 ELSE 0
|
|
END) is_passed_start_date
|
|
FROM event ev
|
|
LEFT JOIN event_schedule evs
|
|
ON ev.event_id = evs.event_id
|
|
WHERE evs.event_schedule_id = ".$eventScheduleId."
|
|
AND evs.back_office_status NOT IN(6)
|
|
AND ev.status = 1
|
|
";
|
|
|
|
$eventDetailsResultSets = $this->db->query($query);
|
|
|
|
//return false if empty records
|
|
if ($eventDetailsResultSets->num_rows() == 0) {
|
|
return false;
|
|
}
|
|
|
|
//get Rows
|
|
$eventDetails = $eventDetailsResultSets->row();
|
|
|
|
//Return event details
|
|
return [
|
|
"event_id" =>($eventDetails->event_id ?? 0),
|
|
"title" =>($eventDetails->title ?? 0),
|
|
"date_month" => ($eventDetails->date_month ?? 0),
|
|
"hour" => ($eventDetails->hour ?? 0),
|
|
"start_date_time_hour" => ($eventDetails->start_date_time_hour ?? 0),
|
|
"is_passed_start_date" => ($eventDetails->is_passed_start_date ?? 0)
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Add new extra people
|
|
*
|
|
* @param int $eventId
|
|
* @param int $eventScheduleId
|
|
* @param string $gender
|
|
* @param string $name
|
|
* @param string $last
|
|
* @param string $email
|
|
* @param string $comment
|
|
* @param int $attendance
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function AddNewExtraPeople($eventId, $eventScheduleId, $gender, $name, $last, $email, $comment, $attendance)
|
|
{
|
|
$this->db->insert("event_attendance_walk_in", array(
|
|
'event_id' => $eventId,
|
|
'event_schedule_id' => $eventScheduleId,
|
|
'gender' => $gender,
|
|
"first_name" => $name,
|
|
'last_name' => $last,
|
|
'email_address' => $email,
|
|
'note' => $comment,
|
|
'attendance' => $attendance,
|
|
'date_time' => date('Y-m-d h:m:s')
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Update event attendance(or NO SHOW)
|
|
*
|
|
* @param null $type
|
|
* @param null $author
|
|
* @param null $registration_id
|
|
* @param null $no_show
|
|
* @param null $note
|
|
* @param integer $added_via = 1 = export excel
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function saveBookAndWait($type, $author, $registration_id, $no_show, $note, $added_via=1)
|
|
{
|
|
//Check first if registration_id exist in table "event_attendance"
|
|
if ($this->checkAttendanceExist($registration_id)) {
|
|
|
|
//Then update attendance
|
|
$this->db->where('registration_id', $registration_id);
|
|
$this->db->update("event_attendance", array(
|
|
'is_attended' => $no_show,
|
|
'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 {
|
|
//Else insert attendance
|
|
$this->db->insert("event_attendance", array(
|
|
'registration_id' => $registration_id,
|
|
'attendance_type' => $type,
|
|
'is_attended' => $no_show,
|
|
'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')
|
|
));
|
|
}
|
|
}
|
|
/**
|
|
* Check "Registration ID" if exist
|
|
*
|
|
* @param integer $registration_id
|
|
* @return boolean
|
|
* access private member
|
|
*/
|
|
private function checkAttendanceExist(int $registration_id) : bool
|
|
{
|
|
$this->db->select("registration_id");
|
|
$this->db->where('registration_id', $registration_id);
|
|
$result = $this->db->get("event_attendance");
|
|
return $result->num_rows() > 0;
|
|
}
|
|
/**
|
|
* Check if exist noshow data exists
|
|
*
|
|
* @param integer $user_id
|
|
* @param integer $event_schedule_id
|
|
* @return boolean
|
|
* access private member
|
|
*/
|
|
private function checkNoshowExist(?int $user_id, int $event_schedule_id) : bool
|
|
{
|
|
if ($user_id == null) {
|
|
return false;
|
|
}
|
|
$this->db->select("user_id");
|
|
$this->db->where('user_id', $user_id);
|
|
$this->db->where('event_schedule_id', $event_schedule_id);
|
|
$result = $this->db->get("event_attendance_noshow");
|
|
return $result->num_rows() > 0;
|
|
}
|
|
|
|
/**
|
|
* Function to check wheter the excel file was already uploaded then insert new record
|
|
* for table "event_attendance_walk_in" and "event_attendance_noshow"
|
|
*
|
|
* @param string $table
|
|
* @param integer $eventId
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function deleteRecordIfExist(int $eventId, int $eventScheduleId)
|
|
{
|
|
//Delete record for table "event_attendance_walk_in" if already uploaded
|
|
if ($this->checkHasAlreadyRecord('event_attendance_walk_in', $eventId, $eventScheduleId)) {
|
|
$this->deleteIfRecordExist('event_attendance_walk_in', $eventId, $eventScheduleId);
|
|
}
|
|
|
|
//Delete record for table "event_attendance_noshow" if already uploaded
|
|
if ($this->checkHasAlreadyRecord('event_attendance_noshow', $eventId, $eventScheduleId)) {
|
|
$this->deleteIfRecordExist('event_attendance_noshow', $eventId, $eventScheduleId);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if event ID and event schedule id exist
|
|
*
|
|
* @param string $table
|
|
* @param integer $eventId
|
|
* @param integer $eventScheduleId
|
|
* @return boolean
|
|
* access public member
|
|
*/
|
|
private function checkHasAlreadyRecord(string $table, int $eventId, int $eventScheduleId) : bool
|
|
{
|
|
$this->db->select("*");
|
|
$this->db->from($table);
|
|
$this->db->where("event_id", $eventId);
|
|
$this->db->where("event_schedule_id", $eventScheduleId);
|
|
$resultCount = $this->db->get();
|
|
return $resultCount->num_rows() > 0 ;
|
|
}
|
|
|
|
/**
|
|
* Delete record if exist
|
|
*
|
|
* @param string $table = event_attendance_walk_in, event_attendance_noshow
|
|
* @param integer $eventId = Event ID
|
|
* @param integer $eventScheduleId = Event Schedule ID
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
private function deleteIfRecordExist(string $table, int $eventId, int $eventScheduleId)
|
|
{
|
|
$this->db->where('event_id', $eventId);
|
|
$this->db->where('event_schedule_id', $eventScheduleId);
|
|
$this->db->delete($table);
|
|
}
|
|
|
|
/**
|
|
* Append to "event_attendance_noshow" booking,waiting,extrapeoples
|
|
*
|
|
* @param array $data
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function saveEventAttendanceNoShow(array $data)
|
|
{
|
|
if (!$this->checkNoshowExist($data['user_id'], $data['event_schedule_id'])) {
|
|
$this->db->insert('event_attendance_noshow', $data);
|
|
} else {
|
|
$user_id = $data['user_id'];
|
|
$event_schedule_id = $data['event_schedule_id'];
|
|
|
|
unset($data['user_id']);
|
|
unset($data['event_schedule_id']);
|
|
unset($data['event_id']);
|
|
|
|
$this->db->where('user_id', $user_id);
|
|
$this->db->where('event_schedule_id', $event_schedule_id);
|
|
$this->db->update('event_attendance_noshow', $data);
|
|
|
|
}
|
|
}
|
|
/**
|
|
* total_available_seat, remaining_seat in Event_schedule table
|
|
*
|
|
* @param integer $eventId
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function getTotalAvailableAndRemainingPlaces(int $eventId, int $eventScheduleId)
|
|
{
|
|
$this->db->select("total_available_seat, remaining_seat");
|
|
$this->db->where('event_id', $eventId);
|
|
$this->db->where('event_schedule_id', $eventScheduleId);
|
|
$scheduleDetails = $this->db->get("event_schedule");
|
|
|
|
if ($scheduleDetails->num_rows() == 0) {
|
|
return false;
|
|
}
|
|
|
|
$eventDetails = $scheduleDetails->row();
|
|
|
|
return [
|
|
'total_available_seat' => $eventDetails->total_available_seat,
|
|
'remaining' => $eventDetails->remaining_seat
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
* save the attendance data on the database
|
|
*
|
|
* @param array $attendance_data
|
|
* @return bool
|
|
* access public member
|
|
*/
|
|
public function save_noshow_data($attendance_data)
|
|
{
|
|
$col = 'booking_expected';
|
|
$is_attended = 1;
|
|
switch ($attendance_data['type']) {
|
|
case 'Réservation':
|
|
case 'Booking':
|
|
$col = 'booking_expected';
|
|
$attendance_type = 0;
|
|
break;
|
|
case 'Attente':
|
|
case 'Waiting':
|
|
$col = 'waiting_expected';
|
|
$attendance_type = 1;
|
|
break;
|
|
|
|
default:
|
|
// code...
|
|
break;
|
|
}
|
|
// identify if attended, partially attended or no show
|
|
if ($attendance_data['no_of_place'] == $attendance_data['attendance']) {
|
|
$is_attended = 1;
|
|
} elseif ($attendance_data['attendance'] == 0) {
|
|
// noshow
|
|
$is_attended = 0;
|
|
} else {
|
|
// partially attended
|
|
$is_attended = 2;
|
|
}
|
|
|
|
$data = array();
|
|
if (!isset(
|
|
$attendance_data['event_id'],
|
|
$attendance_data['event_schedule_id'],
|
|
$attendance_data['user_id']
|
|
)) {
|
|
return false;
|
|
}
|
|
if ($this->noshowDataExists($attendance_data, $col)) {
|
|
$data = array(
|
|
$attendance_data['attendance'],
|
|
$attendance_data['event_id'],
|
|
$attendance_data['event_schedule_id'],
|
|
$attendance_data['user_id'],
|
|
$attendance_data['no_of_place'],
|
|
);
|
|
$query = "UPDATE event_attendance_noshow SET attendance = ?
|
|
WHERE event_id = ? AND event_schedule_id = ? AND user_id = ? AND $col = ?";
|
|
|
|
$data2 = array(
|
|
'n/a',
|
|
$is_attended,
|
|
$attendance_data['registration_id']
|
|
);
|
|
|
|
$query2 = "UPDATE event_attendance SET note = ?, is_attended = ?
|
|
WHERE registration_id = ?";
|
|
} else {
|
|
$data = array(
|
|
$attendance_data['event_id'],
|
|
$attendance_data['event_schedule_id'],
|
|
$attendance_data['user_id'],
|
|
$attendance_data['no_of_place'],
|
|
$attendance_data['attendance'],
|
|
);
|
|
$query = "INSERT INTO event_attendance_noshow(event_id, event_schedule_id, user_id, $col, attendance) VALUES(
|
|
?, ?, ?, ?, ?
|
|
)";
|
|
// insert into event attendance
|
|
$data2 = array(
|
|
$attendance_data['registration_id'],
|
|
$attendance_type,
|
|
'n/a',
|
|
$is_attended,
|
|
2,
|
|
$_SESSION["logged_in"]["user_id"]
|
|
);
|
|
$query2 = "INSERT INTO event_attendance(registration_id, attendance_type, note, is_attended, added_via, author) VALUES(
|
|
?, ?, ?, ?, ?, ?
|
|
)";
|
|
}
|
|
$successful = $this->db->query($query, $data);
|
|
$successful = $this->db->query($query2, $data2);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* check for duplicates in noshow data
|
|
*
|
|
* @param array $attendance_data
|
|
* @return bool
|
|
* @access public
|
|
*/
|
|
public function noshowDataExists($attendance_data, $col)
|
|
{
|
|
$this->db->select("event_id");
|
|
$this->db->where('event_id', $attendance_data['event_id']);
|
|
$this->db->where('event_schedule_id', $attendance_data['event_schedule_id']);
|
|
$this->db->where('user_id', $attendance_data['user_id']);
|
|
$result = $this->db->get("event_attendance_noshow");
|
|
|
|
if ($result->num_rows() > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* save the walkin data on the database
|
|
*
|
|
* @param array $walk_in_data
|
|
* @return bool
|
|
* @access public
|
|
*/
|
|
public function save_walk_in($walk_in_data)
|
|
{
|
|
// $gender = ($walk_in_data['civility'] == "Madame"? 'f': 'm');
|
|
$gender = $walk_in_data['civility'];
|
|
$data = array();
|
|
if ($this->walkInDataExists($walk_in_data)) {
|
|
$data = array(
|
|
$walk_in_data['attendance'],
|
|
$walk_in_data['event_id'],
|
|
$walk_in_data['event_schedule_id'],
|
|
$gender,
|
|
$walk_in_data['first_name'],
|
|
$walk_in_data['last_name'],
|
|
$walk_in_data['email_address']
|
|
);
|
|
$query = "UPDATE event_attendance_walk_in SET attendance = ?
|
|
WHERE event_id = ? AND event_schedule_id = ? AND
|
|
gender = ? AND first_name = ? AND last_name = ? AND email_address = ?";
|
|
|
|
// save to event_attendance_noshow
|
|
$data1 = array(
|
|
$walk_in_data['attendance'],
|
|
$walk_in_data['event_id'],
|
|
$walk_in_data['event_schedule_id'],
|
|
$walk_in_data['note']
|
|
);
|
|
$query1 = "UPDATE event_attendance_noshow SET attendance = ?, note = ?
|
|
WHERE event_id = ? AND event_schedule_id = ?";
|
|
} else {
|
|
$data = array(
|
|
$walk_in_data['event_id'],
|
|
$walk_in_data['event_schedule_id'],
|
|
$gender,
|
|
$walk_in_data['first_name'],
|
|
$walk_in_data['last_name'],
|
|
$walk_in_data['email_address'],
|
|
$walk_in_data['note'],
|
|
$walk_in_data['attendance'],
|
|
);
|
|
$query = "INSERT INTO event_attendance_walk_in(
|
|
event_id, event_schedule_id, gender, first_name, last_name,
|
|
email_address, note, attendance
|
|
) VALUES(
|
|
?, ?, ?, ?, ?, ?, ?, ?
|
|
)";
|
|
$data1 = array(
|
|
$walk_in_data['event_id'],
|
|
$walk_in_data['event_schedule_id'],
|
|
$walk_in_data['attendance'],
|
|
);
|
|
$query1 = "INSERT INTO event_attendance_noshow(
|
|
event_id, event_schedule_id, attendance
|
|
) VALUES(
|
|
?, ?, ?
|
|
)";
|
|
|
|
// insert into event attendance
|
|
// $data2 = array(
|
|
// $attendance_data['registration_id'],
|
|
// $attendance_type,
|
|
// 'n/a',
|
|
// $is_attended,
|
|
// 2,
|
|
// $_SESSION["logged_in"]["user_id"]
|
|
// );
|
|
// $query2 = "INSERT INTO event_attendance(registration_id, attendance_type, note, is_attended, added_via, author) VALUES(
|
|
// ?, ?, ?, ?, ?, ?
|
|
// )";
|
|
}
|
|
return $this->db->query($query, $data) && $this->db->query($query1, $data1);
|
|
}
|
|
|
|
/**
|
|
* check for duplicates in walkin data
|
|
*
|
|
* @param array $walk_in_data
|
|
* @return bool
|
|
* @access public
|
|
*/
|
|
public function walkInDataExists($walk_in_data)
|
|
{
|
|
// $gender = ($walk_in_data['civility'] == "Madame"? 'f': 'm');
|
|
$gender = $walk_in_data['civility'];
|
|
$data = array(
|
|
$walk_in_data['event_id'],
|
|
$walk_in_data['event_schedule_id'],
|
|
$gender,
|
|
$walk_in_data['first_name'],
|
|
$walk_in_data['last_name'],
|
|
$walk_in_data['email_address'],
|
|
);
|
|
$this->db->select("*");
|
|
$this->db->where('event_id', $walk_in_data['event_id']);
|
|
$this->db->where('event_schedule_id', $walk_in_data['event_schedule_id']);
|
|
// $this->db->where('gender', $walk_in_data['gender']);
|
|
$this->db->where('first_name', $walk_in_data['first_name']);
|
|
$this->db->where('last_name', $walk_in_data['last_name']);
|
|
$this->db->where('email_address', $walk_in_data['email_address']);
|
|
$result = $this->db->get("event_attendance_walk_in");
|
|
|
|
if ($result->num_rows() > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* total_available_seat, remaining_seat in Event_schedule table
|
|
*
|
|
* @param integer $eventId
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function getSeatInfo(int $eventScheduleId, int $event_id = 0)
|
|
{
|
|
$query = "SELECT
|
|
(CASE WHEN e.seat_feature = 2 THEN e.total_combined_seat ELSE es.total_available_seat END) offertes_total,
|
|
(CASE WHEN e.seat_feature = 2 THEN
|
|
(
|
|
e.total_combined_seat -(
|
|
(SELECT SUM(attendance)
|
|
FROM event_attendance_noshow
|
|
WHERE event_id = $event_id AND
|
|
user_id IS NOT NULL)
|
|
+
|
|
(CASE
|
|
WHEN (SELECT SUM(attendance)
|
|
FROM event_attendance_walk_in
|
|
WHERE event_id = $event_id AND attendance > 0) IS NOT NULL THEN (SELECT SUM(attendance)
|
|
FROM event_attendance_walk_in
|
|
WHERE event_id = $event_id AND attendance > 0)
|
|
ELSE 0
|
|
END
|
|
)
|
|
)
|
|
)
|
|
ELSE
|
|
(
|
|
total_available_seat-(
|
|
(SELECT SUM(attendance)
|
|
FROM event_attendance_noshow
|
|
WHERE event_schedule_id = $eventScheduleId AND
|
|
user_id IS NOT NULL)
|
|
+
|
|
(CASE
|
|
WHEN (SELECT SUM(attendance)
|
|
FROM event_attendance_walk_in
|
|
WHERE event_schedule_id = $eventScheduleId AND attendance > 0) IS NOT NULL THEN (SELECT SUM(attendance)
|
|
FROM event_attendance_walk_in
|
|
WHERE event_schedule_id = $eventScheduleId AND attendance > 0)
|
|
ELSE 0
|
|
END
|
|
)
|
|
)
|
|
)
|
|
END) restantes_total,
|
|
(
|
|
SELECT COUNT(id)
|
|
FROM event_attendance_noshow
|
|
WHERE event_schedule_id = $eventScheduleId AND attendance > 0
|
|
AND waiting_expected IS NULL AND
|
|
user_id IS NOT NULL
|
|
) abonnes_presents,
|
|
(
|
|
SELECT SUM(attendance-1)
|
|
FROM event_attendance_noshow
|
|
WHERE event_schedule_id = $eventScheduleId AND attendance > 1
|
|
AND waiting_expected IS NULL AND
|
|
user_id IS NOT NULL
|
|
) invites_presents,
|
|
|
|
(
|
|
SELECT COUNT(id)
|
|
FROM event_attendance_noshow
|
|
WHERE event_schedule_id = $eventScheduleId AND attendance = 0 AND booking_expected IS NOT NULL AND
|
|
user_id IS NOT NULL
|
|
) complet_nshow_total,
|
|
(
|
|
SELECT COUNT(id)
|
|
FROM event_attendance_noshow
|
|
WHERE event_schedule_id = $eventScheduleId AND
|
|
(attendance < booking_expected AND attendance != 0) AND
|
|
user_id IS NOT NULL
|
|
) partiel_nshow_total
|
|
FROM event_schedule es
|
|
INNER JOIN event e USING(event_id)
|
|
WHERE event_schedule_id = ?";
|
|
// $this->db->select("total_available_seat offertes_total,
|
|
// (
|
|
// total_available_seat-(
|
|
// (SELECT SUM(attendance)
|
|
// FROM event_attendance_noshow
|
|
// WHERE event_schedule_id = $eventScheduleId AND
|
|
// user_id IS NOT NULL)
|
|
// +
|
|
// (CASE
|
|
// WHEN (SELECT SUM(attendance)
|
|
// FROM event_attendance_walk_in
|
|
// WHERE event_schedule_id = $eventScheduleId AND attendance > 0) IS NOT NULL THEN (SELECT SUM(attendance)
|
|
// FROM event_attendance_walk_in
|
|
// WHERE event_schedule_id = $eventScheduleId AND attendance > 0)
|
|
// ELSE 0
|
|
// END
|
|
// )
|
|
// )
|
|
// ) restantes_total,
|
|
// (
|
|
// SELECT COUNT(id)
|
|
// FROM event_attendance_noshow
|
|
// WHERE event_schedule_id = $eventScheduleId AND attendance > 0
|
|
// AND waiting_expected IS NULL AND
|
|
// user_id IS NOT NULL
|
|
// ) abonnes_presents,
|
|
// (
|
|
// SELECT SUM(attendance-1)
|
|
// FROM event_attendance_noshow
|
|
// WHERE event_schedule_id = $eventScheduleId AND attendance > 1
|
|
// AND waiting_expected IS NULL AND
|
|
// user_id IS NOT NULL
|
|
// ) invites_presents,
|
|
//
|
|
// (
|
|
// SELECT COUNT(id)
|
|
// FROM event_attendance_noshow
|
|
// WHERE event_schedule_id = $eventScheduleId AND attendance = 0 AND booking_expected IS NOT NULL AND
|
|
// user_id IS NOT NULL
|
|
// ) complet_nshow_total,
|
|
// (
|
|
// SELECT COUNT(id)
|
|
// FROM event_attendance_noshow
|
|
// WHERE event_schedule_id = $eventScheduleId AND
|
|
// (attendance < booking_expected AND attendance != 0) AND
|
|
// user_id IS NOT NULL
|
|
// ) partiel_nshow_total,
|
|
//
|
|
// ");
|
|
// $this->db->where('event_schedule_id', $eventScheduleId);
|
|
// $scheduleDetails = $this->db->get("event_schedule es");
|
|
$scheduleDetails = $this->db->query($query, array($eventScheduleId));
|
|
|
|
if ($scheduleDetails->num_rows() == 0) {
|
|
return false;
|
|
}
|
|
return $scheduleDetails->result_array()[0];
|
|
}
|
|
|
|
/**
|
|
* DB query to check if email exists
|
|
*
|
|
* @param string $table = table name
|
|
* @param string $field = field name
|
|
* @param string $search = email address
|
|
* @return string
|
|
* access public member
|
|
*/
|
|
public function checkEmailsExistInDb(string $table, string $field, string $search) :? string
|
|
{
|
|
$this->db->select($field);
|
|
$this->db->from($table);
|
|
$this->db->where($field, $search);
|
|
|
|
$query = $this->db->get();
|
|
if ($query->num_rows() == 0) {
|
|
return null;
|
|
}
|
|
|
|
return $query->row()->email_address;
|
|
}
|
|
|
|
/**
|
|
* total_available_seat, remaining_seat in Event_schedule table
|
|
*
|
|
* @param integer $eventId
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function getNoshowInfo(int $eventScheduleId)
|
|
{
|
|
$query = "SELECT
|
|
ean.event_id, ean.event_schedule_id,
|
|
evsched.no_show_stat,
|
|
SUM(booking_expected) total_waiting,
|
|
SUM(booking_expected) total_bookings,
|
|
SUM(attendance) total_attendance,
|
|
SUM(booking_expected-attendance) total_noshow
|
|
FROM event_attendance_noshow ean
|
|
INNER JOIN event_schedule evsched USING (event_schedule_id)
|
|
WHERE event_schedule_id = ?
|
|
GROUP BY event_schedule_id";
|
|
|
|
$scheduleDetails = $this->db->query($query, $eventScheduleId);
|
|
|
|
if ($scheduleDetails->num_rows() == 0) {
|
|
return false;
|
|
}
|
|
return $scheduleDetails->result_array()[0];
|
|
}
|
|
|
|
/**
|
|
* total_available_seat, remaining_seat in Event_schedule table
|
|
*
|
|
* @param integer noshow_status
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function toggleNoshowStatus(int $status, int $event_schedule_id)
|
|
{
|
|
$this->db->where('event_schedule_id', $event_schedule_id);
|
|
|
|
$toggle_noshow_stat = $this->db->update("event_schedule", array(
|
|
'no_show_stat' => $status
|
|
));
|
|
if ($toggle_noshow_stat) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* gets the current noshow_status
|
|
*
|
|
* @param integer $eventScheduleId
|
|
* @return void
|
|
* access public member
|
|
*/
|
|
public function getNoshowStatus(int $event_schedule_id)
|
|
{
|
|
$this->db->select('no_show_stat');
|
|
$this->db->where('event_schedule_id', $event_schedule_id);
|
|
|
|
$result = $this->db->get('event_schedule');
|
|
if ($result->num_rows() > 0) {
|
|
return $result->row_array();
|
|
} else {
|
|
array(
|
|
"no_show_stat" => 0
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|
|
|