File: /var/www/html/pmw24/pmw_live_testing/app/application/models/admin/Mcustomer.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mcustomer extends CI_Model {
var $table = 'customer';
var $column_order = array('customer_id','customer_type','first_name','business_name','mobile','landline_no','email',null);
var $column_search = array('customer_id','customer_type','first_name','business_name','mobile','landline_no','email');
var $order = array('customer_id' => 'desc'); // default order
public function __construct() {
parent::__construct();
}
private function _get_datatables_query($status){
$this->db->select('customer.*,get_full_address_customer(customer.customer_id) as full_address');
$this->db->from($this->table);
$this->db->where('customer.status='.$status.'');
$i = 0;
foreach ($this->column_search as $item){ // loop column
if($_POST['search']['value']){
if($i===0){
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
}
else{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])){ // here order processing
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}else if(isset($this->order)){
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
public function get_datatables($status){
$this->_get_datatables_query($status);
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
//echo $this->db->last_query();die;
return $query->result();
}
public function count_filtered($status=NULL){
$this->_get_datatables_query($status);
$query = $this->db->get();
return $query->num_rows();
}
public function count_all(){
$this->db->from($this->table);
return $this->db->count_all_results();
}
public function get_details($admin_id){
$this->db->select('admins.*,DATE_FORMAT(admins.dob, "%d/%m/%Y") dob');
$this->db->from($this->table);
$this->db->where('admin_id',$admin_id);
$query=$this->db->get();
return $query->row_array();
}
public function get_user_slots($user_id){
$this->db->from('user_time_slot');
$this->db->where('user_id',$user_id);
$query=$this->db->get();
return $query->result_array();
}
public function update($condition,$data){
$this->db->where($condition);
$this->db->update($this->table,$data);
return 1;
}
public function add($data){
$this->db->insert($this->table,$data);
//echo $this->db->last_query(); exit() ;
return $this->db->insert_id();
}
public function delete($condition){
$this->db->delete($this->table,$condition);
return 1;
}
public function active($condition,$data){
$this->db->where($condition);
$this->db->update($this->table,$data);
return 1;
}
public function get_parent_category(){
$this->db->select('*');
$this->db->from('categories');
$this->db->where('parent_id=0');
$query=$this->db->get();
return $query->result_array();
}
public function get_cities(){
$this->db->select('*');
$this->db->from('city');
$query=$this->db->get();
return $query->result_array();
}
public function get_sub_category($category_id){
$this->db->select('*');
$this->db->from('categories');
$this->db->where('parent_id',$category_id);
$query=$this->db->get();
return $query->result_array();
}
public function get_sub_category_by_category_id($category_id){
$this->db->select('*');
$this->db->from('categories');
$this->db->where('category_id',$category_id);
$query=$this->db->get();
return $query->row_array();
}
public function get_parent_category_by_parent_id($parent_id){
$this->db->select('*');
$this->db->from('categories');
$this->db->where('category_id',$parent_id);
$query=$this->db->get();
return $query->row_array();
}
public function get_sub_categories_by_parent_id($parent_id){
$this->db->select('*');
$this->db->from('categories');
$this->db->where('parent_id',$parent_id);
$query=$this->db->get();
return $query->result_array();
}
public function get_category_by_id($category_id)
{
$this->db->select('*');
$this->db->from('categories');
$this->db->where('category_id',$category_id);
$query=$this->db->get();
return $query->row_array();
}
public function get_city_by_id($city_id)
{
$this->db->select('*');
$this->db->from('city');
$this->db->where('city_id',$city_id);
$query=$this->db->get();
return $query->row_array();
}
public function deviceList(){
$this->db->select('*');
$this->db->from('devices');
$this->db->join('users','users.user_id=devices.user_id','left');
$query=$this->db->get();
return $query->result_array();
}
public function getRows($table,$condition,$order_col=null,$order_type=null){
$this->db->where($condition);
if(isset($limit)){
$this->db->limit($limit);
}
if(!empty($order_col) && !empty($order_type)){
$this->db->order_by($order_col,$order_type);
}
$query=$this->db->get($table);
return $query->result_array();
}
public function getRow($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
//echo $this->db->last_query(); exit() ;
return $query->row_array();
}
public function check_email_exist($email,$customer_id){
$this->db->select('customer_id');
$this->db->from('customer');
$this->db->where('email', $email);
$this->db->where('customer_id !=', $customer_id);
$query = $this->db->get();
$num = $query->num_rows();
if ($num > 0) {
return FALSE;
} else {
return TRUE;
}
}
public function check_old_password($password,$customer_id){
$this->db->select('customer_id');
$this->db->from('customer');
$this->db->where('password', md5($password));
$this->db->where('customer_id', $customer_id);
$query = $this->db->get();
//echo $this->db->last_query(); exit() ;
$num = $query->num_rows();
if ($num > 0) {
return TRUE;
} else {
return FALSE;
}
}
public function check_recovery_key($recovery_key){
$this->db->select('customer_id');
$this->db->where('recovery_key',$recovery_key);
$query = $this->db->get('customer');
//echo $this->db->last_query(); die();
if ($query->num_rows() > 0){
return $query->row_array();
}else{
return false;
}
}
}