<?php
class Cir_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function cir_products()
{
$this->db->select('product_id');
$this->db->from('product_master');
$this->db->like('product_name','CIR Monthly');
$this->db->order_by('product_id','ASC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function cir_subscribers($arr)
{
$this->db->select('id,first_name,last_name,mobile,email,user_type,subscription_type,is_checked'); $this->db->from('subscription_register');
$this->db->where('user_type','Register');
$this->db->where_in('subscription_type',$arr);
$query = $this->db->get();
return $query->result();
}
public function subscribers($value = 1)
{
$this->db->select('id,first_name,last_name,mobile,email,user_type,subscription_type,is_checked');
$this->db->from('subscription_register');
$this->db->where('user_type','Register');
$this->db->where_in('is_checked',$value);
$query = $this->db->get();
//echo $this->db->last_query(); die;
return $query->result();
}
public function get_reports()
{
$this->db->select("cr.*,GROUP_CONCAT(concat(sr.first_name,' ',sr.last_name) SEPARATOR ',') AS subscriber_name");
$this->db->from('cir_reports as cr');
$this->db->join("subscription_register as sr","find_in_set(sr.id,cr.subscriber_id)<> 0","left",false);
$this->db->group_by("cr.id");
$query = $this->db->get();
return $query->result();
}
public function set_report($data)
{
$this->db->insert('cir_reports',$data);
//echo $this->db->lastquery();
if($this->db->insert_id())
{
return true;
}
else
{
return false;
}
}
public function get_report($id)
{
$this->db->select('id,subscribe_month,subscribe_year,last_updation,subscribe_link');
$this->db->from('cir_reports');
$this->db->where('id',$id);
$query = $this->db->get();
return $query->result();
}
public function check_report($data)
{
$this->db->select('*');
$this->db->from('cir_reports');
$this->db->where($data);
$query = $this->db->get();
return $query->num_rows();
}
public function check_lite_report($data)
{
$this->db->select('*');
$this->db->from('lite_cir_reports');
$this->db->where($data);
$query = $this->db->get();
return $query->num_rows();
}
public function update_report($data)
{
$update_data = array(
'subscribe_month' => $data['subscribe_month'],
'subscribe_year' => $data['subscribe_year'],
'last_updation' => $data['last_updation'],
'subscribe_link' => $data['subscribe_link']
);
$this->db->where('id',$data['id']);
$this->db->update('cir_reports',$update_data);
if($this->db->affected_rows()>0)
{
return true;
}
else
{
return false;
}
}
public function delete($id)
{
$this->db->where('id', $id);
$this->db->delete('cir_reports');
return true;
}
public function get_tracking_data()
{
$this->db->select('id, job_id,user_email as email, report_name,status, sent_at, error_message');
$this->db->from('email_delivery_tracking');
$query = $this->db->get();
return $query->result_array();
}
} |