Returns the hierarchy of system course categories.

@return array
778634
private function get_all_category_branches() {

        $categories = data_registry::get_site_categories();

        $categoriesbranch = [];
        while (count($categories) > 0) {
            foreach ($categories as $key => $category) {

                $context = \context_coursecat::instance($category->id);
                $newnode = [
                    'text' => shorten_text(format_string($category->name, true, ['context' => $context])),
                    'categoryid' => $category->id,
                    'contextid' => $context->id,
                ];
                if ($category->coursecount > 0) {
                    $newnode['branches'] = [
                        [
                            'text' => get_string('courses'),
                            'expandcontextid' => $context->id,
                            'expandelement' => 'course',
                            'expanded' => 0,
                        ]
                    ];
                }

                $added = false;
                if ($category->parent == 0) {
                    // New categories root-level node.
                    $categoriesbranch[] = $newnode;
                    $added = true;

                } else {
                    // Add the new node under the appropriate parent.
                    if ($this->add_to_parent_category_branch($category, $newnode, $categoriesbranch)) {
                        $added = true;
                    }
                }

                if ($added) {
                    unset($categories[$key]);
                }
            }
        }

        return $categoriesbranch;
    }
476688
public static function get_level_options() {
        return array(
            \core\event\base::LEVEL_TEACHING      => get_string('teaching', 'logstore_database'),
            \core\event\base::LEVEL_PARTICIPATING => get_string('participating', 'logstore_database'),
            \core\event\base::LEVEL_OTHER         => get_string('other', 'logstore_database'),
        );
    }
836484
public function classes() {

		$classes = array(
			'toggle-checkbox',
		);

		if ( ! empty( $this->struct['on_icon'] ) ) {
			$this->icons['on'] = $this->struct['on_icon'];
		}

		if ( ! empty( $this->struct['off_icon'] ) ) {
			$this->icons['off'] = $this->struct['off_icon'];
		}

		return $classes;
	}
1117239
protected function categoriesMenu() : array
    {
        if (! $this->app->bound($repository = 'category.repository.cahe')) {
            return [];
        }

        return $this->app->make($repository)->categoriesWithProducts()->mapWithKeys(function ($item) {
            return [$item->id => $item];
        })->all();
    }
108228
public function getCategoriesTree()
    {
        $allCategories = $this->getCategories();
        $topCategories = [];

        $currentCategory = null;

        // Building tree from categories collection
        foreach ($allCategories as $idCat => $category) {

            // If level, we put category in an array with only top level categories.
            $topLevel = 2; // 1 is root category
            if ($category->getLevel() == $topLevel && !isset($topCategories[$idCat])) {
                $topCategories[$idCat] = $category;
            } else {
                // Foreach categories with sub category we add a child to the parent
                if (!isset($allCategories[$category->getParentId()])) {
                    // Ignore if no parent
                    continue;
                }
                $parent           = $allCategories[$category->getParentId()];
                $children         = $parent->getData('_children') ?: [];
                $children[$idCat] = $category;
                $category->setData('_parent', $parent);
                $parent->setData('_children', $children);
            }

            if ((int) $idCat === $this->getCurrentCategoryId()) {
                $currentCategory = $category;
            }
        }

        // Set current path
        if (null !== $currentCategory) {
            $setCategoryAsCurrent = function (Mage_Catalog_Model_Category $category, $isParent = false) use (&$setCategoryAsCurrent) {
                if ($isParent) {
                    $category->setContainsCurrentCategory(true);
                } else {
                    $category->setIsCurrentCategory(true);
                }
                if ($parentCategory = $category->getData('_parent')) {
                    $setCategoryAsCurrent($parentCategory, true);
                }
            };
            $setCategoryAsCurrent($currentCategory);
        }

        return $topCategories;
    }
825225
public function getCategories()
    {
        return (new CmsCategoryQuery)
                ->join('cms_category_relation')->on('id', 'cms_category_id')
                ->where('object', 'cms_category_relation')->equals($this->_object)
                ->where('objectId', 'cms_category_relation')->equals($this->_objectId)
                ->find();
    }
765917
public function getCategoryMenus()
    {
        if ($this->_categoryMenus === null) {
            $this->setCategoryMenus($this->categoryMenus());
        }
        return $this->_categoryMenus;
    }
1063531
public function CMSTreeClasses()
    {
        $classes = sprintf('class-%s', Convert::raw2htmlid(static::class));
        if ($this->HasBrokenFile || $this->HasBrokenLink) {
            $classes .= " BrokenLink";
        }

        if (!$this->canAddChildren()) {
            $classes .= " nochildren";
        }

        if (!$this->canEdit() && !$this->canAddChildren()) {
            if (!$this->canView()) {
                $classes .= " disabled";
            } else {
                $classes .= " edit-disabled";
            }
        }

        if (!$this->ShowInMenus) {
            $classes .= " notinmenu";
        }

        return $classes;
    }
433447
protected function getProcessedCategoryIds()
    {
        $categoryIds = [];
        $source = $this->getSource();

        $source->rewind();
        while ($source->valid()) {
            $current = $source->current();
            if (isset($this->newCategory[$current[self::COL_ROOT]][$current[self::COL_CATEGORY]])) {
                $categoryIds[] = $this->newCategory[$current[self::COL_ROOT]][$current[self::COL_CATEGORY]];
            } elseif (isset($this->categoriesWithRoots[$current[self::COL_ROOT]][$current[self::COL_CATEGORY]])) {
                $categoryIds[] = $this->categoriesWithRoots[$current[self::COL_ROOT]][$current[self::COL_CATEGORY]];
            }

            $source->next();
        }

        return $categoryIds;
    }
1285801
public function getTopLevelSections()
    {
        $this->sortSectionsByDepth();
        $topLevelSections = array();

        foreach ($this->sections as $section) {
            if ($section->getDepth() != 0) {
                break;
            }
            $topLevelSections[] = $section;
        }

        return $topLevelSections;
    }
254027
private function getCategoryDirectory()
    {
        if (!$this->category){
            return "_default";
        }

        $category = preg_replace("/\\W/","-",$this->category);
        $category = preg_replace("/-+/","-",$category);
        $category .= crc32($this->category);

        return $category;
    }
540270
public function getCategory()
    {
        $categoryModel = static::getCategoryModel();
        return ($this->type == self::TYPE_CATEGORY) ? $this->hasOne($categoryModel::className(), ['id' => $this->options->category_id]) : null;
    }
254257
protected function get_categories() {
        global $DB;
        $fields = 'c.*, ' . context_helper::get_preload_record_columns_sql('ctx');
        $coursecats = $DB->get_records_sql('SELECT ' . $fields . ' FROM {course_categories} c
                LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)
                WHERE c.parent = :parent ORDER BY c.sortorder',
            array('parent' => $this->category->id, 'contextlevel' => CONTEXT_COURSECAT));

        $hiddencats = [];

        foreach ($coursecats as $id => &$category) {
            context_helper::preload_from_record($category);
            if (!core_course_category::can_view_category($category)) {
                $hiddencats[$id] = $coursecats[$id];
                unset($coursecats[$id]);
            }
        }
        return [$coursecats, $hiddencats];
    }
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();
    }
519265
private function get_default_tree_structure() {

        $frontpage = \context_course::instance(SITEID);

        $categorybranches = $this->get_all_category_branches();

        $elements = [
            'text' => get_string('contextlevelname' . CONTEXT_SYSTEM, 'tool_dataprivacy'),
            'contextlevel' => CONTEXT_SYSTEM,
            'branches' => [
                [
                    'text' => get_string('user'),
                    'contextlevel' => CONTEXT_USER,
                ], [
                    'text' => get_string('categories'),
                    'branches' => $categorybranches,
                    'expandelement' => 'category',
                ], [
                    'text' => get_string('frontpagecourse', 'tool_dataprivacy'),
                    'contextid' => $frontpage->id,
                    'branches' => [
                        [
                            'text' => get_string('activitiesandresources', 'tool_dataprivacy'),
                            'expandcontextid' => $frontpage->id,
                            'expandelement' => 'module',
                            'expanded' => 0,
                        ], [
                            'text' => get_string('blocks'),
                            'expandcontextid' => $frontpage->id,
                            'expandelement' => 'block',
                            'expanded' => 0,
                        ],
                    ]
                ]
            ]
        ];

        // Returned as an array to follow a common array format.
        return [self::complete($elements, $this->defaultcontextlevel, $this->defaultcontextid)];
    }
86447
public static function getCategories()
    {
        $app = App::getInstance();

        $manager = BaseManager::build('FelixOnline\Core\Category', 'category');

        try {
            $values = $manager->filter('hidden = 0')
                            ->filter('deleted = 0')
                            ->filter('id > 0')
                            ->order('order', 'ASC')
                            ->values();

            return $values;
        } catch (\Exception $e) {
            return array();
        }
    }
770050
protected function getCategoryUrl()
    {
        $rootKey = $this->container->getParameter('sulu_product.category_root_key');

        if (null !== $rootKey) {
            return $this->generateUrl(
                'get_category_children',
                ['key' => $rootKey, 'flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
            );
        }

        return $this->generateUrl(
            'get_categories',
            ['flat' => 'true', 'sortBy' => 'depth', 'sortOrder' => 'asc']
        );
    }