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.
 
 
 
 
 
 

123 lines
4.7 KiB

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Event_registration_paid_event_model extends CI_Model {
function __construct(){
parent::__construct();
$this->load->model("user_activity_log_model");
$this->load->model("event_wait_list_model");
$this->load->model("event_schedule_model");
$this->load->model("event_registration_model");
}
/* Check if user can reserve for more than 1 place per event schedule */
public function can_register_to_event($event_id, $user_id, $reg_type) {
$restrict = $this->get_event_registration_restriction($event_id, $reg_type);
if ( !$restrict ) return false;
// Get total reservation per event
$total_reg = $this->event_registration_model->count_all_user_registration_per_event($event_id, $user_id);
// Not allowed to register, the limit has been reached already
if ($restrict->date_feature == 2 && $restrict->is_multiple_reservation == 0 && $total_reg >= 1 ) return false;
return true;
}
public function count_subscription($user_id, $event_schedule_id, $event_id)
{
$result = $this->db->query("
SELECT er.status, (number_of_guest+1) as number_of_guest
FROM event_registration er
INNER JOIN event_schedule es USING(event_schedule_id)
WHERE er.event_schedule_id = ?
AND er.subscriber = ?
AND es.event_status != 'CANCEL'
AND er.status = 1
ORDER BY er.date_time DESC
LIMIT 1
", array($event_schedule_id, $user_id))->row();
return $result ? $result->number_of_guest : false;
}
public function check_availability($event_id, $event_schedule_id, $seats_reserved)
{
return $this->db->query("select
(CASE
WHEN e.seat_feature = 2 THEN e.remaining_combined_seat
ELSE es.remaining_seat
END) as remaining_seat,
es.back_office_status,
es.event_status,
es.seats_per_subscriber,
es.quota_waiting_list_seat
from event_schedule es
left join event e ON e.event_id = es.event_id
where es.back_office_status NOT IN(0,7,6)
and e.event_id = ?
and es.event_schedule_id = ?
limit 1 ", array($event_id, $event_schedule_id))->row();
}
/**
* 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 get_event_category($event_id) {
$this->db->select('event_category');
$this->db->from('event');
$this->db->where('event_id', $event_id);
$this->db->limit('1');
$row = $this->db->get()->row();
return $row ? $row->event_category : null;
}
public function get_event_by_code_selection($code_selection) {
$this->db->select('es.event_id, 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');
$this->db->where('es.item_code', $code_selection);
$this->db->where_in('e.event_category', array('PAID_EVENT'));
$this->db->limit('1');
return $this->db->get()->row();
}
public function add_paid_event($paid_event) {
// Check is "update_date_time" is defined
if (!isset($paid_event['update_date_time']) || empty($paid_event['update_date_time'])) {
unset($paid_event['update_date_time']);
$this->db->set('update_date_time', 'NOW()', FALSE);
}
$this->db->insert('event_registration_paid_event', $paid_event);
return $this->db->insert_id();
}
public function get_event_registration_restriction($event_id, $reg_type){
$result= $this->db->select('is_multiple_reservation, is_multiple_waitlist_reservation, 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;
}
}