Skip to content

Commit

Permalink
Updated Draw\Helper\Pagination, added drawEmpty() support
Browse files Browse the repository at this point in the history
  • Loading branch information
bacinsky committed Mar 30, 2017
1 parent 0d71f28 commit 871926e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/WebinoDraw/Draw/Helper/Pagination.php
Expand Up @@ -36,12 +36,9 @@ class Pagination extends Element
],
'instructions' => [
'snippet' => [
'locator' => 'xpath=.',
'locator' => '.',
'html' => '{$snippet}',

'render' => [
'snippet' => 'webino-draw/snippet/pagination',
],
'render' => ['snippet' => 'webino-draw/snippet/pagination'],
],
// TODO do not use ?1 on the first page by default
'pages' => [
Expand All @@ -50,10 +47,8 @@ class Pagination extends Element
'base' => 'pagesInRange',
'instructions' => [
'active' => [
'locator' => 'xpath=.',
'attribs' => [
'class' => '{$active}',
],
'locator' => '.',
'attribs' => ['class' => '{$active}'],
],
'value' => [
'locator' => 'a',
Expand All @@ -79,7 +74,7 @@ class Pagination extends Element
'instructions' => [
'remove' => [
'locator' => '.',
'remove' => 'xpath=.',
'remove' => '.',
],
],
],
Expand All @@ -106,7 +101,7 @@ class Pagination extends Element
'instructions' => [
'remove' => [
'locator' => '.',
'remove' => 'xpath=.',
'remove' => '.',
],
],
],
Expand All @@ -121,6 +116,10 @@ class Pagination extends Element
],
],
],
'empty' => [
'locator' => '.',
'onEmpty' => ['remove' => '.'],
],
],
];

Expand Down Expand Up @@ -165,17 +164,15 @@ public function drawNodes(NodeList $nodes, array $spec)
$paginatorName = $localSpec['paginator'];

if (!$this->services->has($paginatorName)) {
$nodes->remove();
return $this;
return $this->drawEmpty($nodes, $localSpec);
}

/* @var $paginator \Zend\Paginator\Paginator */
$paginator = $this->services->get($paginatorName);
$pages = $paginator->getPages();

if (1 >= $pages->pageCount) {
$nodes->remove();
return $this;
return $this->drawEmpty($nodes, $localSpec);
}

$curPageNo = $paginator->getCurrentPageNumber();
Expand Down Expand Up @@ -204,4 +201,15 @@ public function drawNodes(NodeList $nodes, array $spec)

return parent::drawNodes($nodes, $localSpec);
}

/**
* @param NodeList $nodes
* @param array $spec
* @return $this
*/
private function drawEmpty(NodeList $nodes, array $spec)
{
unset($spec['instructions']['snippet']);
return parent::drawNodes($nodes, $spec);
}
}

0 comments on commit 871926e

Please sign in to comment.