Returns a list of categories with their related fields.

@param string $component
@param string $area
@param int $itemid
@return category_controller[]
487186
public static function get_categories_with_fields(string $component, string $area, int $itemid) : array {
        global $DB;

        $categories = [];

        $options = [
                'component' => $component,
                'area'      => $area,
                'itemid'    => $itemid
        ];

        $plugins = \core\plugininfo\customfield::get_enabled_plugins();
        list($sqlfields, $params) = $DB->get_in_or_equal(array_keys($plugins), SQL_PARAMS_NAMED, 'param', true, null);

        $fields = 'f.*, ' . join(', ', array_map(function($field) {
                return "c.$field AS category_$field";
        }, array_diff(array_keys(category::properties_definition()), ['usermodified', 'timemodified'])));
        $sql = "SELECT $fields
                  FROM {customfield_category} c
             LEFT JOIN {customfield_field} f ON c.id = f.categoryid AND f.type $sqlfields
                 WHERE c.component = :component AND c.area = :area AND c.itemid = :itemid
              ORDER BY c.sortorder, f.sortorder";
        $fieldsdata = $DB->get_recordset_sql($sql, $options + $params);

        foreach ($fieldsdata as $data) {
            if (!array_key_exists($data->category_id, $categories)) {
                $categoryobj = new \stdClass();
                foreach ($data as $key => $value) {
                    if (preg_match('/^category_(.*)$/', $key, $matches)) {
                        $categoryobj->{$matches[1]} = $value;
                    }
                }
                $category = category_controller::create(0, $categoryobj);
                $categories[$categoryobj->id] = $category;
            } else {
                $category = $categories[$data->categoryid];
            }
            if ($data->id) {
                $fieldobj = new \stdClass();
                foreach ($data as $key => $value) {
                    if (!preg_match('/^category_/', $key)) {
                        $fieldobj->{$key} = $value;
                    }
                }
                $field = field_controller::create(0, $fieldobj, $category);
            }
        }
        $fieldsdata->close();

        return $categories;
    }
787043
public function get_active_instances($itemid) {
        global $DB;
        $conditions = array('definitionid'  => $this->definition->id,
                    'itemid' => $itemid,
                    'status'  => gradingform_instance::INSTANCE_STATUS_ACTIVE);
        $records = $DB->get_recordset('grading_instances', $conditions);
        $rv = array();
        foreach ($records as $record) {
            $rv[] = $this->get_instance($record);
        }
        $records->close();
        return $rv;
    }
805308
public function getList($area, $locale)
    {
        $model = $this->app->make($this->model());
        $group = str_replace(["\n", "\r", ' '], '', $this->app->make('languages')->getTranslationNamedGroup());

        return $model->where('area', $area)->where(function($query) use($locale, $group) {
                    $query->where('locale', $locale);
                    if (strlen($group) > 0) {
                        $query->where('group', $group);
                    }
                });
    }
394834
public function getCategory(ConnectionInterface $con = null)
    {
        if ($this->aCategory === null && ($this->category_id != 0)) {
            $this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aCategory->addC2Ms($this);
             */
        }

        return $this->aCategory;
    }
1052431
public static function get_areas_names($tagcollid, $enabledonly = true) {
        $allitemtypes = core_tag_area::get_areas($tagcollid, $enabledonly);
        $itemtypes = array();
        foreach ($allitemtypes as $itemtype => $it) {
            foreach ($it as $component => $v) {
                $itemtypes[$v->id] = core_tag_area::display_name($component, $itemtype);
            }
        }
        return $itemtypes;
    }
792884
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
        // try to emulate require_login() tests here
        if (!isloggedin()) {
            return null;
        }

        $coursecontext = $this->context->get_course_context(true);
        if (!$this->course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
            return null;
        }

        if (!is_viewing($this->context) and !$this->browser->is_enrolled($this->course->id)) {
            // no peaking here if not enrolled or inspector
            return null;
        }

        if (!$this->cm->uservisible) {
            // activity hidden sorry
            return null;
        }

        if (empty($component)) {
            return $this;
        }

        if ($component == 'mod_'.$this->modname and $filearea === 'intro') {
            return $this->get_area_intro($itemid, $filepath, $filename);
        } else if ($component == 'backup' and $filearea === 'activity') {
            return $this->get_area_backup($itemid, $filepath, $filename);
        }

        if ($functionname = component_callback_exists('mod_'.$this->modname, 'get_file_info')) {
            $cm = $this->cm->get_course_module_record();
            return $functionname($this->browser, $this->areas, $this->course, $cm,
                $this->context, $filearea, $itemid, $filepath, $filename);
        }

        return null;
    }
488998
public function getItemByPath(string $path, string $itemId = ''):array
    {
        if (empty($itemId)) {
            return $this->get("Items/ByPath?Path={$path}");
        } else {
            return $this->get("Items({$itemId})/ByPath?Path={$path}");
        }
    }
531988
public function getRubricByAlias($alias, $regionId, array $additionalFields = array())
    {
        return $this->getSingle(
            'catalog/rubric/get',
            'Rubric',
            array('alias' => $alias, 'region_id' => (int)$regionId, 'fields' => self::getArray($additionalFields))
        );
    }
164456
public function getItemById(string $itemId, bool $getChildren = false):array
    {
        $parameters = $getChildren === true ? '$expand=Children' : '';

        return $this->get("Items({$itemId})?{$parameters}");
    }
44398
public function getCategoryUrls(string $category, array $criteria = [], $siteId = null): array
    {
        return RouteMap::$plugin->routes->getCategoryUrls($category, $criteria, $siteId);
    }
895444
public static function display_name($component, $itemtype) {
        $identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
        if ($component === 'core') {
            $component = 'tag';
        }
        return new lang_string($identifier, $component);
    }
171762
public static function get_by_id($tagareaid) {
        $tagareas = self::get_areas();
        foreach ($tagareas as $itemtype => $it) {
            foreach ($it as $component => $v) {
                if ($v->id == $tagareaid) {
                    return $v;
                }
            }
        }
        return null;
    }
640503
protected function getItem($itemType, $itemId, TagAttributes $attr)
    {
        $data = '';

        switch ($itemType) {

            case self::LAYOUT_WIDGET:
                try {
                    /** @var $data \PageBuilder\BaseWidget */
                    $widgetName = $itemId . WidgetFactory::WIDGET_SUFFIX;
                    $options    = $attr->getOptions();

                    if (!$this->isShared($options)) {
                        $this->getServiceLocator()->setShared($widgetName, false);
                    }

                    if (array_key_exists('shared', $options) and empty($options['shared'])) {
                        $this->getServiceLocator()->setShared($widgetName, false);
                    }

                    $data = $this->getServiceLocator()->get($widgetName);
                    $attr->addClass($data->getId());
                    $data->setAttributes($attr);
                } catch (ServiceNotFoundException $e) {
                    $data = '';
                }

                break;
            case self::LAYOUT_USER_DEFINED:
                /** @var $componentModel \PageBuilder\Model\ComponentModel */
                $componentModel = $this->getServiceLocator()->get('pagebuilder\model\component');

                /** @var $component \PageBuilder\Entity\Component */
                if ($component = $componentModel->findOneTranslatedBy(['id' => $itemId])) {
                    $data     = $this->transform($component->getContent());
                    $comId    = "data-id='{$itemType}-{$itemId}'";
                    $cssClass = trim("{$itemType} {$component->getCssClass()}");
                    $attr->addClass($cssClass)
                        ->addClass($component->getCssId())
                        ->addAttr($comId)
                        ->addAttr("id='{$component->getCssId()}'");

                    //Apply replaces to the output
                    $replacements = $this->getOptions()->getReplacements();
                    $data         = str_replace(array_keys($replacements), array_values($replacements), $data);

                    //apply formats to the data
                    $data = $this->applyFormats($data);
                }

                break;
            default:
                $message = 'Layout itemType ' . $itemType . ' not found';
                if ($this->serviceManager->has('logger')) {
                    $this->serviceManager->get('logger')->err($message);
                } else {
                    throw new RuntimeException($message);
                }
        }

        return new WidgetData(
            [
                'data'       => $data,
                'attributes' => $attr,
            ]
        );
    }
657967
public static function get_search_area_categories() {
        if (!isset(static::$searchareacategories)) {
            $categories = self::get_core_search_area_categories();

            // Go through all existing search areas and get categories they are assigned to.
            $areacategories = [];
            foreach (self::get_search_areas_list() as $searcharea) {
                foreach ($searcharea->get_category_names() as $categoryname) {
                    if (!key_exists($categoryname, $areacategories)) {
                        $areacategories[$categoryname] = [];
                    }

                    $areacategories[$categoryname][] = $searcharea;
                }
            }

            // Populate core categories by areas.
            foreach ($areacategories as $name => $searchareas) {
                if (key_exists($name, $categories)) {
                    $categories[$name]->set_areas($searchareas);
                } else {
                    throw new \coding_exception('Unknown core search area category ' . $name);
                }
            }

            // Get additional categories.
            $additionalcategories = self::get_additional_search_area_categories();
            foreach ($additionalcategories as $additionalcategory) {
                if (!key_exists($additionalcategory->get_name(), $categories)) {
                    $categories[$additionalcategory->get_name()] = $additionalcategory;
                }
            }

            // Remove categories without areas.
            foreach ($categories as $key => $category) {
                if (empty($category->get_areas())) {
                    unset($categories[$key]);
                }
            }

            // Sort categories by order.
            uasort($categories, function($category1, $category2) {
                return $category1->get_order() > $category2->get_order();
            });

            static::$searchareacategories = $categories;
        }

        return static::$searchareacategories;
    }
125712
public static function reload_template($component, $area, $itemid) {
        global $PAGE;

        $params = self::validate_parameters(self::reload_template_parameters(),
                      ['component' => $component, 'area' => $area, 'itemid' => $itemid]);

        $PAGE->set_context(context_system::instance());
        $handler = \core_customfield\handler::get_handler($params['component'], $params['area'], $params['itemid']);
        self::validate_context($handler->get_configuration_context());
        if (!$handler->can_configure()) {
            throw new moodle_exception('nopermissionconfigure', 'core_customfield');
        }
        $output = $PAGE->get_renderer('core_customfield');
        $outputpage = new \core_customfield\output\management($handler);
        return $outputpage->export_for_template($output);
    }
285013
public static function delete_customfields_data_for_context(string $component, string $area, \context $context) {
        global $DB;

        $sql = "SELECT d.id
            FROM {customfield_category} c
            JOIN {customfield_field} f ON f.categoryid = c.id
            JOIN {customfield_data} d ON d.fieldid = f.id
            JOIN {context} ctx ON ctx.id = d.contextid AND ctx.path LIKE :ctxpath
            WHERE c.component = :cfcomponent AND c.area = :cfarea";
        $params = self::get_params($component, $area, ['ctxpath' => $context->path . '%']);

        self::before_delete_data('IN (' . $sql . ') ', $params);

        $DB->execute("DELETE FROM {customfield_data}
            WHERE fieldid IN (SELECT f.id
                FROM {customfield_category} c
                JOIN {customfield_field} f ON f.categoryid = c.id
                WHERE c.component = :cfcomponent AND c.area = :cfarea)
            AND contextid IN (SELECT id FROM {context} WHERE path LIKE :ctxpath)",
            $params);
    }
108825
public static function getCategoryAssociations($id = 0, $extension = 'com_content')
	{
		$return = array();

		if ($id)
		{
			// Load route helper
			jimport('helper.route', JPATH_COMPONENT_SITE);
			$helperClassname = ucfirst(substr($extension, 4)) . 'HelperRoute';

			$associations = CategoriesHelper::getAssociations($id, $extension);

			foreach ($associations as $tag => $item)
			{
				if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute')))
				{
					$return[$tag] = $helperClassname::getCategoryRoute($item, $tag);
				}
				else
				{
					$return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item;
				}
			}
		}

		return $return;
	}