/
Result.php
187 lines (159 loc) · 4.49 KB
/
Result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
namespace Concrete\Core\Search\Result;
use Concrete\Core\Search\Column\Set;
use Concrete\Core\Search\ItemList\ItemList;
use Concrete\Core\Search\Pagination\PaginationFactory;
use Pagerfanta\View\TwitterBootstrap3View;
use stdClass;
class Result
{
protected $listColumns;
protected $list;
protected $baseURL;
protected $breadcrumb;
protected $query; // This is a search request, it gets rid of folders, etc...
protected $filters; // These are search filters - they display folders, don't display a "reset search" label, etc...
/** @var \Concrete\Core\Search\Pagination\Pagination */
protected $pagination;
protected $items;
protected $fields;
protected $columns;
/**
* @return mixed
*/
public function getFilters()
{
return $this->filters;
}
/**
* @param mixed $filters
*/
public function setFilters($filters)
{
$this->filters = $filters;
}
/**
* @return mixed
*/
public function getQuery()
{
return $this->query;
}
/**
* @param mixed $query
*/
public function setQuery($query)
{
$this->query = $query;
}
public function getItemListObject()
{
return $this->list;
}
/**
* @return mixed
*/
public function getBreadcrumb()
{
return $this->breadcrumb;
}
/**
* @param mixed $breadcrumb
*/
public function setBreadcrumb($breadcrumb)
{
$this->breadcrumb = $breadcrumb;
}
public function setBaseURL($url)
{
$this->baseURL = $url;
}
public function getBaseURL()
{
return $this->baseURL;
}
public function getSearchResultBulkMenus()
{
return false;
}
/**
* @return Set
*/
public function getListColumns()
{
return $this->listColumns;
}
public function __construct(Set $columns, ItemList $il, $url = null, $fields = array())
{
$this->listColumns = $columns;
$this->list = $il;
$this->baseURL = $url;
$this->fields = $fields;
$factory = new PaginationFactory(\Request::createFromGlobals());
$this->pagination = $factory->createPaginationObject($il, PaginationFactory::PERMISSIONED_PAGINATION_STYLE_PAGER);
}
public function getItems()
{
if (!isset($this->items)) {
$this->items = array();
$items = $this->pagination->getCurrentPageResults();
foreach ($items as $item) {
$node = $this->getItemDetails($item);
$this->items[] = $node;
}
}
return $this->items;
}
public function getColumns()
{
if (!isset($this->columns)) {
$this->columns = array();
foreach ($this->listColumns->getColumns() as $column) {
$node = $this->getColumnDetails($column);
$this->columns[] = $node;
}
}
return $this->columns;
}
public function getColumnDetails($column)
{
$node = new Column($this, $column);
return $node;
}
public function getItemDetails($item)
{
$node = new Item($this, $this->listColumns, $item);
return $node;
}
public function getSortURL($column, $dir = 'asc')
{
return $this->getItemListObject()->getSortURL($column, $dir, $this->getBaseURL());
}
public function getJSONObject()
{
$obj = new stdClass();
$obj->items = array();
foreach ($this->getItems() as $item) {
$obj->items[] = $item;
}
foreach ($this->getColumns() as $column) {
$obj->columns[] = $column;
}
$html = '';
if ($this->pagination->haveToPaginate()) {
$this->pagination->setBaseURL($this->getBaseURL());
$html = $this->pagination->renderView('dashboard', [
'prev_message' => tc('Pagination', '← Previous'),
'next_message' => tc('Pagination', 'Next →'),
'active_suffix' => '<span class="sr-only">' . tc('Pagination', '(current)') . '</span>']);
}
$obj->paginationTemplate = $html;
$obj->fields = $this->fields;
$obj->filters = $this->filters;
$obj->query = $this->query;
$obj->bulkMenus = $this->getSearchResultBulkMenus();
$obj->baseUrl = (string) $this->getBaseURL();
$obj->breadcrumb = $this->getBreadcrumb();
return $obj;
}
}