<?php namespace App\Models\Admin;
 
use App\Models\Project\DatatableModel;

class DocumentFormData extends AdminModel{
	private $table;
	
    public function __construct(){
		parent::__construct();
		$this->table = "document_form_data";
    }
	
	public function get_datatable(){
		$dtObj = new DatatableModel($this->db);
		$dtObj->set_table($this->table);
		// Set Datatable columns 
		$dtObj->set_column('doc_id', 'desc|sort|search', 'RecordID');
		$dtObj->set_column('doc_name', 'sort|search');	
		$dtObj->set_column('doc_email', 'sort|search');	
		$dtObj->set_column('doc_contact_number ', '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($doc_id){
		$builder = $this->db->table($this->table);
		$query = $builder->where('doc_id',$doc_type_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 delete($doc_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table($this->table);
		$builder->where('doc_type_id',$doc_type_id)
				->update($data);
	}
	
	public function is_unique_doc_type_name($name,$doc_id){
		$builder = $this->db->table($this->table);
		$builder->where('is_deleted','No')
				->where('name',$name);
		if($doc_type_id){
			$builder->where('doc_id!=',$doc_id);
		}
		$query = $builder->get();
		if($query->getRowArray()){
			$response = "FALSE|The Name already exist!";
		}else{
			$response = "TRUE|";
		}
		return $response;
	}
	
	
}