<?php namespace App\Models\Admin;

use App\Models\Project\DatatableModel;

class ClientsModel extends AdminModel{
	private $table;
	
    public function __construct(){
		parent::__construct();
		$this->table = "client";
    }
	
	public function get_datatable(){
		$dtObj = new DatatableModel($this->db);
		$dtObj->set_table($this->table);
		// Set Datatable columns 
		$dtObj->set_column('client_id', 'desc', 'RecordID');
		$dtObj->set_column('title', 'sort|search');
		$dtObj->set_column('logo', 'sort|search');
		$dtObj->set_column('status', 'sort|search');
		$builder = $dtObj->get_builder();
		$builder->where('is_deleted','No');
		return $dtObj->get_data($builder);
	}
	
	public function get($client_id){
		$builder = $this->db->table($this->table);
		$query = $builder->where('client_id',$client_id)->get();
		return $query->getRowArray();
	}
	
	public function insert($data){
		$this->add_insert_log($data);
		$builder = $this->db->table($this->table);
		$builder->insert($data);
	}
	
	public function update($data, $client_id){
		$this->add_update_log($data);
		$builder = $this->db->table($this->table);
		$builder->where('client_id',$client_id);
		$builder->update($data);
	}
	
	
	public function delete($client_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table($this->table);
		$builder->where('client_id',$client_id)
				->update($data);
	}
}