• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 7048127238

30 Nov 2023 02:47PM UTC coverage: 34.081%. First build
7048127238

Pull #1060

github

paveljanda
Minor CSS changes for the next verison of datagrid
Pull Request #1060: [7.x] Next

118 of 431 new or added lines in 54 files covered. (27.38%)

1125 of 3301 relevant lines covered (34.08%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Components/DatagridPaginator/DatagridPaginator.php
1
<?php declare(strict_types = 1);
2

3
/**
4
 * Nette Framework Extras
5
 *
6
 * This source file is subject to the New BSD License.
7
 *
8
 * For more information please see http://addons.nette.org
9
 *
10
 * @link http://addons.nette.org
11
 */
12

13
namespace Contributte\Datagrid\Components\DatagridPaginator;
14

15
use Contributte\Datagrid\Datagrid;
16
use Nette\Application\UI\Control;
17
use Nette\Bridges\ApplicationLatte\Template;
18
use Nette\Localization\Translator;
19
use Nette\Utils\Paginator;
20
use UnexpectedValueException;
21

22
class DatagridPaginator extends Control
23
{
24

25
        private ?Paginator $paginator = null;
26

27
        private ?string $templateFile = null;
28

NEW
29
        public function __construct(private Translator $translator, private string $iconPrefix = 'fa fa-', private string $btnSecondaryClass = 'btn-default btn-secondary')
×
30
        {
31
        }
32

33
        public function setTemplateFile(string $templateFile): void
34
        {
35
                $this->templateFile = $templateFile;
×
36
        }
37

38
        public function getTemplateFile(): string
39
        {
40
                return $this->templateFile ?? __DIR__ . '/templates/data_grid_paginator.latte';
×
41
        }
42

43
        public function getOriginalTemplateFile(): string
44
        {
45
                return __DIR__ . '/templates/data_grid_paginator.latte';
×
46
        }
47

48
        public function getPaginator(): Paginator
49
        {
50
                if ($this->paginator === null) {
×
51
                        $this->paginator = new Paginator();
×
52
                }
53

54
                return $this->paginator;
×
55
        }
56

57
        public function render(): void
58
        {
59
                $paginator = $this->getPaginator();
×
60
                $page = $paginator->page;
×
61

62
                if ($paginator->pageCount < 2) {
×
63
                        $steps = [$page];
×
64

65
                } else {
66
                        $arr = range(max($paginator->firstPage, $page - 2), (int) min($paginator->lastPage, $page + 2));
×
67

68
                        /**
69
                         * Something to do with steps in template...
70
                         * [Default $count = 3;]
71
                         */
72
                        $count = 1;
×
73

74
                        $perPage = $paginator->pageCount;
×
75

76
                        $quotient = ($perPage - 1) / $count;
×
77

78
                        for ($i = 0; $i <= $count; $i++) {
×
79
                                $arr[] = round($quotient * $i) + $paginator->firstPage;
×
80
                        }
81

82
                        sort($arr);
×
83
                        $steps = array_values(array_unique($arr));
×
84
                }
85

86
                if (!$this->getTemplate() instanceof Template) {
×
87
                        throw new UnexpectedValueException();
×
88
                }
89

90
                $this->getTemplate()->setTranslator($this->translator);
×
91

92
                if (!isset($this->getTemplate()->steps)) {
×
93
                        $this->getTemplate()->steps = $steps;
×
94
                }
95

96
                if (!isset($this->getTemplate()->paginator)) {
×
97
                        $this->getTemplate()->paginator = $paginator;
×
98
                }
99

100
                $this->getTemplate()->iconPrefix = $this->iconPrefix;
×
101
                $this->getTemplate()->btnSecondaryClass = $this->btnSecondaryClass;
×
102
                $this->getTemplate()->originalTemplate = $this->getOriginalTemplateFile();
×
103
                $this->getTemplate()->setFile($this->getTemplateFile());
×
104
                $this->getTemplate()->render();
×
105
        }
106

107
        /**
108
         * Loads state informations.
109
         */
110
        public function loadState(array $params): void
111
        {
112
                parent::loadState($params);
×
113

NEW
114
                if ($this->getParent() instanceof Datagrid) {
×
115
                        $this->getPaginator()->page = $this->getParent()->page;
×
116
                }
117
        }
118

119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc