Load all categories or, depending on the <displayEmpty> option, only those that have blog posts
@return mixed
3746
protected function loadCategories()
    {
        $categories = BlogCategory::with('posts_count')->getNested();
        if (!$this->property('displayEmpty')) {
            $iterator = function ($categories) use (&$iterator) {
                return $categories->reject(function ($category) use (&$iterator) {
                    if ($category->getNestedPostCount() == 0) {
                        return true;
                    }
                    if ($category->children) {
                        $category->children = $iterator($category->children);
                    }
                    return false;
                });
            };
            $categories = $iterator($categories);
        }

        /*
         * Add a "url" helper attribute for linking to each category
         */
        return $this->linkCategories($categories);
    }
588465
public function getFirstCategoryPur()
    {
        $firstOrderId = $this->model->getFirstOrderId();
        $order = $this->orderFactory->create();
        $this->orderResource->load($order, $firstOrderId);
        $categoryIds = $this->getCategoriesFromOrderItems($order->getAllItems());

        return $this->getCategoryNames($categoryIds);
    }
1260262
public function getArticleList()
    {
        if ($this->_aArticleList === null) {
            if ($category = $this->getActiveCategory()) {
                $articleList = $this->_loadArticles($category);
                if (count($articleList)) {
                    $this->_aArticleList = $articleList;
                }
            }
        }

        return $this->_aArticleList;
    }
1150026
public function getSidebarData()
    {
        if ($this->_entityName === 'Veonik\Bundle\BlogBundle\Entity\Category') {
            $join = 'JOIN posts_categories pt ON pt.category_id = t.id ';
        } else {
            $join = 'JOIN posts_tags pt ON pt.tag_id = t.id ';
        }
        
        $stmt = $this->_em->getConnection()->executeQuery(
            "SELECT t.id FROM tags t 
                  {$join}
                  JOIN posts p ON pt.post_id = p.id 
                WHERE p.active = TRUE 
                  AND t.active = TRUE
                GROUP BY t.id
                ORDER BY COUNT(p.id) DESC
                LIMIT 10"
        );
        $results = $stmt->fetchAll(\PDO::FETCH_COLUMN);
        
        return $this->createQueryBuilder('t')
            ->join('VeonikBlogBundle:AbstractPost', 'p')
            ->where('t.id IN (:ids)')
            ->setParameter('ids', $results)
            ->getQuery()
            ->useResultCache(true, 3600, 'sidebar_tags' . $this->_entityName)
            ->getResult();
    }
31623
public function categories()
    {
        $findPostType = PostType::findBySlug($this->getTable());
        if(!$findPostType) {
            throw new \Exception("Categories  relations could not be made because the post type of the post #".$this->postID." could ont be found!");
        }
        return $this->customHasManyThrough(
            'App\Models\Category', 'App\Models\CategoryRelation',
            'postID', 'categoryID', 'postID', 'categoryID', $this->getTable()."_categories"
        )
            ->where('postTypeID', $findPostType->postTypeID);
    }
1021360
public function load()
    {
        if ($this->_isCollectionLoaded == false) {


            $collection = Mage::getResourceModel('catalog/category_collection')->addNameToResult();
            /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */

            foreach ($collection as $category) {
                /** @var $category Mage_Catalog_Model_Category */
                $structure = explode('/', $category->getPath());
                $pathSize = count($structure);
                if ($pathSize > 1) {
                    $path = array();
                    for ($i = 1; $i < $pathSize; $i++) {
                        $path[] = $collection->getItemById($structure[$i])->getName();
                    }
                    $rootCategoryName = array_shift($path);
                    if (!isset($this->_categoriesWithRoots[$rootCategoryName])) {
                        $this->_categoriesWithRoots[$rootCategoryName] = array();
                    }
                    $index = $this->_implodeEscaped('/', $path);

                    $this->_categoriesWithRoots[$rootCategoryName][$index] = array(
                        'entity_id' => $category->getId(),
                        'path' => $category->getPath(),
                        'level' => $category->getLevel(),
                        'position' => $category->getPosition()
                    );

//allow importing by ids.
                    if (!isset($this->_categoriesWithRoots[$structure[1]])) {
                        $this->_categoriesWithRoots[$structure[1]] = array();
                    }
                    $this->_categoriesWithRoots[$structure[1]][$category->getId()] =
                        $this->_categoriesWithRoots[$rootCategoryName][$index];
                }
            }


            $collection = clone $this->_categoryCollection;
            $collection->removeAttributeToSelect();
            $tableName = $collection->getResource()->getEntityTable();
            $collection->getSelect()->from($tableName, ['entity_id', 'website_id', 'email']);

            $this->_byPagesIterator->iterate(
                $this->_categoryCollection,
                $this->_pageSize,
                [[$this, 'addCustomer']]
            );

            $this->_isCollectionLoaded = true;
        }
    }
1155357
public function load_includes() {

		// Get includes
		$includes = $this->includes;

		// Loop conditions
		foreach ( $includes as $condition => $files ) {

			$do_includes = false;

			// Check condition
			switch( $condition ) {

				// Admin Only
				case 'admin':

					if ( is_admin() ) {
						$do_includes = true;
					}

					break;

				// Frontend Only
				case 'frontend':

					if ( ! is_admin() ) {
						$do_includes = true;
					}

					break;

				// Admin or Frontend (always)
				default:

					$do_includes = true;

					break;

			}

			// Loop files if condition met
			if ( $do_includes ) {

				foreach ( $files as $file ) {
					require_once trailingslashit( CTC_PATH ) . $file;
				}

			}

		}

	}
691284
public function load_parent_category() {
        if (empty($this->parent_category) && !empty($this->parent)) {
            $this->parent_category = $this->get_parent_category();
        }
        return $this->parent_category;
    }
1288395
public function getActCategory()
    {
        // if active category is not set yet - trying to load it from request params
        // this may be usefull when category component was unable to load active category
        // and we still need some object to mount navigation info
        if ($this->_oClickCat === null) {
            $this->_oClickCat = false;
            $oCategory = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
            if ($oCategory->load($this->getCategoryId())) {
                $this->_oClickCat = $oCategory;
            }
        }

        return $this->_oClickCat;
    }
1195023
public function renderEmpty()
    {
        $options = $this->emptyTextOptions;
        $tag = ArrayHelper::remove($options, 'tag', 'div');
        return Html::tag($tag, ($this->emptyText === null ? Yii::t('yii', 'No results found.') : $this->emptyText), $options);
    }
773661
public function index()
    {
        //  Page data
        $this->data['page']->title = 'Blog &rsaquo; Tags';

        // --------------------------------------------------------------------------

        $data                  = array();
        $data['include_count'] = true;
        $data['where']         = array();
        $data['where'][]       = array('column' => 'blog_id', 'value' => $this->blog->id);

        $this->data['tags'] = $this->blog_tag_model->getAll(null, null, $data);

        // --------------------------------------------------------------------------

        Helper::loadView('index');
    }
1191877
public function getCategory()
    {
        $oCategory = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
        $oCategory->setLanguage($this->getLanguage());

        // variant handling
        $sOXID = $this->getId();
        if (isset($this->oxarticles__oxparentid->value) && $this->oxarticles__oxparentid->value) {
            $sOXID = $this->oxarticles__oxparentid->value;
        }

        if ($sOXID) {
            // if the oxcategory instance of this article is not cached
            if (!isset($this->_aCategoryCache[$sOXID])) {
                startPRofile('getCategory');
                $oStr = getStr();
                $sWhere = $oCategory->getSqlActiveSnippet();
                $sSelect = $this->_generateSearchStr($sOXID);
                $sSelect .= ($oStr->strstr(
                    $sSelect,
                    'where'
                ) ? ' and ' : ' where ') . $sWhere . " order by oxobject2category.oxtime limit 1";

                // category not found ?
                if (!$oCategory->assignRecord($sSelect)) {
                    $sSelect = $this->_generateSearchStr($sOXID, true);
                    $sSelect .= ($oStr->strstr($sSelect, 'where') ? ' and ' : ' where ') . $sWhere . " limit 1";

                    // looking for price category
                    if (!$oCategory->assignRecord($sSelect)) {
                        $oCategory = null;
                    }
                }
                // add the category instance to cache
                $this->_aCategoryCache[$sOXID] = $oCategory;
                stopPRofile('getCategory');
            } else {
                // if the oxcategory instance is cached
                $oCategory = $this->_aCategoryCache[$sOXID];
            }
        }

        return $oCategory;
    }
1254430
public function getCategories()
    {
        $apiCategories = [];
        $fileVersion = $this->getFileVersion();
        $categories = $fileVersion->getCategories();

        return array_map(function(CategoryEntity $category) {
            return $category->getId();
        }, $categories->toArray());
    }
1191182
protected function fetchSidebarWidgets()
    {
        $this->data['widget'] = new stdClass();

        if (appSetting('sidebar_latest_posts', 'blog-' . $this->oBlog->id)) {

            $this->data['widget']->latest_posts = $this->blog_widget_model->latestPosts($this->oBlog->id);
        }

        if (appSetting('sidebar_categories', 'blog-' . $this->oBlog->id)) {

            $this->data['widget']->categories = $this->blog_widget_model->categories($this->oBlog->id);
        }

        if (appSetting('sidebar_tags', 'blog-' . $this->oBlog->id)) {

            $this->data['widget']->tags = $this->blog_widget_model->tags($this->oBlog->id);
        }

        if (appSetting('sidebar_popular_posts', 'blog-' . $this->oBlog->id)) {

            $this->data['widget']->popular_posts = $this->blog_widget_model->popularPosts($this->oBlog->id);
        }
    }
950835
private function findCategoriesWithoutParents()
    {
        // get categories that have no parent but depth > 0
        $qb = $this->categoryRepository->createQueryBuilder('c2')
            ->select('count(c2.id)')
            ->leftJoin('c2.parent', 'c1')
            ->where('c2.depth <> 0 AND c2.parent IS NULL');

        return $qb->getQuery()->getSingleScalarResult();
    }
945762
public function index()
    {
        $categories = $this->repository->all();
        $categoryGrid = new CategoryDataGrid($this->repository->query());

        return view('avored-framework::product.category.index')
            ->with('dataGrid', $categoryGrid->dataGrid)
            ->with('categories', $categories);
    }
384167
public function getCurrentCategory()
    {
        /**
         * @var Blog $dataRecord
         */
        $dataRecord = $this->dataRecord;
        $category = $this->request->param('Category');
        if ($category) {
            $filter = URLSegmentFilter::create();
            // url encode unless it's multibyte (already pre-encoded in the database)
            // see https://github.com/silverstripe/silverstripe-cms/pull/2384
            if (!$filter->getAllowMultibyte()) {
                $category = rawurlencode($category);
            }

            return $dataRecord->Categories()
                ->filter('URLSegment', $category)
                ->first();
        }
        return null;
    }