@@ -223,6 +223,33 @@ public function close()
223223
224224 // ---------------------------------------------------------------------------------------------------------------------------------------- //
225225
226+ /**
227+ * Function get_off_set
228+ *
229+ * @param $size
230+ * @param $page
231+ *
232+ * @return int
233+ * @author : 713uk13m <dev@nguyenanhung.com>
234+ * @copyright: 713uk13m <dev@nguyenanhung.com>
235+ * @time : 22/03/2023 13:24
236+ */
237+ public function get_off_set ($ size = 500 , $ page = 0 )
238+ {
239+ $ size = (int ) $ size ;
240+ $ page = (int ) $ page ;
241+ if ($ page !== 0 ) {
242+ if ($ page <= 0 || empty ($ page )) {
243+ $ page = 1 ;
244+ }
245+ $ start = ($ page - 1 ) * $ size ;
246+ } else {
247+ $ start = $ page ;
248+ }
249+
250+ return (int ) $ start ;
251+ }
252+
226253 /**
227254 * Function page_limit
228255 *
@@ -237,14 +264,7 @@ public function close()
237264 public function page_limit ($ size = 500 , $ page = 0 )
238265 {
239266 if ($ size !== 'no_limit ' ) {
240- if ($ page !== 0 ) {
241- if ($ page <= 0 || empty ($ page )) {
242- $ page = 1 ;
243- }
244- $ start = ($ page - 1 ) * $ size ;
245- } else {
246- $ start = $ page ;
247- }
267+ $ start = $ this ->get_off_set ($ size , $ page );
248268
249269 return $ this ->db ->limit ($ size , $ start );
250270 }
@@ -253,15 +273,16 @@ public function page_limit($size = 500, $page = 0)
253273 }
254274
255275 /**
256- * Function _page_limit
276+ * Function _page_limit alias of page_limit
257277 *
258278 * @param int $size
259279 * @param int $page
260280 *
281+ * @deprecated use page_limit method
261282 * @return \CI_DB_query_builder
262- * @author : 713uk13m <dev@nguyenanhung.com>
263- * @copyright: 713uk13m <dev@nguyenanhung.com>
264- * @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
265286 */
266287 public function _page_limit ($ size = 500 , $ page = 0 )
267288 {
@@ -1050,9 +1071,7 @@ public function get_data_simple_result($select = '*', $wheres = array(), $size =
10501071 }
10511072 }
10521073 }
1053- // Limit Result
1054- $ this ->_page_limit ($ size , $ page );
1055- // Order Result
1074+ $ this ->page_limit ($ size , $ page );
10561075 foreach ($ orderBy as $ key => $ val ) {
10571076 $ this ->db ->order_by ($ this ->tableName . '. ' . $ key , $ val );
10581077 }
@@ -1137,7 +1156,6 @@ public function get_value($value_input = '', $field_input = null, $field_output
11371156 $ this ->db ->where ($ field_input , $ value_input );
11381157 }
11391158 $ query = $ this ->db ->get ();
1140- // Query
11411159 if (null !== $ field_output ) {
11421160 if (null === $ query ->row ()) {
11431161 return null ;
@@ -1196,12 +1214,43 @@ public function insert_batch($data = array())
11961214 */
11971215 public function update ($ id = '' , $ data = array ())
11981216 {
1217+ if (empty ($ id )) {
1218+ log_message ('error ' , 'Update method give Input Primary Key is Empty ' );
1219+
1220+ return 0 ;
1221+ }
11991222 $ this ->db ->where ($ this ->primary_key , $ id );
12001223 $ this ->db ->update ($ this ->tableName , $ data );
12011224
12021225 return $ this ->db ->affected_rows ();
12031226 }
12041227
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+
12051254 /**
12061255 * Function delete
12071256 *
@@ -1215,6 +1264,8 @@ public function update($id = '', $data = array())
12151264 public function delete ($ id = '' )
12161265 {
12171266 if (empty ($ id )) {
1267+ log_message ('error ' , 'Delete method give Input Primary Key is Empty ' );
1268+
12181269 return 0 ;
12191270 }
12201271 $ this ->db ->where ($ this ->primary_key , $ id );
@@ -1223,6 +1274,32 @@ public function delete($id = '')
12231274 return $ this ->db ->affected_rows ();
12241275 }
12251276
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+
12261303 /**
12271304 * Function request_builder
12281305 *
0 commit comments