Import_model.php 1.74 KB
<?php 
class Import_model extends CI_Model {
	
	public function _consruct(){
		parent::_construct();
 	}

 	public function checkBrand($brand){
 		$result = $this->db->get_where('product_brand',array('brand_name'=>$brand));
 		if(empty($result) || $result->num_rows() <  0 || empty($result = $result->row_array())){
 			$this->db->insert('product_brand',array('brand_name'=>$brand,'brand_logo'=>'assets/images/user_avatar.png'));
 			$result['brand_id'] = $this->db->insert_id();
 		}
 		return $result['brand_id'];
 	}

 	public function checkCardetails($year,$brand,$model){
 		$brandData = $this->db->get_where('vehicles_brand',array('maker'=>$brand));
 		if(empty($brandData) || $brandData->num_rows() < 0 || empty($brandData = $brandData->row_array())){
 			$this->db->insert('vehicles_brand',array('maker'=>$brand));
 			$brandData['veh_brand_id'] = $this->db->insert_id();
 		}
 		$modelData = $this->db->get_where('vehicles_model',array('veh_brand_id'=>$brandData['veh_brand_id'],'model'=>$model));
 		if(empty($modelData) || $modelData->num_rows < 0 || empty($modelData = $modelData->row_array())){
 			$this->db->insert('vehicles_model',array('veh_brand_id'=>$brandData['veh_brand_id'],'model'=>$model));
 			$modelData['veh_modal_id'] = $this->db->insert_id();
 		}
 		$carData = $this->db->get_where('cardetails',array('year'=>$year,'veh_modal_id'=>$modelData['veh_modal_id']));
 		if(empty($carData) || $carData->num_rows < 0 || empty($carData = $carData->row_array())){
 			$this->db->insert('cardetails',array('year'=>$year,'veh_modal_id'=>$modelData['veh_modal_id']));
 			$carData['id'] = $this->db->insert_id();
 		}
 		return $carData['id'];
 	}

 	public function addProduct($new = array()){
 		if($this->db->insert('products',$new)){
 			return 1;
 		}
 	}
}
?>