Skip to content

Commit d7eaff4

Browse files
committed
Add where_update and where_delete
1 parent af410dd commit d7eaff4

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

hungng/HungNG_Custom_Based_model.php

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ public function page_limit($size = 500, $page = 0)
280280
*
281281
* @deprecated use page_limit method
282282
* @return \CI_DB_query_builder
283-
* @author : 713uk13m <dev@nguyenanhung.com>
284-
* @copyright: 713uk13m <dev@nguyenanhung.com>
285-
* @time : 08/16/2021 30:54
283+
* @author : 713uk13m <dev@nguyenanhung.com>
284+
* @copyright : 713uk13m <dev@nguyenanhung.com>
285+
* @time : 08/16/2021 30:54
286286
*/
287287
public function _page_limit($size = 500, $page = 0)
288288
{
@@ -1071,9 +1071,7 @@ public function get_data_simple_result($select = '*', $wheres = array(), $size =
10711071
}
10721072
}
10731073
}
1074-
// Limit Result
1075-
$this->_page_limit($size, $page);
1076-
// Order Result
1074+
$this->page_limit($size, $page);
10771075
foreach ($orderBy as $key => $val) {
10781076
$this->db->order_by($this->tableName . '.' . $key, $val);
10791077
}
@@ -1158,7 +1156,6 @@ public function get_value($value_input = '', $field_input = null, $field_output
11581156
$this->db->where($field_input, $value_input);
11591157
}
11601158
$query = $this->db->get();
1161-
// Query
11621159
if (null !== $field_output) {
11631160
if (null === $query->row()) {
11641161
return null;
@@ -1217,12 +1214,43 @@ public function insert_batch($data = array())
12171214
*/
12181215
public function update($id = '', $data = array())
12191216
{
1217+
if (empty($id)) {
1218+
log_message('error', 'Update method give Input Primary Key is Empty');
1219+
1220+
return 0;
1221+
}
12201222
$this->db->where($this->primary_key, $id);
12211223
$this->db->update($this->tableName, $data);
12221224

12231225
return $this->db->affected_rows();
12241226
}
12251227

1228+
/**
1229+
* Function where_update
1230+
*
1231+
* @param $wheres
1232+
* @param $data
1233+
* @param $table
1234+
*
1235+
* @return int
1236+
* @author : 713uk13m <dev@nguyenanhung.com>
1237+
* @copyright: 713uk13m <dev@nguyenanhung.com>
1238+
* @time : 22/03/2023 32:40
1239+
*/
1240+
public function where_update($wheres, $data, $table = '')
1241+
{
1242+
if (empty($wheres)) {
1243+
log_message('error', 'Update method give Input Wheres is Empty');
1244+
1245+
return 0;
1246+
}
1247+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1248+
$this->prepare_wheres_statement($wheres);
1249+
$this->db->update($tableName, $data);
1250+
1251+
return $this->db->affected_rows();
1252+
}
1253+
12261254
/**
12271255
* Function delete
12281256
*
@@ -1236,6 +1264,8 @@ public function update($id = '', $data = array())
12361264
public function delete($id = '')
12371265
{
12381266
if (empty($id)) {
1267+
log_message('error', 'Delete method give Input Primary Key is Empty');
1268+
12391269
return 0;
12401270
}
12411271
$this->db->where($this->primary_key, $id);
@@ -1244,6 +1274,32 @@ public function delete($id = '')
12441274
return $this->db->affected_rows();
12451275
}
12461276

1277+
/**
1278+
* Function where_delete
1279+
*
1280+
* @param $wheres
1281+
* @param $data
1282+
* @param $table
1283+
*
1284+
* @return int
1285+
* @author : 713uk13m <dev@nguyenanhung.com>
1286+
* @copyright: 713uk13m <dev@nguyenanhung.com>
1287+
* @time : 22/03/2023 33:27
1288+
*/
1289+
public function where_delete($wheres, $data, $table = '')
1290+
{
1291+
if (empty($wheres)) {
1292+
log_message('error', 'Delete method give Input Wheres is Empty');
1293+
1294+
return 0;
1295+
}
1296+
$tableName = !empty($table) ? trim($table) : $this->tableName;
1297+
$this->prepare_wheres_statement($wheres);
1298+
$this->db->delete($tableName, $data);
1299+
1300+
return $this->db->affected_rows();
1301+
}
1302+
12471303
/**
12481304
* Function request_builder
12491305
*

0 commit comments

Comments
 (0)