Skip to content

Commit 52b95b7

Browse files
author
Marvin Kuhn
committed
initial commit
1 parent 16ca242 commit 52b95b7

File tree

7 files changed

+151
-0
lines changed

7 files changed

+151
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace Breadlesscode\Listable\Fusion;
3+
4+
use Neos\Flow\Annotations as Flow;
5+
use Neos\Fusion\FusionObjects\AbstractFusionObject;
6+
7+
class PaginationArrayImplementation extends AbstractFusionObject
8+
{
9+
/**
10+
* @return Array
11+
*/
12+
public function evaluate()
13+
{
14+
$maximumNumberOfLinks = $this->tsValue('maximumNumberOfLinks') - 2;
15+
$itemsPerPage = $this->tsValue('itemsPerPage');
16+
$totalCount = $this->tsValue('totalCount');
17+
$currentPage = $this->tsValue('currentPage');
18+
if ($totalCount > 0 !== true) {
19+
return [];
20+
}
21+
$numberOfPages = ceil($totalCount / $itemsPerPage);
22+
if ($maximumNumberOfLinks > $numberOfPages) {
23+
$maximumNumberOfLinks = $numberOfPages;
24+
}
25+
$delta = floor($maximumNumberOfLinks / 2);
26+
$displayRangeStart = $currentPage - $delta;
27+
$displayRangeEnd = $currentPage + $delta + ($maximumNumberOfLinks % 2 === 0 ? 1 : 0);
28+
if ($displayRangeStart < 1) {
29+
$displayRangeEnd -= $displayRangeStart - 1;
30+
}
31+
if ($displayRangeEnd > $numberOfPages) {
32+
$displayRangeStart -= ($displayRangeEnd - $numberOfPages);
33+
}
34+
$displayRangeStart = (integer)max($displayRangeStart, 1);
35+
$displayRangeEnd = (integer)min($displayRangeEnd, $numberOfPages);
36+
$links = \range($displayRangeStart, $displayRangeEnd);
37+
if ($displayRangeStart > 2) {
38+
array_unshift($links, "...");
39+
array_unshift($links, 1);
40+
}
41+
if ($displayRangeEnd + 1 < $numberOfPages) {
42+
$links[] = "...";
43+
$links[] = $numberOfPages;
44+
}
45+
return $links;
46+
}
47+
}

Configuration/Routes.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-
2+
name: 'Paginate for Breadlesscode.Listable'
3+
uriPattern: '{node}<pageSeparator>{currentPage}<defaultUriSuffix>'
4+
defaults:
5+
'@package': 'Neos.Neos'
6+
'@controller': 'Frontend\Node'
7+
'@format': 'html'
8+
'@action': 'show'
9+
routeParts:
10+
node:
11+
handler: Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface
12+
appendExceedingArguments: TRUE

Configuration/Settings.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Neos:
2+
Flow:
3+
mvc:
4+
routes:
5+
'Breadlesscode.Listable':
6+
position: 'before Neos.Neos'
7+
variables:
8+
pageSeparator: '~p'
9+
defaultUriSuffix: '.html'
10+
Neos:
11+
fusion:
12+
autoInclude:
13+
Breadlesscode.Listable: true
14+
userInterface:
15+
translation:
16+
autoInclude:
17+
Breadlesscode.Listable:
18+
- 'NodeTypes/*'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
prototype(Breadlesscode.Listable:List) < prototype(Neos.Fusion:Component) {
2+
paginated = ${ false }
3+
collection = ${ [] }
4+
itemsPerPage = ${ 10 }
5+
itemRenderer = 'Breadlesscode.Listable:ListItem'
6+
7+
_currentPage = ${request.arguments.currentPage || 1}
8+
9+
renderer = Neos.Fusion:Array {
10+
@context.data = Neos.Fusion:RawArray {
11+
collection = Neos.Fusion:Case {
12+
@context.limit = ${props._currentPage * props.itemsPerPage}
13+
@context.offset = ${(props._currentPage - 1) * props.itemsPerPage}
14+
elasticSearch {
15+
condition = ${Type.instance(props.collection, 'Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder')}
16+
renderer = ${props.collection}
17+
[email protected] = ${value.limit(limit).from(offset)}
18+
[email protected][email protected] = ${ props.paginated }
19+
[email protected] = ${value.execute()}
20+
}
21+
default {
22+
condition = ${true}
23+
renderer = ${Type.instance(props.collection, 'Neos\Eel\FlowQuery\FlowQuery') ? props.collection : q(props.collection)}
24+
[email protected] = ${value.slice(offset, limit)}
25+
[email protected][email protected] = ${ props.paginated }
26+
[email protected] = ${value.get()}
27+
}
28+
}
29+
totalCount = ${Type.getType(props.collection) == 'array' ? q(props.collection).count() : props.collection.count()}
30+
}
31+
list = Neos.Fusion:Collection {
32+
collection = ${ data.collection }
33+
itemName = 'item'
34+
itemRenderer = Neos.Fusion:Case {
35+
prop {
36+
condition = ${true}
37+
type = ${ props.itemRenderer }
38+
}
39+
}
40+
}
41+
pagination >
42+
}
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prototype(Breadlesscode.Listable:ListItem) < prototype(Neos.Fusion:Component) {
2+
renderer = Neos.Fusion:Tag {
3+
tagName = 'a'
4+
content = ${ q(item).property('title') }
5+
attributes {
6+
href = Neos.Neos:NodeUri {
7+
node = ${ item }
8+
}
9+
}
10+
}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: Component/*.fusion

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"description": "",
3+
"type": "neos-plugin",
4+
"name": "breadlesscode/listable",
5+
"require": {
6+
"neos/neos": "~3.3",
7+
"neos/flow": "*"
8+
},
9+
"autoload": {
10+
"psr-4": {
11+
"Breadlesscode\\Listable\\": "Classes/"
12+
}
13+
},
14+
"extra": {
15+
"neos": {
16+
"package-key": "Breadlesscode.Listable"
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)