-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAmslib_Pager.php
49 lines (40 loc) · 1.28 KB
/
Amslib_Pager.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
<?php
class Amslib_Pager
{
static protected function setFromArray($array)
{
if(isset($array["pager_page"]) && isset($array["pager_length"])){
return array($array["pager_page"],$array["pager_length"]);
}else if(isset($array[0]) && isset($array[1])){
return array($array[0],$array[1]);
}
return array(NULL,NULL);
}
static public function set($page,$length=NULL)
{
if(is_array($page)){
list($page,$length) = self::setFromArray($page);
}
if(strlen($page) && strlen($length)){
// Don't trust them to actually send the correct page, autofix any stupid things
if(intval($page) < 0) $page = 0;
// Set the filters and calculate the offset based on that
Amslib_Keystore::set("pager_page", intval($page));
Amslib_Keystore::set("pager_length", intval($length));
Amslib_Keystore::set("pager_offset", intval($page * $length));
}
return self::get();
}
static public function get(&$count=NULL,&$offset=NULL)
{
$count = Amslib_Keystore::get("pager_length",$count);
$offset = Amslib_Keystore::get("pager_offset",$offset);
return array($count,$offset);
}
static public function count($count)
{
$length = intval(Amslib_Keystore::get("pager_length"));
$count = intval($count);
return $length ? ceil($count / $length) : $length;
}
}