-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblogs_model.php
139 lines (125 loc) · 3.16 KB
/
blogs_model.php
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
class Blogs_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database("default");
}
/////// ----------------------- Product ----------------------------- ////////
function getBlogs($blog_id = "",$select = "",$where = "")
{
if(is_array($blog_id))
{
$where = " AND blog.blog_id IN ('".implode("','",$blog_id)."')";
}
else if($blog_id)
{
$where = " AND blog.blog_id = '".$blog_id."'";
}
if($select == "")
{
$select = "blog.*";
}
$sql = "SELECT ".$select."
FROM ".DBPREFIX."_blogs as blog";
// echo $sql;
$result = $this->db->query($sql);
if($result && $result->num_rows()>0)
{
return $result->result_array();
}
}
function insertBlog($data)
{
if(!(isset($data[0])))$data[0] = $data;
// echo "<pre>";print_r($data);die;
$this->db->insert_batch(DBPREFIX."_blogs", $data);
return TRUE;
}
function deleteProduct($blog_id)
{
$arr = array('blog_id' => $blog_id);
$this->db->where($arr);
$this->db->delete(DBPREFIX."_blogs", $arr);
// echo "update".$product_id;print_r($data);die;
return TRUE;
}
function updateProduct($blog_id,$data)
{
if(!(isset($data[0])))$data[0] = $data;
$arr = array('blog_id' => $blog_id);
$this->db->where($arr);
$this->db->update(DBPREFIX."_blogs", $data[0]);
// echo "update".$product_id;print_r($data);die;
return TRUE;
}
function updateProducts($data)
{
$this->db->update_batch(DBPREFIX."_product", $data, 'product_id');
return TRUE;
}
public function getProductsByID($blog_id)
{
$sql = "SELECT * FROM ".DBPREFIX."_blogs
WHERE blog_id = '".$blog_id."'
";
$result = $this->db->query($sql);
if($result && $result->num_rows()>0)
{
return $result->result_array();
}
}
public function GetCurrData()
{
$sql = "SELECT * FROM ".DBPREFIX."_currency";
$result = $this->db->query($sql);
return $result->result_array();
//print_r($test[0]['curr_amount']);die;
}
function getAllData()
{
$this->db->select('*');
$this->db->order_by('blog_id','DESC');
$this->db->from('_blogs');
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
public function getProduct($product_name="",$brand_id = "",$where = "",$offset="0",$limit="",$order = "",$select = "*")
{
$wherestr = "";
if($product_name)
{
$product_name = $this->db->escape_like_str($product_name);
$wherestr .= " AND (
blog_name = '".$product_name."' OR
blog_name LIKE '%".$product_name."%' OR
blog_name LIKE '%".$product_name."' OR
blog_name LIKE '".$product_name."%'
)";
}
if($brand_id)
{
$wherestr .= " AND (
brands_id = '".$brand_id."' OR
brands_id LIKE '%,".$brand_id.",%' OR
brands_id LIKE '%,".$brand_id."' OR
brands_id LIKE '".$brand_id.",%'
)";
}
$wherestr .= $where;
if($limit)$limit = "LIMIT ".$offset.",".$limit;
$sql = "SELECT ".$select." FROM ".DBPREFIX."_blogs
WHERE
display_status = '1'
".$wherestr." ORDER BY ".$order." blog_id DESC ".$limit;
// echo $sql;die;
$result = $this->db->query($sql);
if($result && $result->num_rows()>0)
{
return $result->result_array();
}
}
}
?>