protected function getInactiveCategories(array $customCategories = [])
    {
        // Find only the categories that still can display some results combined with active categories
        if ($this->activeCategories !== null) {
            $columns = [];
            $values = [];

            // Collect the news that match all active categories
            /** @var NewsCategoryModel $activeCategory */
            foreach ($this->activeCategories as $activeCategory) {
                $criteria = new NewsCriteria(System::getContainer()->get('contao.framework'));

                try {
                    $criteria->setBasicCriteria($this->news_archives);
                    $criteria->setCategory($activeCategory->id, false, (bool) $this->news_includeSubcategories);
                } catch (NoNewsException $e) {
                    continue;
                }

                $columns = array_merge($columns, $criteria->getColumns());
                $values = array_merge($values, $criteria->getValues());
            }

            // Should not happen but you never know
            if (count($columns) === 0) {
                return null;
            }

            $newsIds = Database::getInstance()
                ->prepare('SELECT id FROM tl_news WHERE ' . implode(' AND ', $columns))
                ->execute($values)
                ->fetchEach('id')
            ;

            if (count($newsIds) === 0) {
                return null;
            }

            $categoryIds = Model::getRelatedValues('tl_news', 'categories', $newsIds);
            $categoryIds = \array_map('intval', $categoryIds);
            $categoryIds = \array_unique(\array_filter($categoryIds));

            // Include the parent categories
            if ($this->news_includeSubcategories) {
                foreach ($categoryIds as $categoryId) {
                    $categoryIds = array_merge($categoryIds, Database::getInstance()->getParentRecords($categoryId, 'tl_news_category'));
                }
            }

            // Remove the active categories, so they are not considered again
            $categoryIds = array_diff($categoryIds, $this->activeCategories->fetchEach('id'));

            // Filter by custom categories
            if (count($customCategories) > 0) {
                $categoryIds = array_intersect($categoryIds, $customCategories);
            }

            if (count($categoryIds) === 0) {
                return null;
            }

            $customCategories = $categoryIds;
        }

        return NewsCategoryModel::findPublishedByArchives($this->news_archives, $customCategories);
    }
protected function getInactiveCategories(array $customCategories = [])
    {
        // Find only the categories that still can display some results combined with active categories
        if ($this->activeCategories !== null) {
            $columns = [];
            $values = [];

            // Collect the news that match all active categories
            /** @var NewsCategoryModel $activeCategory */
            foreach ($this->activeCategories as $activeCategory) {
                $criteria = new NewsCriteria(System::getContainer()->get('contao.framework'));

                try {
                    $criteria->setBasicCriteria($this->news_archives);
                    $criteria->setCategory($activeCategory->id, false, (bool) $this->news_includeSubcategories);
                } catch (NoNewsException $e) {
                    continue;
                }

                $columns = array_merge($columns, $criteria->getColumns());
                $values = array_merge($values, $criteria->getValues());
            }

            // Should not happen but you never know
            if (count($columns) === 0) {
                return null;
            }

            $newsIds = Database::getInstance()
                ->prepare('SELECT id FROM tl_news WHERE ' . implode(' AND ', $columns))
                ->execute($values)
                ->fetchEach('id')
            ;

            if (count($newsIds) === 0) {
                return null;
            }

            $categoryIds = Model::getRelatedValues('tl_news', 'categories', $newsIds);
            $categoryIds = \array_map('intval', $categoryIds);
            $categoryIds = \array_unique(\array_filter($categoryIds));

            // Include the parent categories
            if ($this->news_includeSubcategories) {
                foreach ($categoryIds as $categoryId) {
                    $categoryIds = array_merge($categoryIds, Database::getInstance()->getParentRecords($categoryId, 'tl_news_category'));
                }
            }

            // Remove the active categories, so they are not considered again
            $categoryIds = array_diff($categoryIds, $this->activeCategories->fetchEach('id'));

            // Filter by custom categories
            if (count($customCategories) > 0) {
                $categoryIds = array_intersect($categoryIds, $customCategories);
            }

            if (count($categoryIds) === 0) {
                return null;
            }

            $customCategories = $categoryIds;
        }

        return NewsCategoryModel::findPublishedByArchives($this->news_archives, $customCategories);
    }
protected function getInactiveCategories ( array $ customCategories = [ ] ) { // Find only the categories that still can display some results combined with active categories if ( $ this -> activeCategories !== null ) { $ columns = [ ] ; $ values = [ ] ; // Collect the news that match all active categories /** @var NewsCategoryModel $activeCategory */ foreach ( $ this -> activeCategories as $ activeCategory ) { $ criteria = new NewsCriteria ( System :: getContainer ( ) -> get ( 'contao.framework' ) ) ; try { $ criteria -> setBasicCriteria ( $ this -> news_archives ) ; $ criteria -> setCategory ( $ activeCategory -> id , false , ( bool ) $ this -> news_includeSubcategories ) ; } catch ( NoNewsException $ e ) { continue ; } $ columns = array_merge ( $ columns , $ criteria -> getColumns ( ) ) ; $ values = array_merge ( $ values , $ criteria -> getValues ( ) ) ; } // Should not happen but you never know if ( count ( $ columns ) === 0 ) { return null ; } $ newsIds = Database :: getInstance ( ) -> prepare ( 'SELECT id FROM tl_news WHERE ' . implode ( ' AND ' , $ columns ) ) -> execute ( $ values ) -> fetchEach ( 'id' ) ; if ( count ( $ newsIds ) === 0 ) { return null ; } $ categoryIds = Model :: getRelatedValues ( 'tl_news' , 'categories' , $ newsIds ) ; $ categoryIds = \ array_map ( 'intval' , $ categoryIds ) ; $ categoryIds = \ array_unique ( \ array_filter ( $ categoryIds ) ) ; // Include the parent categories if ( $ this -> news_includeSubcategories ) { foreach ( $ categoryIds as $ categoryId ) { $ categoryIds = array_merge ( $ categoryIds , Database :: getInstance ( ) -> getParentRecords ( $ categoryId , 'tl_news_category' ) ) ; } } // Remove the active categories, so they are not considered again $ categoryIds = array_diff ( $ categoryIds , $ this -> activeCategories -> fetchEach ( 'id' ) ) ; // Filter by custom categories if ( count ( $ customCategories ) > 0 ) { $ categoryIds = array_intersect ( $ categoryIds , $ customCategories ) ; } if ( count ( $ categoryIds ) === 0 ) { return null ; } $ customCategories = $ categoryIds ; } return NewsCategoryModel :: findPublishedByArchives ( $ this -> news_archives , $ customCategories ) ; }
Get the inactive categories

@param array $customCategories

@return Collection|null
Get the inactive categories