From 54e635f5998d4dd8a7094e812762637e8003ecc0 Mon Sep 17 00:00:00 2001 From: Anton Titov Date: Tue, 16 Feb 2016 21:43:34 +0300 Subject: [PATCH 1/3] Update composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2359b464..c0d6bbe7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "symfony/translation": "^2.7" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.0", + "mockery/mockery": "^0.9.4" }, "autoload": { "files": [ From 59b6393fc2deb02c0594871a99a916c083e71de2 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 13 Mar 2016 16:25:10 +0300 Subject: [PATCH 2/3] pre-merge --- tests/Files/fixtures/.empty | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/Files/fixtures/.empty diff --git a/tests/Files/fixtures/.empty b/tests/Files/fixtures/.empty new file mode 100644 index 00000000..e69de29b From 68b192973047019b3b4f627ddbbac510a293a696 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 13 Mar 2016 23:35:50 +0300 Subject: [PATCH 3/3] - fixes in ORM loader cloning - simple paginator --- source/Spiral/ORM/Entities/Loader.php | 2 + .../Spiral/Pagination/CountingPaginator.php | 180 ++++++++++++++++++ .../Spiral/Pagination/PaginatorInterface.php | 19 +- 3 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 source/Spiral/Pagination/CountingPaginator.php diff --git a/source/Spiral/ORM/Entities/Loader.php b/source/Spiral/ORM/Entities/Loader.php index fa7fcea7..f2e4e331 100644 --- a/source/Spiral/ORM/Entities/Loader.php +++ b/source/Spiral/ORM/Entities/Loader.php @@ -711,10 +711,12 @@ public function __clone() { foreach ($this->loaders as $name => $loader) { $this->loaders[$name] = clone $loader; + $this->loaders[$name]->parent = $this; } foreach ($this->joiners as $name => $loader) { $this->joiners[$name] = clone $loader; + $this->joiners[$name]->parent = $this; } } diff --git a/source/Spiral/Pagination/CountingPaginator.php b/source/Spiral/Pagination/CountingPaginator.php new file mode 100644 index 00000000..4507bc4b --- /dev/null +++ b/source/Spiral/Pagination/CountingPaginator.php @@ -0,0 +1,180 @@ +setLimit($limit); + } + + /** + * {@inheritdoc} + */ + public function setPage($number) + { + $this->pageNumber = abs(intval($number)); + + //Real page number + return $this->getPage(); + } + + /** + * {@inheritdoc} + */ + public function getPage() + { + if ($this->pageNumber < 1) { + return 1; + } + + if ($this->pageNumber > $this->countPages) { + return $this->countPages; + } + + return $this->pageNumber; + } + + /** + * {@inheritdoc} + */ + public function setLimit($limit) + { + $this->limit = $limit; + } + + /** + * {@inheritdoc} + */ + public function getLimit() + { + return $this->limit; + } + + /** + * Get pagination offset. + * + * @return int + */ + public function getOffset() + { + return ($this->getPage() - 1) * $this->limit; + } + + /** + * {@inheritdoc} + */ + public function paginate(PaginableInterface $paginable) + { + $this->setCount($paginable->count()); + + $paginable->offset($this->getOffset()); + $paginable->limit($this->getLimit()); + + return $paginable; + } + + /** + * {@inheritdoc} + */ + public function setCount($count) + { + $this->count = abs(intval($count)); + if ($this->count > 0) { + $this->countPages = ceil($this->count / $this->limit); + } else { + $this->countPages = 1; + } + + return $this; + } + + /** + * @return int + */ + public function count() + { + return $this->count; + } + + /** + * {@inheritdoc} + */ + public function countPages() + { + return $this->countPages; + } + + /** + * {@inheritdoc} + */ + public function countDisplayed() + { + if ($this->getPage() == $this->countPages) { + return $this->count - $this->getOffset(); + } + + return $this->limit; + } + + /** + * {@inheritdoc} + */ + public function isRequired() + { + return ($this->countPages > 1); + } + + /** + * {@inheritdoc} + */ + public function nextPage() + { + if ($this->getPage() != $this->countPages) { + return $this->getPage() + 1; + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function previousPage() + { + if ($this->getPage() > 1) { + return $this->getPage() - 1; + } + + return false; + } +} \ No newline at end of file diff --git a/source/Spiral/Pagination/PaginatorInterface.php b/source/Spiral/Pagination/PaginatorInterface.php index 5d816f6c..057d916d 100644 --- a/source/Spiral/Pagination/PaginatorInterface.php +++ b/source/Spiral/Pagination/PaginatorInterface.php @@ -33,13 +33,28 @@ public function setPage($number); */ public function getPage(); + /** + * Set pagination limit. + * + * @param int $limit + * @return $this + */ + public function setLimit($limit); + + /** + * Get pagination limit (items per page). + * + * @return int + */ + public function getLimit(); + /** * Set initial paginator uri * * @internal to be moved to UriPaginator * @param UriInterface $uri */ - public function setUri(UriInterface $uri); + //public function setUri(UriInterface $uri); /** * Create page URL using specific page number. No domain or schema information included by @@ -49,7 +64,7 @@ public function setUri(UriInterface $uri); * @param int $pageNumber * @return UriInterface */ - public function uri($pageNumber); + //public function uri($pageNumber); /** * Apply paginator to paginable object.