source: trunk/Packages/Common/Paging.php

Last change on this file was 9, checked in by chronos, 12 months ago
  • Fixed: Modules initialization.
File size: 2.8 KB
Line 
1<?php
2
3class Paging
4{
5 public int $TotalCount;
6 public int $ItemPerPage;
7 public int $Around;
8 public string $SQLLimit;
9 public int $Page;
10 private System $System;
11
12 function __construct(System $System)
13 {
14 $this->System = $System;
15 $this->ItemPerPage = Core::Cast($this->System)->Config['Web']['ItemsPerPage'];
16 $this->Around = Core::Cast($this->System)->Config['Web']['VisiblePagingItems'];
17 }
18
19 function Show(): string
20 {
21 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
22
23 $Result = '';
24 if (array_key_exists('all', $QueryItems))
25 {
26 $PageCount = 1;
27 $ItemPerPage = $this->TotalCount;
28 } else
29 {
30 $ItemPerPage = $this->ItemPerPage;
31 $Around = round($this->Around / 2);
32 $PageCount = floor($this->TotalCount / $ItemPerPage) + 1;
33 }
34
35 if (!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
36 if (array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
37 if ($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
38 if ($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
39 $CurrentPage = $_SESSION['Page'];
40
41 $Result .= 'Počet položek: <strong>'.$this->TotalCount.'</strong> &nbsp; Stránky: ';
42
43 $Result = '';
44 if ($PageCount > 1)
45 {
46 if ($CurrentPage > 0)
47 {
48 $QueryItems['page'] = 0;
49 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;&lt;</a> ';
50 $QueryItems['page'] = ($CurrentPage - 1);
51 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&lt;</a> ';
52 }
53 $PagesMax = $PageCount - 1;
54 $PagesMin = 0;
55 if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
56 if ($PagesMin < ($CurrentPage - $Around))
57 {
58 $Result.= ' ... ';
59 $PagesMin = $CurrentPage - $Around;
60 }
61 for ($i = $PagesMin; $i <= $PagesMax; $i++)
62 {
63 if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
64 else {
65 $QueryItems['page'] = $i;
66 $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
67 }
68 }
69 if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
70 if ($CurrentPage < ($PageCount - 1))
71 {
72 $QueryItems['page'] = ($CurrentPage + 1);
73 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;</a> ';
74 $QueryItems['page'] = ($PageCount - 1);
75 $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">&gt;&gt;</a>';
76 }
77 }
78 $QueryItems['all'] = '1';
79 if ($PageCount > 1) $Result.= ' <a href="?'.SetQueryStringArray($QueryItems).'">Vše</a>';
80
81 $Result = '<div style="text-align: center">'.$Result.'</div>';
82 $this->SQLLimit = ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage;
83 $this->Page = $CurrentPage;
84 return $Result;
85 }
86}
Note: See TracBrowser for help on using the repository browser.