renaming some function in paginator + fixing bug in paginator

- the '*itemPerPage' function are renamed '*itemsPerPage'
- the paginatorFactory now get the route parameters correctly
This commit is contained in:
Julien Fastré 2016-09-02 08:20:08 +02:00
parent ede767d01a
commit 1b674f9141
4 changed files with 65 additions and 53 deletions

View File

@ -76,7 +76,7 @@ class SearchController extends Controller
$pattern, $pattern,
$name, $name,
$paginatorFactory->getCurrentPageFirstItemNumber(), $paginatorFactory->getCurrentPageFirstItemNumber(),
$paginatorFactory->getCurrentItemPerPage(), $paginatorFactory->getCurrentItemsPerPage(),
array(SearchInterface::SEARCH_PREVIEW_OPTION => false) array(SearchInterface::SEARCH_PREVIEW_OPTION => false)
)]; )];
} }

View File

@ -134,12 +134,12 @@ class Paginator implements PaginatorInterface
return $page->getNumber() === $this->currentPageNumber; return $page->getNumber() === $this->currentPageNumber;
} }
public function getItemPerPage() public function getItemsPerPage()
{ {
return $this->itemPerPage; return $this->itemPerPage;
} }
public function setItemPerPage($itemPerPage) public function setItemsPerPage($itemPerPage)
{ {
$this->itemPerPage = $itemPerPage; $this->itemPerPage = $itemPerPage;
} }

View File

@ -87,7 +87,7 @@ class PaginatorFactory
return new Paginator( return new Paginator(
$totalItems, $totalItems,
$this->getCurrentItemPerPage(), $this->getCurrentItemsPerPage(),
$this->getCurrentPageNumber(), $this->getCurrentPageNumber(),
$route === null ? $this->getCurrentRoute() : $route, $route === null ? $this->getCurrentRoute() : $route,
$routeParameters === null ? $this->getCurrentRouteParameters() : $routeParameters === null ? $this->getCurrentRouteParameters() :
@ -109,7 +109,7 @@ class PaginatorFactory
->getInt(self::DEFAULT_CURRENT_PAGE_KEY, self::DEFAULT_PAGE_NUMBER); ->getInt(self::DEFAULT_CURRENT_PAGE_KEY, self::DEFAULT_PAGE_NUMBER);
} }
public function getCurrentItemPerPage() public function getCurrentItemsPerPage()
{ {
return $this->requestStack return $this->requestStack
->getCurrentRequest() ->getCurrentRequest()
@ -120,7 +120,7 @@ class PaginatorFactory
public function getCurrentPageFirstItemNumber() public function getCurrentPageFirstItemNumber()
{ {
return ($this->getCurrentPageNumber() - 1) * return ($this->getCurrentPageNumber() - 1) *
$this->getCurrentItemPerPage(); $this->getCurrentItemsPerPage();
} }
protected function getCurrentRoute() protected function getCurrentRoute()
@ -134,7 +134,13 @@ class PaginatorFactory
{ {
return array_merge( return array_merge(
$this->router->getContext()->getParameters(), $this->router->getContext()->getParameters(),
$this->requestStack->getCurrentRequest() // get the route parameters
->query->all()); $this->requestStack
->getCurrentRequest()
->attributes->get('_route_params'),
// get the query parameters
$this->requestStack
->getCurrentRequest()->query->all()
);
} }
} }

View File

@ -35,7 +35,7 @@ namespace Chill\MainBundle\Pagination;
interface PaginatorInterface extends \Countable interface PaginatorInterface extends \Countable
{ {
/** /**
* get the number of result for this pagination * get the number of results for this paginator
* *
* @return int * @return int
*/ */
@ -48,12 +48,18 @@ interface PaginatorInterface extends \Countable
*/ */
public function getCurrentPageFirstItemNumber(); public function getCurrentPageFirstItemNumber();
public function getItemPerPage(); /*
* get the number of items per page
*/
public function getItemsPerPage();
public function setItemPerPage($itemPerPage); /*
* set the number of items per page
*/
public function setItemsPerPage($itemsPerPage);
/** /**
* get the number of page for this pagination. * get the number of pages for this pagination.
* *
* @return int * @return int
*/ */