Skip to content

Commit

Permalink
Use new methods of StackList
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Nov 13, 2024
1 parent 8dee7dd commit 366148d
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions concrete/src/Page/Stack/Folder/FolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
use Concrete\Core\Application\Application;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\Type\Type;
use Concrete\Core\Page\Stack\StackList;
use Punic\Comparer;
use Concrete\Core\Page\Type\Type;

class FolderService implements Container
{
Expand Down Expand Up @@ -125,7 +124,11 @@ public function createSubfolder($name)
public function getGlobalAreas()
{
$stackList = new StackList();
$stackList->filterByGlobalAreas();
$stackList
->setIncludeFolders(false)
->setIncludeStacks(false)
->filterByParentID($this->getRootPage()->getCollectionID())
;

return $stackList->getResults();
}
Expand All @@ -150,29 +153,16 @@ public function getStacks()
public function getChildFolders(Folder $parentFolder = null)
{
$parentPage = $parentFolder ? $parentFolder->getPage() : $this->getRootPage();
$rs = $this->connection->executeQuery(
'SELECT cID FROM Pages WHERE cParentID = :cParentID AND ptID = :ptID',
[
'cParentID' => $parentPage->getCollectionID(),
'ptID' => $this->getFolderPageType()->getPageTypeID(),
]
);
$stackList = new StackList();
$stackList
->setIncludeGlobalAreas(false)
->setIncludeStacks(false)
->filterByParentID($parentPage->getCollectionID())
;
$result = [];
while (($cID = $rs->fetchOne()) !== false) {
if (($folder = $this->getByID($cID)) !== null) {
$result[] = $folder;
}
foreach ($stackList->getResults() as $page) {
$result[] = $this->makeFolder($page);
}
$comparer = new Comparer();
usort(
$result,
static function (Folder $a, Folder $b) use ($comparer) {
$pageA = $a->getPage();
$pageB = $b->getPage();

return $comparer->compare($pageA->getCollectionName(), $pageB->getCollectionName()) ?: ($pageA->getCollectionID() - $pageA->getCollectionID);
}
);

return $result;
}
Expand All @@ -187,8 +177,10 @@ static function (Folder $a, Folder $b) use ($comparer) {
public function getChildStacks(Folder $parentFolder = null)
{
$stackList = new StackList();
$stackList->excludeGlobalAreas();
$stackList->getQueryObject()->andWhere('p.ptID <> :folderPageType')->setParameter('folderPageType', $this->getFolderPageType()->getPageTypeID());
$stackList
->setIncludeFolders(false)
->setIncludeGlobalAreas(false)
;
if ($parentFolder === null) {
$stackList->filterByParentID($this->getRootPage()->getCollectionID());
} else {
Expand Down

0 comments on commit 366148d

Please sign in to comment.