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.
 
 
 
 
 
 

1045 lines
43 KiB

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use app\core\utils\Response;
class Moderation extends MY_Controller
{
/**
* Allow reservation
* @var integer
*/
private const ALLOWED = true;
/**
* Block Reservation
* @var boolean
*/
private const MODERATED = false;
protected $canReserve = true;
/**
* @var array holds the current active settings
*/
protected $_current_settings;
/**
* @var array settings from the gm_settings view
*/
protected $_current_view_settings;
protected $_current_sub_settings;
/**
* Initialize this Class; call Parent Class construct
* Load Model
*
* @return void
*
* @access public
*/
public function __construct() {
$this->my_parent_controller();
Response::handleSessionTimeout("bo");
$this->load_language_backoffice();
$this->clear_cache();
$this->load->model('event_moderation_model');
$this->load->model('event_model');
$this->initCurrentSettings();
}
/**
*
* @method initialize current settings
* @param string purpose, 'save' or 'validation'
* @access protected
* @return array
*
*/
protected function initCurrentSettings($purpose = 'save')
{
try {
if ($purpose == 'save') {
$get_actual_settings = 1;
} else {
$get_actual_settings = 0;
}
/*get current active settings that are either used or unused*/
$this->_current_settings = $this->getLatestModSettings(3, $get_actual_settings);
/*get current active settings from the settings view*/
$this->_current_view_settings = $this->getLatestModSettings(3, 0);
if (isset($this->_current_settings['gm_id'])) {
$this->_current_sub_settings = $this->event_moderation_model->getSubModSettings($this->_current_settings['gm_id'], $get_actual_settings);
} else {
$this->_current_sub_settings = array();
}
} catch (\Exception $e) {
throw new Exception("Cannot get old settings");
}
}
/**
*
* @method get old settings
* @access public
* @param int used(1) | unused(0) | either (3)
* @param int get from view or actual table 1:get from view. 0: get from actual table
* @return array
*
*/
private function getLatestModSettings(int $is_used, int $get_actual = 1)
{
try {
return $this->event_moderation_model->getLatestModSettings($is_used, $get_actual);
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
*
* @method get old settings for BO
* @access public
* @param int used(1) | unused(0) | either (3)
* @param int for validation 1 | 0
* @param int get array form or output to json format
* @return array
*
*/
public function getLatestModerationSettings(int $is_used, int $for_validation = 0, $get_array = 0)
{
try {
if ($for_validation) {
$this->initCurrentSettings('validation');
}
$settings = $this->_current_settings;
if (count($settings) >0 ) {
$sub_settings = $this->_current_sub_settings;
$all_settings = array(
"main_settings" => $settings,
"sub_settings" => $sub_settings,
);
if ($get_array) {
return $all_settings;
}
output_to_json($this, $all_settings);
} else {
$all_settings = array(
"main_settings" => array(
"gm_mod_stat" => 0,
"noshow_psub_stat" => 0,
"res_psub_stat" => 0,
"event_cat_stat" => 0,
"event_loc_stat" => 0,
"event_month_stat" => 0,
"flex_mod_stat" => 0,
),
"sub_settings" => array(
"max_noshow" => null,
"nshow_period" => null,
"max_res" => null,
"res_period_type" => null,
"event_cats" => null,
"locations" => null,
"months" => null,
"hrs_bef_event_closes" => null,
"places_volume" => null
)
);
if ($get_array) {
return $all_settings;
}
output_to_json($this, $all_settings);
}
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
*
* Save moderation settings
* @access public
*
* @param int type of settings to save 1:main, 2:sub
* @return array
*
*/
public function saveSettings($type = 1)
{
try {
$post = $this->input->post();
/*
* check for existing moderation setting used or unused
* if no settings are present then insert
*/
if (count($this->_current_settings) > 0) {
$action ='update';
/*
* get latest settings
* if the current settings are being used insert new settings
* else update the current settings
*/
$cur_sett = $this->_current_settings;
$cur_view_sett = $this->_current_view_settings;
/*
* update current settings in the row if unused else add new row
* of gm settings the set the action to add
*/
if ($cur_view_sett['is_used']) {
// $action = 'add';
}
$data = array(
"gm_id" => $cur_sett['gm_id'],
"gm_mod_stat" => ($post['gm_mod_stat']) ?? $cur_sett['gm_mod_stat'],
"noshow_psub_stat" => $post['noshow_psub_stat'] ?? $cur_sett['noshow_psub_stat'],
"res_psub_stat" => $post['res_psub_stat'] ?? $cur_sett['res_psub_stat'],
"event_cat_stat" => $post['event_cat_stat'] ?? $cur_sett['event_cat_stat'],
"event_loc_stat" => $post['event_loc_stat'] ?? $cur_sett['event_loc_stat'],
"event_month_stat" => $post['event_month_stat'] ?? $cur_sett['event_month_stat'],
"flex_mod_stat" => $post['flex_mod_stat'] ?? $cur_sett['flex_mod_stat'],
);
/*
* save main settings if type is not 2 and action is add
* if the type is set to 2 and the action is update it simply means
* that the only settings that will be changed are related to sub settings
*/
if ($type != 2 || $action == 'add') {
$main_sett_saved = $this->event_moderation_model->saveSettings($data, $action);
/*
* reinitialize current settings
*/
$this->_current_settings = $this->getLatestModSettings(3, 1);
} else {
$main_sett_saved = true;
}
/*
* save sub settings if type is set to 2 and action is add
*/
if ($type == 2 || $action == 'add') {
$sub_sett_saved = $this->saveSubSettings($post, $action);
$this->initCurrentSettings();
/*
* reinitialize current settings
*/
} else {
$sub_sett_saved = true;
}
if ($main_sett_saved) {
output_to_json($this, array(
'mtype' => "success",
'msg' => "Moderation settings updated",
"main_settings" => $this->_current_settings,
"sub_settings" => $this->_current_sub_settings,
));
} else {
output_to_json($this, array(
'mtype' => "error",
'msg' => "Cannot update moderation settings",
));
}
} else {
/*
* insert new main and sub settings
*/
$data = array(
"gm_mod_stat" => 1,
"noshow_psub_stat" => 0,
"res_psub_stat" => 0,
"event_cat_stat" => 0,
"event_loc_stat" => 0,
"event_month_stat" => 0,
"flex_mod_stat" => 0,
);
$saved = $this->event_moderation_model->saveSettings($data);
$this->initCurrentSettings();
$gm_nshow_psubs = array(
"max_noshow" => $saved,
"gm_mod_stat" => 1,
);
if ($saved) {
output_to_json($this, array(
'mtype' => "success",
'msg' => "Moderation settings updated",
));
} else {
output_to_json($this, array(
'mtype' => "error",
'msg' => "Cannot update moderation settings",
));
}
}
} catch (\Exception $e) {
throw new Exception('Cannot update settings');
output_to_json($this, array(
'mtype' => "error",
'msg' => $e->getMessage(),
));
}
}
/**
*
* @method Save moderation settings
* @access private
*
* @param array sub settings data
* @param int type of settings to save 1:main, 2:sub
* @return array
*
*/
private function saveSubSettings($post, $action = 'update')
{
try {
/*
* get latest settings
* if the current settings are being used insert new settings
* else update the current settings
*/
$cur_sett = $this->_current_settings;
$cur_view_sett = $this->_current_view_settings;
if ($cur_view_sett['is_used']) {
// $action = 'add';
}
/*
* get current sub settings, if no settings are detected set default one
*/
$cur_sub_sett = $this->_current_sub_settings;
switch ($post['type']) {
case 'noshow_psub_sub':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"max_noshow" => ($post['max_noshow']) ?? ($cur_sub_sett['max_noshow']),
"nshow_period" => ($post['nshow_period']) ?? ($cur_sub_sett['nshow_period']),
);
break;
case 'reservation_psub':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"max_res" => ($post['max_res']) ?? ($cur_sub_sett['max_res']),
"res_period_type" => ($post['res_period_type']) ?? ($cur_sub_sett['res_period_type']),
);
break;
case 'event_category':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"event_cat" => ($post['event_cats']) ?? ($cur_sub_sett['event_cats']),
);
break;
case 'event_location':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"event_location" => ($post['event_locations']) ?? ($cur_sub_sett['locations']),
);
break;
case 'event_month':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"event_month" => ($post['event_months']) ?? ($cur_sub_sett['months']),
);
break;
case 'flex_moderation':
$sub_data = array(
"type" => $post['type'],
"gm_id" => $cur_sett['gm_id'],
"hrs_bef_event_closes" => ($post['hrs_bef_event_closes']) ?? ($cur_sub_sett['hrs_bef_event_closes']),
"places_volume" => ($post['places_volume']) ?? ($cur_sub_sett['places_volume']),
);
break;
default:
// code...
break;
}
if (isset($sub_data)) {
return $this->event_moderation_model->saveSubSettings($sub_data, $action);
} else {
return false;
}
} catch (\Exception $e) {
throw new Exception('Cannot update settings');
output_to_json($this, array(
'mtype' => "error",
'msg' => $e->getMessage(),
));
}
}
/**
*
* @method evsched mod settings
* @access public
* @param int event_schedule_id
* @return array
*
*/
public function getEvSchedModSettings(int $event_schedule_id)
{
try {
$settings = $this->event_moderation_model->getEvSchedModSettings($event_schedule_id);
output_to_json($this, array(
'evsched_settings' => $settings,
));
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
*
* @method check if event schedule qualifies in event moderation
* @access public
* @param int event_schedule_id
* @return array
*
*/
public function checkIfEventQualifiesInModeration(int $event_schedule_id)
{
try {
$settings = $this->event_moderation_model->checkIfEventQualifiesInModeration($event_schedule_id);
$qualifies = 0;
$mod_data = array();
if (count($settings) > 0) {
$qualifies = 1;
$mod_data = $settings;
}
output_to_json($this, array(
'qualifies' => $qualifies,
'mod_data' => $mod_data,
));
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
* Check if moderation is disabled for the user or not
* @method checkIfSubscriberIsModeratedByDate
* @param array $data
* @return boolean
*/
private function checkIfSubscriberIsModeratedOrNot($data) {
if ((int) $data->isModeratedByDate || $data->isModerationDisabled) {
return true;
}
return false;
}
/**
* Check if event status is in WL
*
* @method isEventInWaitlistedStatus
* @param integer $eventScheduleId
* @return boolean
*/
private function isEventInWaitlistedStatus($eventScheduleId) {
$eventSched = $this->event_moderation_model->getEventScheduleStatus($eventScheduleId);
if ($eventSched) {
return ( ($eventSched->event_status == 'FULL' || $eventSched->remaining_seat == 0) && $eventSched->back_office_status == 2 );
}
return false;
}
/**
* Check if Subscriber is Moderated or Not before reserving
*
* @param integer $eventId
* @param integer $eventScheduleId
* @return boolean
*
* access public function
*/
public function checkIfSubscriberIsModerated($eventId, $eventScheduleId)
{
// isAccountNotPremium : helpers/single_signon_helper.php
// if ($this->isAccountPremiumButNotAllowedToReserve() || isAccountNotPremium()) {
// return output_to_json($this, ["allowed" => false, 'sso' => true]);
// }
// check if event is waiting list
if ($this->isEventInWaitlistedStatus($eventScheduleId)) {
return output_to_json($this, ["allowed" => true]);
}
$validated = false;
//get the loggedin user
$subscriber = $this->data["logged_in"]["user_id"];
/**
* Condition 1: check if data needed are not empty||null
*/
if (notSet($subscriber) || notSet($eventScheduleId) || notSet($eventId)) {
$this->canReserve = self::MODERATED;
$validated = true;
}
$months = array('Tous les mois', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai',
'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
// Get event date
$eventStartDate = $this->event_moderation_model->getEventStartDate($eventScheduleId);
$eventStartDateConvertedToTime = strtotime($eventStartDate);
$cur_year = date('Y', $eventStartDateConvertedToTime);
$cur_month = date('n', $eventStartDateConvertedToTime);
$cur_month_text = $months[date('n', $eventStartDateConvertedToTime)];
$cur_quarter = ceil($cur_month/3);
/*
* months per quarter
*/
$cur_q_months = array(
1 => "{$months[1]}, {$months[2]} et {$months[3]}",
2 => "{$months[4]}, {$months[5]} et {$months[6]}",
3 => "{$months[7]}, {$months[8]} et {$months[9]}",
4 => "{$months[10]}, {$months[11]} et {$months[12]}",
);
$half_yearly = ceil($cur_month/6);
$user_exceeded_subs_limit = false;
$user_exceeded_noshow_limit = false;
$flexible_moderation_is_applied = false;
$mod_info = array(
"allowed" => true,
"is_user_moderated" => 0,
"nr_exceeded" => $user_exceeded_subs_limit,
"max_res" => 0,
"mod_nr_count" => 0,
"res_period" => '',
"res_period2" => '',
"ns_exceeded" => $user_exceeded_noshow_limit,
"max_ns" => 0,
"ns_count" => 0,
"ns_period" => '',
"ns_period2" => '',
"noshow_msg" => '',
"res_msg" => '',
"wldata" => null
);
/**
* Check if susbcriber should by pass moderation for all events or not
*/
$this->load->model('user_subscriber_model');
$checkModeration = $this->user_subscriber_model->get_user_moderation( $subscriber );
if(!$this->checkIfSubscriberIsModeratedOrNot($checkModeration)) {
/**
* Test Event
* event_id: 521
* event_schedule_id: 637
*
* Below, checks reservation on each scenario
*/
/*
* Get moderation settings for the event, if there's none then allow
*/
$mod_sett = $this->getLatestModerationSettings(3, 1, 1);
$mod_sett_main = $mod_sett['main_settings'];
$mod_sett_sub = $mod_sett['sub_settings'];
$ev_mod_sett = $this->event_moderation_model->getEvSchedModSettings($eventScheduleId);
$waitList = $this->event_moderation_model->queryCheckSubscriberInWaitingList($eventScheduleId, $subscriber);
do {
/**
* Implementation of New SSO.
* capping: (true = the subscriber will be under the moderation (capping),
* (false = the subscriber will not be under moderation)
*/
// if (!$this->isModerationUnderCapping()) {
// $this->canReserve = self::ALLOWED;
// break;
// }
/*
* If no settings is found then ALLOW
*/
if (count($mod_sett) == 0 || count($ev_mod_sett) == 0) {
$this->canReserve = self::ALLOWED;
break;
}
/*
* If global moderation is turned off OR event schedule mod stat is turned off
*/
if (!$mod_sett_main['gm_mod_stat'] || !$ev_mod_sett['mod_stat']) {
$this->canReserve = self::ALLOWED;
break;
}
/*
* If flexible moderation is applied then ALLOW
*/
if ($ev_mod_sett['flex_mod_applied'] && $ev_mod_sett['flex_mod_stat']) {
$this->canReserve = self::ALLOWED;
break;
}
/*
* check if user exceeded number of noshow if moderation per noshow is turned on
*/
if ($mod_sett_main['noshow_psub_stat']) {
/*
* If max_noshow is null or 0 OR noshow period is null or zero then allow
* Noshow period is in days. So count number of moderation in the past "nshow_period" days then validate
*/
if ($mod_sett_sub['max_noshow'] && $mod_sett_sub['nshow_period']) {
/*
* If maximum noshow and noshow period is set
* Check If the user exceeded or is equal to the number of full noshow
*/
$nshow_period = $mod_sett_sub['nshow_period'];
$noshow_count = $this->event_moderation_model->getNumberOfNoshow($nshow_period, $subscriber);
if ($noshow_count >= $mod_sett_sub['max_noshow']) {
$user_exceeded_noshow_limit = true;
$mod_info['ns_exceeded'] = true;
$mod_info['max_ns'] = $mod_sett_sub['max_noshow'];
$mod_info['ns_period'] = $mod_sett_sub['nshow_period'];
$mod_info['ns_period2'] = $this->event_moderation_model->noShowDateWhenToResumeReservation($this->data['logged_in']['user_id'], $mod_sett_sub['max_noshow'], $mod_sett_sub['nshow_period']);
$mod_info['noshow_msg'] = "You reached the maximum number of noshows which is {$mod_sett_sub['max_noshow']}";
}
}
}
/*
* check if user exceeded number of subscription if moderation per subscription is turned on
*/
if ($mod_sett_main['res_psub_stat']) {
/*
* If max reservation is null or 0 OR res_period_type is null allow
* res_period_type is
* => 0 = monthly
* => 1 = quarterly
* => 2 = Half year
* => 3 = Yearly
*/
if ($mod_sett_sub['max_res'] && !is_null($mod_sett_sub['res_period_type'])) {
/*
* If max reservation and reservation period type is set
* Get number of reservations based on the period and validate
*/
$mod_info['max_res'] = $mod_sett_sub['max_res'];
// Get total reservation
$reservation_count = $this->event_moderation_model->getNumberOfReservation(
$mod_sett_sub['res_period_type'],
$subscriber,
false,
1,
0,
['cur_year' => $cur_year, 'cur_month' => $cur_month],
true
);
if ($reservation_count >= $mod_sett_sub['max_res']) {
$user_exceeded_subs_limit = true;
$mod_info['mod_nr_count'] = $reservation_count;
$mod_info['nr_exceeded'] = $user_exceeded_subs_limit;
/*Identify period type*/
switch ($mod_sett_sub['res_period_type']) {
case 0:
$mod_info['res_period'] = 'par mois';
$mod_info['res_period2'] = "pour {$cur_month_text}";
$mod_info['when_can_reserve'] = "jusqu'à la fin du mois";
break;
case 1:
$mod_info['res_period'] = "par trimestre";
$mod_info['res_period2'] = "pour les mois de {$cur_q_months[$cur_quarter]}";
$mod_info['when_can_reserve'] = "jusqu'à la fin du trimestre";
break;
case 2:
// $mod_info['res_period'] = "the ".(getOrdinal($half_yearly))." half of this year";
$mod_info['res_period'] = "par semestre";
$mod_info['res_period2'] = "pour le ".($half_yearly == 1? "premier":"second")." semestre";
$mod_info['when_can_reserve'] = "jusqu'à la fin du ".($half_yearly == 1? "premier":"second")." semestre";
break;
case 3:
$mod_info['res_period'] = 'par an';
$mod_info['res_period2'] = "pour l'année en cours";
$mod_info['when_can_reserve'] = "jusqu'à la fin de l'année";
break;
default:
// code...
break;
}
$mod_info['res_msg'] = "You reached the maximum number of reservations which is {$mod_sett_sub['max_res']}";
} else {
$mod_info['res_msg'] = "You have ".($mod_sett_sub['max_res'] - $reservation_count)." reservations left";
}
}
}
/*
* If user exceeded max noshows or reservations do not allow reserving else allow
*/
if (!$mod_sett_main['gm_mod_stat'] || !$ev_mod_sett['mod_stat'] || $waitList['reservedInWL'] == 1) {
$this->canReserve = self::ALLOWED;
if ($user_exceeded_noshow_limit || $user_exceeded_subs_limit) {
$mod_info['is_user_moderated'] = 1;
}
break;
}
if ($user_exceeded_noshow_limit || $user_exceeded_subs_limit) {
$this->canReserve = self::MODERATED;
$mod_info['is_user_moderated'] = 1;
break;
} else {
$this->canReserve = self::ALLOWED;
break;
}
} while (!$validated);
} else {
$this->canReserve = self::ALLOWED;
}
$mod_info['allowed'] = $this->canReserve;
$mod_info['wldata'] = $this->canReserve ? null : $this->verifyWL($eventId, $eventScheduleId, $waitList);
return output_to_json($this, $mod_info);
}
/**
*
* @method get information for my reservations
* @access public
* @return array
*
*/
public function getModerationInfoForFirstLogin()
{
//get the loggedin user
$subscriber = $this->data["logged_in"]["user_id"];
$my_reservation_info = array(
"max_res" => 0,
"res_period" => 0,
"mod_nr_count" => 0,
"remaining_res" => 0,
"max_noshow" => 0,
"total_noshow" => 0,
"nshow_period" => 0,
);
/*
* GET MODERATION SETTINGS
*/
$mod_sett = $this->getLatestModerationSettings(3, 1, 1);
$mod_sett_main = $mod_sett['main_settings'];
$mod_sett_sub = $mod_sett['sub_settings'];
$mod_sett_sub['max_res'] = (int)$mod_sett_sub['max_res'];
try {
if ($mod_sett_main['noshow_psub_stat']) {
if ($mod_sett_sub['max_noshow'] && $mod_sett_sub['nshow_period']) {
$noshow_count = $this->event_moderation_model->getNumberOfNoshow($mod_sett_sub['nshow_period'], $subscriber);
if (!is_null($noshow_count)) {
$my_reservation_info['total_noshow'] = $noshow_count;
}
$my_reservation_info['max_noshow'] = $mod_sett_sub['max_noshow'];
$my_reservation_info['nshow_period'] = $mod_sett_sub['nshow_period']." days";
}
}
if ($mod_sett_main['res_psub_stat']) {
if (isset($mod_sett_sub['max_res']) && isset($mod_sett_sub['res_period_type'])) {
$months = array('Tous les mois', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai',
'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
$cur_year = date("Y", time());
$cur_month = date("n", time());
$cur_month_text = $months[date("n", time())];
$cur_quarter = ceil($cur_month/3);
/*
* months per quarter
*/
$cur_q_months = array(
1 => "{$months[1]}, {$months[2]} et {$months[3]}",
2 => "{$months[4]}, {$months[5]} et {$months[6]}",
3 => "{$months[7]}, {$months[8]} et {$months[9]}",
4 => "{$months[10]}, {$months[11]} et {$months[12]}",
);
$half_yearly = ceil($cur_month/6);
$reservation_count = $this->event_moderation_model->getNumberOfReservation($mod_sett_sub['res_period_type'], $subscriber, false, 1, 0, [], true);
if (!is_null($reservation_count)) {
$my_reservation_info['mod_nr_count'] = $reservation_count;
$my_reservation_info['remaining_res'] = max(($mod_sett_sub['max_res']-$reservation_count),0);
}
$my_reservation_info['max_res'] = $mod_sett_sub['max_res'];
/*Identify period type*/
switch ($mod_sett_sub['res_period_type']) {
case 0:
$my_reservation_info['res_period'] = 'mois';
$my_reservation_info['res_period2'] = "pour le mois de {$cur_month_text}";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du mois";
break;
case 1:
$my_reservation_info['res_period'] = "trimestre";
$my_reservation_info['res_period2'] = "pour les mois de {$cur_q_months[$cur_quarter]}";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du trimestre";
break;
case 2:
$my_reservation_info['res_period'] = "semestre";
$my_reservation_info['res_period2'] = "pour le ".($half_yearly == 1? "premier":"second")." semestre";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du ".($half_yearly == 1? "premier":"second")." semestre";
break;
case 3:
$my_reservation_info['res_period'] = 'an';
$my_reservation_info['res_period2'] = "pour l'année en cours";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin de l'année";
break;
default:
// code...
break;
}
}
}
output_to_json($this, $my_reservation_info);
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
*
* @method get information for my reservations
* @access public
* @return array
*
*/
public function getMyReservationsInfo($get_array = false)
{
//get the loggedin user
$subscriber = $this->data["logged_in"]["user_id"];
$my_reservation_info = array(
"max_res" => 0,
"res_period" => 0,
"total_reservation_mod_event_count" => 0,
"remaining_res_current_period" => 0,
"remaining_res_next_period" => 0,
"max_noshow" => 0,
"total_noshow" => 0,
"nshow_period" => 0,
"total_reservation_count" => 0,
"cancel_events_count" => 0,
"gm_mod_stat" => 0
);
/*
* GET MODERATION SETTINGS
*/
$mod_sett = $this->getLatestModerationSettings(3, 1, 1);
$mod_sett_main = $mod_sett['main_settings'];
$mod_sett_sub = $mod_sett['sub_settings'];
$mod_sett_sub['max_res'] = (int)$mod_sett_sub['max_res'];
try {
if($mod_sett_main['gm_mod_stat']=='0'){
$total_reservation_count = $this->event_moderation_model->getNumberOfReservation(3, $subscriber, true, 1, 0, [], false, true);
$total_cancel_events_count = $this->event_moderation_model->getNumberOfCancelledReservation(3, $subscriber, true, 1, 0, [], false, true);
$my_reservation_info['total_reservation_count'] = $total_reservation_count;
$my_reservation_info['cancel_events_count'] = $total_cancel_events_count;
}
if ($mod_sett_main['noshow_psub_stat']) {
if ($mod_sett_sub['max_noshow'] && $mod_sett_sub['nshow_period']) {
$noshow_count = $this->event_moderation_model->getNumberOfNoshow($mod_sett_sub['nshow_period'], $subscriber);
if (!is_null($noshow_count)) {
$my_reservation_info['total_noshow'] = $noshow_count;
}
$my_reservation_info['max_noshow'] = $mod_sett_sub['max_noshow'];
$my_reservation_info['nshow_period'] = $mod_sett_sub['nshow_period']." days";
}
}
if ($mod_sett_main['res_psub_stat']) {
if (isset($mod_sett_sub['max_res']) && isset($mod_sett_sub['res_period_type'])) {
$months = array('Tous les mois', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai',
'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
$cur_year = date("Y", time());
$cur_month = date("n", time());
$cur_month_text = $months[date("n", time())];
$cur_quarter = ceil($cur_month/3);
/*
* months per quarter
*/
$cur_q_months = array(
1 => "{$months[1]}, {$months[2]} et {$months[3]}",
2 => "{$months[4]}, {$months[5]} et {$months[6]}",
3 => "{$months[7]}, {$months[8]} et {$months[9]}",
4 => "{$months[10]}, {$months[11]} et {$months[12]}",
);
$half_yearly = ceil($cur_month/6);
// Total number or events the subscriber is currently reserved ( moderated events included )
$total_reservation_count = $this->event_moderation_model->getNumberOfReservation(3, $subscriber, true, 1, 0, [], false, true);
// Total number of moderated events reserved
$total_reservation_mod_event_count = $this->event_moderation_model->getNumberOfReservation(3, $subscriber, false, 1);
// Total number of moderated events reserved for the current period
$total_reservation_mod_event_count_current_period = $this->event_moderation_model->getNumberOfReservation($mod_sett_sub['res_period_type'], $subscriber, false, 1, 0, [], true);
// Get reservations for the next period (next [month, quater, year])
$total_reservation_mod_event_count_next_period = $this->event_moderation_model->getNumberOfReservation($mod_sett_sub['res_period_type'], $subscriber, false, 1, 1, [], true);
// Total number or events the subscriber is currently cancelled ( moderated events included )
$total_cancel_events_count = $this->event_moderation_model->getNumberOfCancelledReservation(3, $subscriber, true, 1, 0, [], false, true);
// print_r($total_reservation_mod_event_count_next_period);
if (!is_null($total_reservation_count)) {
$my_reservation_info['total_reservation_mod_event_count'] = $total_reservation_mod_event_count;
// You can still book [X] event (s) subject to moderation (picto) in [current period].
$my_reservation_info['remaining_res_current_period'] = max(($mod_sett_sub['max_res'] - $total_reservation_mod_event_count_current_period),0);
// You can still book [X] event (s) subject to moderation (picto) in [next period].
$my_reservation_info['remaining_res_next_period'] = max(($mod_sett_sub['max_res'] - $total_reservation_mod_event_count_next_period),0);
}
$my_reservation_info['max_res'] = $mod_sett_sub['max_res'];
$my_reservation_info['total_reservation_count'] = $total_reservation_count;
$my_reservation_info['cancel_events_count'] = $total_cancel_events_count;
$my_reservation_info['gm_mod_stat'] = $mod_sett_main['gm_mod_stat'];
/*Identify period type*/
switch ($mod_sett_sub['res_period_type']) {
case 0:
$my_reservation_info['res_period'] = 'par mois';
// $my_reservation_info['res_period2'] = "pour le mois de {$cur_month_text}";
$my_reservation_info['res_period2'] = mb_strtolower($cur_month_text);
// removing first array element
array_shift($months);
$my_reservation_info['res_period3'] = mb_strtolower($months[date("n", strtotime("next month"))-1]);
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du mois";
break;
case 1:
$my_reservation_info['res_period'] = "par trimestre";
$my_reservation_info['res_period2'] = "trimestriel";
// $my_reservation_info['res_period2'] = "pour les mois de {$cur_q_months[$cur_quarter]}";
$my_reservation_info['res_period3'] = "trimestriel";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du trimestre";
break;
case 2:
$my_reservation_info['res_period'] = "par semestre";
// $my_reservation_info['res_period2'] = "pour le ".($half_yearly == 1? "premier":"second")." semestre";
$my_reservation_info['res_period2'] = "semestriel";
$my_reservation_info['res_period3'] = "semestriel";
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin du ".($half_yearly == 1? "premier":"second")." semestre";
break;
case 3:
$my_reservation_info['res_period'] = 'par an';
// $my_reservation_info['res_period2'] = "pour l'année en cours";
$my_reservation_info['res_period2'] = date('Y');
$my_reservation_info['res_period3'] = date('Y') + 1;
$my_reservation_info['when_can_reserve'] = "jusqu'à la fin de l'année";
break;
default:
// code...
break;
}
}
}
if ($get_array) {
return $my_reservation_info;
}
output_to_json($this, $my_reservation_info);
} catch (\Exception $e) {
throw new Exception('No settings detected');
}
}
/**
* Check if user has waiting list that is saved before or not.
* If no waiting list yet then the user will have to register to WL otherwise modify current WL registration
* @method verifyWLData
* @param array $waitListData Array of waitinglist data of the user for the current event
* @return void
*/
private function verifyWL(int $eventId, int $eventScheduleId, array $waitList)
{
$result = array("canReserveInWL" => false, "data"=>[]);
if($waitList['reservedInWL'] != 1)
{
$checkIfCanReserveInWL = $this->event_model->check_seats($eventScheduleId, 2);
$action = (($waitList['reservedInWL'] && $checkIfCanReserveInWL) ? 'modify': ($waitList['reservedInWL'] && !$checkIfCanReserveInWL) ? 'cancel': ((bool)$checkIfCanReserveInWL ? 'register' : 'full'));
$result['ps'] = array(
'event_id' => $eventId,
'event_schedule_id' => $eventScheduleId,
'action' => $action,
'check_subscription' => 1,
'process_type' => (($action == 'modify') ? 7: ($action == 'cancel') ? 4: 3),
'reg_type' => 2,
'request_type' => 1,
);
$result['data'] = $waitList['data'];
$result['canReserveInWL'] = (bool)$checkIfCanReserveInWL;
return $result;
}
return $result;
}
/**
* Check if Moderation capping is enabled or disabled
*
* Make sure this limitation applies to real subscribers and not admin login as subscriber
* @return @boolean
*/
private function isModerationUnderCapping() {
// if (isset($this->data['logged_in']['sso']) && !empty($this->data['logged_in']['sso']) && !isBOUserLoggedInAsSubscriber()) {
// return $this->data['logged_in']['sso']['capping'];
// }
return false;
}
/**
* Cannot reserve
* - Service Les evenements : False
* - Premium : True
* - Capping : True (or False or null)
*
* Make sure this limitation applies to real subscribers and not admin login as subscriber
* @return @boolean
*/
private function isAccountPremiumButNotAllowedToReserve() {
// if (isset($this->data['logged_in']['sso']) && !empty($this->data['logged_in']['sso']) && !isBOUserLoggedInAsSubscriber()) {
// return $this->data['logged_in']['sso']['premium'] && !in_array("evenements_abonnes", $this->data['logged_in']['sso']['services']);
// }
return false;
}
}