/
StackList.php
101 lines (86 loc) · 2.65 KB
/
StackList.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
<?php
namespace Concrete\Core\Page\Stack;
use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Page\Stack\Folder\Folder;
use Concrete\Core\Site\Tree\TreeInterface;
use Loader;
use Concrete\Core\Page\PageList;
use Concrete\Core\Search\StickyRequest;
class StackList extends PageList
{
protected $foldersFirst;
public function __construct()
{
parent::__construct();
$this->foldersFirst = false;
/* retreive most recent version to include stacks that have no approved versions */
$this->pageVersionToRetrieve = self::PAGE_VERSION_RECENT;
$this->query->leftJoin('p', 'Stacks', 's', 's.cID = p.cID');
$this->ignorePermissions();
$this->filterByPath(STACKS_PAGE_PATH);
$this->filter(false, '(s.stMultilingualSection is null or s.stMultilingualSection = 0)');
$this->includeSystemPages();
$this->sortByName();
}
public function performAutomaticSorting(StickyRequest $request = null)
{
parent::performAutomaticSorting($request);
if ($this->foldersFirst) {
$previousOrderBy = $this->query->getQueryPart('orderBy');
$this->query->orderBy('pt.ptHandle', 'desc');
$this->query->add('orderBy', $previousOrderBy, true);
}
}
public function filterByLanguageSection(Section $ms)
{
$this->filter('stMultilingualSection', $ms->getCollectionID());
}
/**
* Should we list stack folders first?
*
* @param bool $value
*/
public function setFoldersFirst($value)
{
$this->foldersFirst = (bool) $value;
}
/**
* Should we list stack folders first?
*
* @return bool
*/
public function getFoldersFirst()
{
return $this->foldersFirst;
}
public function filterByFolder(Folder $folder)
{
$this->filterByParentID($folder->getPage()->getCollectionID());
}
public function filterByGlobalAreas()
{
$this->filter('stType', Stack::ST_TYPE_GLOBAL_AREA);
}
public function excludeGlobalAreas()
{
$this->filter(false, 'stType != '.Stack::ST_TYPE_GLOBAL_AREA.' or stType is null');
}
public function filterByUserAdded()
{
$this->filter('stType', Stack::ST_TYPE_USER_ADDED);
}
public function filterByStackCategory(StackCategory $category)
{
$this->filterByParentID($category->getPage()->getCollectionID());
}
/**
* @param $queryRow
*
* @return \Stack
*/
public function getResult($queryRow)
{
$stack = Stack::getByID($queryRow['cID'], 'ACTIVE');
return $stack ?: parent::getResult($queryRow);
}
}