generated from jric11/baseProject
Chat's updates for security, db and workflow
Security and workflow regressions / regression (push) Has been cancelled
Security and workflow regressions / regression (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
final class Pagination {
|
||||
public static function calculate(int $count,int $size,int $current,string $action=''): array {
|
||||
$count=max(0,$count);$size=max(1,min(100,$size));$last=max(1,(int)ceil($count/$size));
|
||||
$page=match($action){'first'=>1,'previous'=>$current-1,'next'=>$current+1,'last'=>$last,default=>$current};
|
||||
$page=max(1,min($last,$page));$offset=($page-1)*$size;
|
||||
return ['size'=>$size,'page'=>$page,'offset'=>$offset,'start'=>$count?$offset+1:0,'end'=>min($count,$offset+$size)];
|
||||
}
|
||||
public static function session(string $scope,int $count,int $size,string $action=''): array {
|
||||
if(!is_array($_SESSION[Base::PAGINATION_PAGE]??null))$_SESSION[Base::PAGINATION_PAGE]=[];
|
||||
$result=self::calculate($count,$size,(int)($_SESSION[Base::PAGINATION_PAGE][$scope]??1),$action);
|
||||
$_SESSION[Base::PAGINATION_PAGE][$scope]=$result['page'];return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user