|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ChildPaginatorControllerExtension extends Extension |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
/* |
|
6
|
|
|
Call this from a template to iterate through a number of items (default 10) for the |
|
7
|
|
|
currently selected page. The result is saved as a variable called $this->lastPagedResults for |
|
8
|
|
|
caching purposes when it comes to rendering the pagination |
|
9
|
|
|
|
|
10
|
|
|
<code> |
|
11
|
|
|
<% control PagedChildren(NewsItem,8) %> |
|
12
|
|
|
<li> |
|
13
|
|
|
<a href="$Link">$Title</a> |
|
14
|
|
|
<br/> |
|
15
|
|
|
<a href="$Link">$NewsItemImage.SetWidth(200)</a> |
|
16
|
|
|
<br/> |
|
17
|
|
|
<a href="$Link">$NewsItemDate.Nice</a> |
|
18
|
|
|
|
|
19
|
|
|
</li> |
|
20
|
|
|
<% end_control %> |
|
21
|
|
|
</code> |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
public function PagedChildren($klazz, $pageLength = 10, $prime = false, $relationship_key = 'ParentID') |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$parentID = $this->owner->ID; |
|
26
|
|
|
$req = Controller::curr()->getRequest(); |
|
27
|
|
|
$list = DataList::create($klazz)->where('"ParentID" = '.$parentID); |
|
28
|
|
|
$this->lastPagedResults = new PaginatedList($list, $req); |
|
|
|
|
|
|
29
|
|
|
$this->lastPagedResults->setPageLength($pageLength); |
|
30
|
|
|
$this->lastPagedResults->setLimitItems($pageLength); |
|
|
|
|
|
|
31
|
|
|
$result = $this->lastPagedResults; |
|
32
|
|
|
if ($prime == true) { |
|
|
|
|
|
|
33
|
|
|
$result = ''; // render nothing to the template, we are only updating variables |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return $result; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
View Code Duplication |
public function AllPagedChildren($pageLength = 10, $sort = 'Sort', $prime = false, $relationship_key = 'ParentID') |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
$parentID = $this->owner->ID; |
|
42
|
|
|
$req = Controller::curr()->getRequest(); |
|
43
|
|
|
$list = SiteTree::get()->where('"ParentID" = '.$parentID); |
|
44
|
|
|
$this->lastPagedResults = new PaginatedList($list, $req); |
|
45
|
|
|
$this->lastPagedResults->setPageLength($pageLength); |
|
46
|
|
|
$this->lastPagedResults->setLimitItems($pageLength); |
|
|
|
|
|
|
47
|
|
|
$result = $this->lastPagedResults; |
|
48
|
|
|
if ($prime == true) { |
|
|
|
|
|
|
49
|
|
|
$result = ''; // render nothing to the template, we are only updating variables |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $result; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function PagedDataObjectsByClassName($klazz, $pageLength = 10, $sort = 'ASC') |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
$req = Controller::curr()->getRequest(); |
|
58
|
|
|
$this->lastPagedResults = new PaginatedList(DataList::create($klazz)->sort('LastEdited '.$sort), $req); |
|
59
|
|
|
$this->lastPagedResults->setPageLength($pageLength); |
|
60
|
|
|
$this->lastPagedResults->setLimitItems($pageLength); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
return $this->lastPagedResults; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function SetPagedOffset($newoffset) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$this->PagedOffset = $newoffset; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function PagedChildrenAllButFirst() |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/* |
|
75
|
|
|
The current page number. This is only populated after the call to PagedChildren |
|
76
|
|
|
*/ |
|
77
|
|
|
public function PageNumber() |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
return $this->PageNumber; // variable, not the method, populated when loading the pages items |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/* |
|
83
|
|
|
A cached copy of the pagination results |
|
84
|
|
|
*/ |
|
85
|
|
|
public function LastPagedResults() |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return $this->lastPagedResults; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.