<commit_before><?php
namespace Concrete\Core\Page\Stack;

use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Page\Stack\Folder\Folder;
use Loader;
use Concrete\Core\Page\PageList;

class StackList extends PageList
{
    public function __construct()
    {
        parent::__construct();
        $this->query->leftJoin('p', 'Stacks', 's', 's.cID = p.cID');
        $this->ignorePermissions();
        $this->filterByPath(STACKS_PAGE_PATH);
        $this->includeSystemPages();
        $this->sortByName();
    }

    public function filterByFolder(Folder $folder)
    {
        $this->filterByParentID($folder->getPage()->getCollectionID());
    }

    public function filterByGlobalAreas()
    {
        $this->filter('stType', Stack::ST_TYPE_GLOBAL_AREA);
    }

    public function filterByUserAdded()
    {
        $this->filter('stType', Stack::ST_TYPE_USER_ADDED);
    }

    public function filterByStackCategory(StackCategory $category)
    {
        $this->filterByParentID($category->getPage()->getCollectionID());
    }

    public function filterByPageLanguage(\Concrete\Core\Page\Page $page)
    {
        $ms = Section::getBySectionOfSite($page);
        if (!is_object($ms)) {
            $ms = static::getPreferredSection();<commit_msg>Allow keeping stacks folders first<commit_after><?php
namespace Concrete\Core\Page\Stack;

use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Page\Stack\Folder\Folder;
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;
        $this->query->leftJoin('p', 'Stacks', 's', 's.cID = p.cID');
        $this->ignorePermissions();
        $this->filterByPath(STACKS_PAGE_PATH);
        $this->includeSystemPages();
        $this->sortByName();
    }

    public function setupAutomaticSorting(StickyRequest $request = null)
    {
        parent::setupAutomaticSorting($request);
        if ($this->foldersFirst) {
            $previousOrderBy = $this->query->getQueryPart('orderBy');
            $this->query->orderBy('pt.ptHandle', 'desc');
            $this->query->add('orderBy', $previousOrderBy, true);
        }
    }

    /**
     * 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 filterByUserAdded()
    {
        $this->filter('stType', Stack::ST_TYPE_USER_ADDED);
    }

    public function filterByStackCategory(StackCategory $category)
    {
        $this->filterByParentID($category->getPage()->getCollectionID());
    }

    public function filterByPageLanguage(\Concrete\Core\Page\Page $page)
    {
        $ms = Section::getBySectionOfSite($page);
        if (!is_object($ms)) {
            $ms = static::getPreferredSection();
{'fraction_non_alphanumeric': 0.13925535033714453, 'fraction_numerical': 0.0, 'mean_word_length': 2.9953161592505855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3388344', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1023, 'n_words': 168}