Skip to content

Commit af410dd

Browse files
committed
Refactor Page Limit function
1 parent 1d558f8 commit af410dd

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

hungng/HungNG_Custom_Based_model.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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,11 +273,12 @@ 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
262283
* @author : 713uk13m <dev@nguyenanhung.com>
263284
* @copyright: 713uk13m <dev@nguyenanhung.com>

0 commit comments

Comments
 (0)