1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?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;
}
}
}
?>