Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
core_question\output\question_category_selector Class Reference
Inheritance diagram for core_question\output\question_category_selector:
core\output\renderable core\output\templatable

Public Member Functions

 add_indented_names (array $categories, int $nochildrenof=-1)
 Format categories into an indented list reflecting the tree structure.
 
 export_for_template (renderer_base $output)
 Context for the question_category_selector.mustache template.
 
 flatten_category_tree (array &$categories, $id, int $depth=0, int $nochildrenof=-1)
 Only for the use of add_indented_names().
 
 get_categories_for_contexts (string $contexts, string $sortorder='parent, sortorder, name ASC', bool $top=false, int $showallversions=0,)
 Constructor.
 
 question_add_context_in_key (array $categories)
 Add context in categories key.
 
 question_category_options (array $contexts, bool $top=false, int $currentcat=0, bool $popupform=false, int $nochildrenof=-1, bool $escapecontextnames=true,)
 Output an array of question categories.
 
 question_fix_top_names (array $categories, bool $escape=true)
 Finds top categories in the given categories hierarchy and replace their name with a proper localised string.
 

Member Function Documentation

◆ add_indented_names()

core_question\output\question_category_selector::add_indented_names ( array $categories,
int $nochildrenof = -1 )

Format categories into an indented list reflecting the tree structure.

Parameters
array$categoriesAn array of category objects, keyed by ID.
int$nochildrenofIf the category with this ID is in the list, don't include its children.
Return values
arrayThe formatted list of categories.

◆ export_for_template()

core_question\output\question_category_selector::export_for_template ( renderer_base $output)

Context for the question_category_selector.mustache template.

Parameters
renderer_base$output
Return values
array[][ 'banks' => a 2-D array of question banks and categories, for a plain select list with optgroups. 'categories' => A flat list of categories, with bank names and disabled entries, for enhancing with an Autocomplete. ]

Implements core\output\templatable.

◆ flatten_category_tree()

core_question\output\question_category_selector::flatten_category_tree ( array & $categories,
$id,
int $depth = 0,
int $nochildrenof = -1 )

Only for the use of add_indented_names().

Recursively adds an indentedname field to each category, starting with the category with id $id, and dealing with that category and all its children, and return a new array, with those categories in the right order.

Parameters
array$categoriesan array of categories which has had childids fields added by flatten_category_tree(). Passed by reference for performance only. It is not modfied.
int$idthe category to start the indenting process from.
int$depththe indent depth. Used in recursive calls.
int$nochildrenofIf the category with this ID is in the list, don't recur to its children.
Return values
arraya new array of categories, in the right order for the tree.

◆ get_categories_for_contexts()

core_question\output\question_category_selector::get_categories_for_contexts ( string $contexts,
string $sortorder = 'parent,
sortorder ,
name ASC' ,
bool $top = false,
int $showallversions = 0 )

Constructor.

Parameters
array$contexts
bool$top
string$currentcat
string$selected
int$nochildrenof
bool$autocompleteGet all the category objects, including a count of the number of questions in that category, for all the categories in the lists $contexts.
string$contextscomma separated list of contextids
string$sortorderused as the ORDER BY clause in the select statement.
bool$topWhether to return the top categories or not.
int$showallversions1 to show all versions not only the latest.
Return values
arrayof category objects.
Exceptions
dml_exception

◆ question_add_context_in_key()

core_question\output\question_category_selector::question_add_context_in_key ( array $categories)

Add context in categories key.

Parameters
array$categoriesThe list of categories, keyed by ID.
Return values
arrayThe list with the context id added to each key, id, and parent attribute.

◆ question_category_options()

core_question\output\question_category_selector::question_category_options ( array $contexts,
bool $top = false,
int $currentcat = 0,
bool $popupform = false,
int $nochildrenof = -1,
bool $escapecontextnames = true )

Output an array of question categories.

Parameters
array$contextsThe list of contexts.
bool$topWhether to return the top categories or not.
int$currentcatThe current category, to exclude from the list.
bool$popupformReturn each question bank's group in an additional nested array.
int$nochildrenofDon't include children of this category
bool$escapecontextnamesWhether the returned name of the thing is to be HTML escaped or not.
Return values
array
Exceptions
coding_exception|dml_exception

◆ question_fix_top_names()

core_question\output\question_category_selector::question_fix_top_names ( array $categories,
bool $escape = true )

Finds top categories in the given categories hierarchy and replace their name with a proper localised string.

Parameters
array$categoriesAn array of question categories.
bool$escapeWhether the returned name of the thing is to be HTML escaped or not.
Return values
arrayThe same question category list given to the function, with the top category names being translated.
Exceptions
coding_exception

The documentation for this class was generated from the following file: