diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:44:51 +0000 |
commit | a1ec78bf0dc93d0e05e5f066f1949dc3baecea06 (patch) | |
tree | ee596ce1bc9840661386f96f9b8d1f919a106317 /vendor/gipfl/icingaweb2/src/Data | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.tar.xz icingaweb2-module-incubator-a1ec78bf0dc93d0e05e5f066f1949dc3baecea06.zip |
Adding upstream version 0.20.0.upstream/0.20.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gipfl/icingaweb2/src/Data')
-rw-r--r-- | vendor/gipfl/icingaweb2/src/Data/Paginatable.php | 64 | ||||
-rw-r--r-- | vendor/gipfl/icingaweb2/src/Data/SimpleQueryPaginationAdapter.php | 68 |
2 files changed, 132 insertions, 0 deletions
diff --git a/vendor/gipfl/icingaweb2/src/Data/Paginatable.php b/vendor/gipfl/icingaweb2/src/Data/Paginatable.php new file mode 100644 index 0000000..8cd3963 --- /dev/null +++ b/vendor/gipfl/icingaweb2/src/Data/Paginatable.php @@ -0,0 +1,64 @@ +<?php + +namespace gipfl\IcingaWeb2\Data; + +use Countable; + +interface Paginatable extends Countable +{ + /** + * Set a limit count and offset + * + * @param int $count Number of rows to return + * @param int $offset Skip that many rows + * + * @return self + */ + public function limit($count = null, $offset = null); + + /** + * Whether a limit is set + * + * @return bool + */ + public function hasLimit(); + + /** + * Get the limit if any + * + * @return int|null + */ + public function getLimit(); + + /** + * Set limit + * + * @param int $limit Number of rows to return + * + * @return int|null + */ + public function setLimit($limit); + + /** + * Whether an offset is set + * + * @return bool + */ + public function hasOffset(); + + /** + * Get the offset if any + * + * @return int|null + */ + public function getOffset(); + + /** + * Set offset + * + * @param int $offset Skip that many rows + * + * @return int|null + */ + public function setOffset($offset); +} diff --git a/vendor/gipfl/icingaweb2/src/Data/SimpleQueryPaginationAdapter.php b/vendor/gipfl/icingaweb2/src/Data/SimpleQueryPaginationAdapter.php new file mode 100644 index 0000000..d6a1b97 --- /dev/null +++ b/vendor/gipfl/icingaweb2/src/Data/SimpleQueryPaginationAdapter.php @@ -0,0 +1,68 @@ +<?php + +namespace gipfl\IcingaWeb2\Data; + +use Icinga\Application\Benchmark; +use Icinga\Data\SimpleQuery; + +class SimpleQueryPaginationAdapter implements Paginatable +{ + /** @var SimpleQuery */ + private $query; + + public function __construct(SimpleQuery $query) + { + $this->query = $query; + } + + #[\ReturnTypeWillChange] + public function count() + { + Benchmark::measure('Running count() for pagination'); + $count = $this->query->count(); + Benchmark::measure("Counted $count rows"); + + return $count; + } + + public function limit($count = null, $offset = null) + { + $this->query->limit($count, $offset); + } + + public function hasLimit() + { + return $this->getLimit() !== null; + } + + public function getLimit() + { + return $this->query->getLimit(); + } + + public function setLimit($limit) + { + $this->query->limit( + $limit, + $this->getOffset() + ); + } + + public function hasOffset() + { + return $this->getOffset() !== null; + } + + public function getOffset() + { + return $this->query->getOffset(); + } + + public function setOffset($offset) + { + $this->query->limit( + $this->getLimit(), + $offset + ); + } +} |