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.
307 lines
9.5 KiB
307 lines
9.5 KiB
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class User_subscriber_model extends CI_Model {
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function add_subscriber_data($data){
|
|
$this->db->insert('user_subscriber', $data);
|
|
return $this->db->insert_id();
|
|
}
|
|
|
|
public function getSubscribers($where = [], $joinEvent = true) {
|
|
$result = $joinEvent === true
|
|
? $this->db
|
|
->select('*')
|
|
->from('user_subscriber as us')
|
|
->join('user as u', 'u.user_id = us.subscriber')
|
|
->join('event_registration as er', 'er.subscriber = us.subscriber AND er.subscriber=u.user_id', 'left')
|
|
->where($where)
|
|
->where('u.status', 1)
|
|
->get()
|
|
: $this->db
|
|
->where($where)
|
|
->get('user_subscriber');
|
|
|
|
return $result->result();
|
|
}
|
|
|
|
public function setPreferences($user_id, $location, $mail, $email, $tel, $mobile)
|
|
{
|
|
$settings = array(
|
|
'address' => $location,
|
|
'additional_address' => $mail,
|
|
// 'email_address' => $email,
|
|
'phone' => $tel,
|
|
'mobile' => $mobile
|
|
);
|
|
$this->db->where('subscriber', $user_id);
|
|
$this->db->update('user_subscriber', $settings);
|
|
}
|
|
|
|
public function myaccount($user_id)
|
|
{
|
|
$query = $this->db->select("us.subscriber_id, us.civility, us.birthday, us.company, us.sponsorship, us.news_subscription, us.profession, us.address, us.additional_address, us.country, us.postal_code, us.city, us.phone, us.mobile, u.email_address, u.first_name, u.last_name, u.user_id")
|
|
->from('user_subscriber us')
|
|
->join('user u', 'u.user_id = us.subscriber', 'left')
|
|
->where('us.subscriber', $user_id)
|
|
->where('u.status', 1)
|
|
->get();
|
|
// return $user_id;
|
|
return $query->row();
|
|
}
|
|
|
|
public function update_field($user_id, $login_id)
|
|
{
|
|
$datas = "";
|
|
|
|
$data = $this->input->post('params');
|
|
$field = $this->input->post('field');
|
|
$unlock_action = $this->input->post('unlock_action');
|
|
$table = $this->input->post('table');
|
|
|
|
$id = $this->input->post('id');
|
|
$table = $this->input->post('table');
|
|
|
|
if($field=="birthday") {
|
|
if( $data !="" ){
|
|
$split = explode("/",$data);
|
|
$datas = $split[2]."-".$split[1]."-".$split[0];
|
|
}else{
|
|
$datas = NULL;
|
|
}
|
|
}else if($field=="civility") {
|
|
if( $data != "" ){
|
|
|
|
$datas = $data;
|
|
}else{
|
|
$datas = NULL;
|
|
}
|
|
}else if($field=="mobile" || $field =="phone") {
|
|
if( $data != "" ){
|
|
$datas = trim($data);
|
|
}else{
|
|
$datas = NULL;
|
|
}
|
|
}else{
|
|
$datas = $data;
|
|
}
|
|
|
|
$this->db->set($field, $datas);
|
|
$this->db->where($id, $user_id);
|
|
$this->db->update($table);
|
|
|
|
//$this->lock_action($unlock_action, $login_id);
|
|
}
|
|
|
|
public function lock_action($process_type, $login_id){
|
|
$this->db->set('process_status', 1);
|
|
$this->db->where('login_id', $login_id);
|
|
$this->db->where('process_type', $process_type);
|
|
$this->db->update('event_concurrent_process');
|
|
}
|
|
public function unlock_action($process_type, $login_id)
|
|
{
|
|
$this->db->set('process_status', 0);
|
|
$this->db->where('login_id', $login_id);
|
|
$this->db->where('process_type', $process_type);
|
|
$this->db->update('event_concurrent_process');
|
|
}
|
|
|
|
public function create_client_account($id)
|
|
{
|
|
$current_date = date('Y-m-d');
|
|
$this->db->insert('user_subscriber',
|
|
array(
|
|
'subscriber' => $id,
|
|
'subscription_date' => $current_date
|
|
)
|
|
);
|
|
}
|
|
|
|
public function email_registered($user_id)
|
|
{
|
|
$query = $this->db->select('u.email_address, u.user_id, u.first_name, u.last_name')
|
|
->from('user u')
|
|
->where('u.user_id', $user_id)
|
|
->get()
|
|
->row();
|
|
return $query;
|
|
}
|
|
|
|
public function check_profile_info_update($user_id, $field, $profile_info)
|
|
{
|
|
|
|
$data = "";
|
|
$row_data ;
|
|
|
|
if( $field == "first_name" || $field == "last_name"){
|
|
|
|
$query = $this->db->select($field)->from('user')->where('user_id', $user_id)->get();
|
|
$row = $query->row();
|
|
|
|
if($row) {
|
|
if(strtolower($row->$field) != strtolower($profile_info))
|
|
{
|
|
return array(
|
|
'status' => true,
|
|
'field' => "#".$field,
|
|
'data' => $row->$field
|
|
);
|
|
}
|
|
}
|
|
}else if( $field == "preferences" ){
|
|
$list_preferences = [];
|
|
$list_ids = [];
|
|
foreach ($this->user_subscriber_event_preference_model->myaccount($user_id) as $key => $event_types) {
|
|
array_push($list_preferences, $event_types->event_type);
|
|
array_push($list_ids, $event_types->event_preference);
|
|
}
|
|
|
|
if( $profile_info != implode(", ", $list_preferences) ){
|
|
return array(
|
|
'status' => true,
|
|
'field' => "#".$field,
|
|
'preference_ids' => ($list_ids)?$list_ids:null,
|
|
'data' => implode(", ", $list_preferences)
|
|
);
|
|
}
|
|
}else{
|
|
|
|
$query = $this->db->select($field)->from('user_subscriber')->where('subscriber', $user_id)->get();
|
|
$row = $query->row();
|
|
|
|
|
|
if($row)
|
|
{
|
|
$row->$field = trim($row->$field);
|
|
$profile_info = trim($profile_info);
|
|
|
|
if($field == "birthday" && $profile_info !== ''){
|
|
$split = explode("/",$profile_info);
|
|
$profile_info = $split[2]."-".$split[1]."-".$split[0];
|
|
|
|
$split2 = explode("-",$row->$field);
|
|
$data = $split2[2]."/".$split2[1]."/".$split2[0];
|
|
$row_data = $row->$field;
|
|
|
|
}else if( $field =="phone" || $field =="mobile" ){
|
|
$profile_info = ($profile_info != "" && $profile_info != null)?str_replace(" ", "+", $profile_info):"";
|
|
// $data = $row_data = ( trim($profile_info) !== "" ? remove_brackets(array( '[', ']' ), (strpos($row->$field, '+') !== false ? $row->$field : $row->$field) ) : "");
|
|
$row_data = ($row->$field!="" && $row->$field!=null)?str_replace(" ", "+", $row->$field):"";
|
|
$data = ($row->$field!="" && $row->$field!=null)?$row->$field:"";
|
|
|
|
}else if($field == "civility"){
|
|
$data = ucfirst($row->$field);
|
|
$row_data = $row->$field;
|
|
}else{
|
|
$data = $row->$field;
|
|
$row_data = $row->$field;
|
|
}
|
|
|
|
if(strtolower($row_data) != strtolower( $profile_info ) )
|
|
{
|
|
return array(
|
|
'status' => true,
|
|
'field' => "#".$field,
|
|
'row_data' => (strtolower($row_data) != strtolower( $profile_info )),
|
|
'data' => $data
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return array('status' => false);
|
|
}
|
|
|
|
/**
|
|
* Nofity user on his/her first login about the new feature - Moderation
|
|
* @method notifyUserABoutModerationFeature
|
|
* @param int $subscriber
|
|
* @return bool
|
|
*/
|
|
public function notifyUserABoutModerationFeature(int $subscriber) :bool {
|
|
|
|
if(!isset($subscriber) || empty($subscriber)) {
|
|
return false;
|
|
}
|
|
|
|
$this->db->select('notify_for_moderation_feature');
|
|
$this->db->where('subscriber', $subscriber);
|
|
$this->db->where('notify_for_moderation_feature', 0);
|
|
$this->db->limit(1);
|
|
$result = $this->db->get('user_subscriber')->num_rows();
|
|
if($result) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Set notif to on once the user has been notified about the new feature moderation
|
|
* @method notif_moderation_feature
|
|
* @param int $subscriber
|
|
* @return void
|
|
*/
|
|
public function notif_moderation_feature(int $subscriber) :void {
|
|
$this->db->where('subscriber', $subscriber);
|
|
$this->db->where('notify_for_moderation_feature', 0);
|
|
$this->db->update('user_subscriber', array('notify_for_moderation_feature' => 1));
|
|
}
|
|
|
|
/**
|
|
* Enable or Disable Moderation of the user, If disable, user is allowed to subscribe in any event regardless of moderation
|
|
* @method enable_disable_user_moderation
|
|
* @param array $post
|
|
* @return boolean
|
|
*/
|
|
public function enable_disable_user_moderation(array $post) :bool {
|
|
$this->db->where('subscriber', $post['subscriber_id']);
|
|
$moderation = array('isModerationDisabled' => (int) $post['isModerationDisabled']);
|
|
if($moderation['isModerationDisabled'] && ( isset($post['number_of_days_in_moderation']) && !empty($post['number_of_days_in_moderation']))) {
|
|
$this->db->set('numberOfDaysModeratedDateAdded', 'NOW()', FALSE);
|
|
$this->db->set('numberOfDaysModerated', $post['number_of_days_in_moderation'], FALSE);
|
|
} else {
|
|
$this->db->set('numberOfDaysModeratedDateAdded', 'NULL', FALSE);
|
|
$this->db->set('numberOfDaysModerated', 0, FALSE);
|
|
}
|
|
return $this->db->update('user_subscriber', $moderation);
|
|
}
|
|
|
|
public function get_user_moderation(int $subscriber_id) :stdClass {
|
|
|
|
return $this->db->query(
|
|
"SELECT isModerationDisabled,
|
|
numberOfDaysModerated,
|
|
numberOfDaysModeratedDateAdded,
|
|
(CASE
|
|
WHEN numberOfDaysModerated > 0 && isModerationDisabled > 0 THEN 1
|
|
ELSE 0
|
|
END) AS isModeratedByDate
|
|
FROM user_subscriber
|
|
WHERE subscriber = ?
|
|
",array($subscriber_id))->row();
|
|
}
|
|
|
|
public function automatic_disable_moderation_events() {
|
|
$this->db->query("
|
|
UPDATE user_subscriber SET isModerationDisabled = 0
|
|
WHERE numberOfDaysModerated > 0 && isModerationDisabled > 0
|
|
AND DATE_ADD(numberOfDaysModeratedDateAdded, INTERVAL (numberOfDaysModerated) DAY) < NOW()
|
|
");
|
|
}
|
|
|
|
public function is_email_exists($email_address)
|
|
{
|
|
return $this->db->select('u.user_id')
|
|
->from('user u')
|
|
->where('u.email_address', $email_address)
|
|
->where('u.role_id', USER_ROLES['regular'])
|
|
->where_not_in('u.status', 0)
|
|
->get()
|
|
->num_rows();
|
|
}
|
|
}
|
|
|