-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_model.php
155 lines (117 loc) · 4.42 KB
/
api_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* PHP version 5
* Codeigniter Model
* @category models
* @package api_model.php
* @author Nizam <aam6my@qq.com> @ aam6my
* @author Norlihazmey <norlihazmey89@gmail.com> @metallurgical
* @license https://ellislab.com/codeigniter/user-guide/license.html
* @copyright 2014
*/
class Api_model extends CI_Model {
function __construct()
{
parent::__construct();
}
/**
* [insert_new_data insert data into table - any type of table]
* @param [type] $arrayData [data value received from controller(column and value already)]
* @param [type] $table [name of table to insert the data]
* @return [type] [description]
*/
function insert_new_data($arrayData,$table)
{
$this->db->insert($table,$arrayData);
return $this->db->insert_id();
}
/**
* [delete_data delete all type of table]
* @param [type] $table [name of table]
* @param [type] $where [condition to applied]
* @return [type] [description]
*/
public function delete_data($table, $where){
$this->db->where($where);
$this->db->delete($table);
}
/**
* [get_all_rows This function can use for all the tables, default function is to call all the results rows in table]
* @param [string] $table [name of table you want to fetch data]
* @param [array] $where [condition to apply]
* @return [type] [return data sets]
*/
function get_all_rows($table,$where = false, $tableNameToJoin = false, $tableRelation = false, $likes = false, $places = false)
{
$this->db->select('*');
$this->db->from($table);
if($where!=false){
$this->db->where($where);
}
if($tableNameToJoin!=false && $tableRelation!=false){
$this->db->join($tableNameToJoin, $tableRelation);
}
if($likes!=false){
$this->db->like($likes, 'after');
}
$query = $this->db->get();
return $query->result_array();
}
/**
* [get_specified_row This function can use for all the tables, default function is to call the specified results rows in table]
* @param [string] $table [name of table you want to fetch data]
* @param [array] $where [where condition]
* @param [array] $order_by [order by]
* @return [type] [return sepcified row]
*/
function get_specified_row($table,$where = false,$order_by = false, $tableNameToJoin = false, $tableRelation = false)
{
$this->db->select('*');
$this->db->from($table);
if($where!=false)
{
$this->db->where($where);
}
if($order_by!=false)
{
$this->db->order_by($order_by[0], $order_by[1]);
}
if($tableNameToJoin && $tableRelation){
$this->db->join($tableNameToJoin, $tableRelation);
}
$query = $this->db->get();
return $query->row_array();
}
/**
* [update_data update datas in any tables you want]
* @param [array] $columnToUpdate [what column you want to update = array value]
* @param [string] $tableToUpdate [what table you want to update]
* @param [array] $usingCondition [using condition or not]
* @return [type] [description]
*/
function update_data($columnToUpdate, $tableToUpdate, $usingCondition)
{
$this->db->where($usingCondition);
$this->db->update($tableToUpdate, $columnToUpdate);
}
function get_data_join($table,$where = false, $join_to = false, $join_id = false, $likes = false, $places = false)
{
$this->db->select('*');
$this->db->from($table);
if($where!=false){
$this->db->where($where);
}
if($join_to!=false && $join_id!=false){
for ($i=0; $i < count($join_to); $i++){
$this->db->join($join_to[$i], $join_to[$i].".".$join_id[$i]." = ".$table.".".$join_id[$i], ' left outer');
}
}
if($likes!=false){
$this->db->like($likes, 'after');
}
$query = $this->db->get();
return $query->result_array();
}
}
/* End of file api_model.php */
?>