Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
qbank_managecategories\helper Class Reference
Inheritance diagram for qbank_managecategories\helper:
mod_quiz\question\bank\filter\custom_category_condition_helper

Static Public Member Functions

static add_indented_names (array $categories, int $nochildrenof=-1)
 Format categories into an indented list reflecting the tree structure.
 
static flatten_category_tree (array &$categories, $id, int $depth=0, int $nochildrenof=-1)
 Only for the use of add_indented_names().
 
static get_categories_for_contexts ($contexts, string $sortorder='parent, sortorder, name ASC', bool $top=false, int $showallversions=0)
 Get all the category objects, including a count of the number of questions in that category, for all the categories in the lists $contexts.
 
static question_add_context_in_key (array $categories)
 Add context in categories key.
 
static question_can_delete_cat (int $todelete)
 Ensures that this user is allowed to delete this category.
 
static 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.
 
static question_category_select_menu (array $contexts, bool $top=false, int $currentcat=0, string $selected="", int $nochildrenof=-1, bool $return=false)
 Output a select menu of question categories.
 
static 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.
 
static question_is_only_child_of_top_category_in_context (int $categoryid)
 Checks whether this is the only child of a top category in a context.
 
static question_is_top_category (int $categoryid)
 Checks whether the category is a "Top" category (with no parent).
 
static question_remove_stale_questions_from_category (int $categoryid)
 Remove stale questions from a category.
 

Public Attributes

const PLUGINNAME = 'qbank_managecategories'
 Name of this plugin.
 

Member Function Documentation

◆ add_indented_names()

static qbank_managecategories\helper::add_indented_names ( array $categories,
int $nochildrenof = -1 )
static

Format categories into an indented list reflecting the tree structure.

Parameters
array$categoriesAn array of category objects, for example from the.
int$nochildrenof
Return values
arrayThe formatted list of categories.

◆ flatten_category_tree()

static qbank_managecategories\helper::flatten_category_tree ( array & $categories,
$id,
int $depth = 0,
int $nochildrenof = -1 )
static

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$nochildrenof
Return values
arraya new array of categories, in the right order for the tree.

◆ get_categories_for_contexts()

static qbank_managecategories\helper::get_categories_for_contexts ( $contexts,
string $sortorder = 'parent,
sortorder ,
name ASC' ,
bool $top = false,
int $showallversions = 0 )
static

Get all the category objects, including a count of the number of questions in that category, for all the categories in the lists $contexts.

Parameters
context$contexts
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

Reimplemented in mod_quiz\question\bank\filter\custom_category_condition_helper.

◆ question_add_context_in_key()

static qbank_managecategories\helper::question_add_context_in_key ( array $categories)
static

Add context in categories key.

Parameters
array$categoriesThe list of categories.
Return values
array

◆ question_can_delete_cat()

static qbank_managecategories\helper::question_can_delete_cat ( int $todelete)
static

Ensures that this user is allowed to delete this category.

Parameters
int$todeletea category id.
Exceptions
required_capability_exception
dml_exception|moodle_exception

◆ question_category_options()

static qbank_managecategories\helper::question_category_options ( array $contexts,
bool $top = false,
int $currentcat = 0,
bool $popupform = false,
int $nochildrenof = -1,
bool $escapecontextnames = true )
static

Output an array of question categories.

Parameters
array$contextsThe list of contexts.
bool$topWhether to return the top categories or not.
int$currentcat
bool$popupform
int$nochildrenof
bool$escapecontextnamesWhether the returned name of the thing is to be HTML escaped or not.
Return values
array
Exceptions
coding_exception|dml_exception

Reimplemented in mod_quiz\question\bank\filter\custom_category_condition_helper.

◆ question_category_select_menu()

static qbank_managecategories\helper::question_category_select_menu ( array $contexts,
bool $top = false,
int $currentcat = 0,
string $selected = "",
int $nochildrenof = -1,
bool $return = false )
static

Output a select menu of question categories.

Categories from this course and (optionally) published categories from other courses are included. Optionally, only categories the current user may edit can be included.

Parameters
array$contexts
bool$top
int$currentcat
string$selectedoptionally, the id of a category to be selected by default in the dropdown.
int$nochildrenof
bool$returnto return the string of the select menu or echo that from the method
Exceptions
coding_exception|dml_exception

◆ question_fix_top_names()

static qbank_managecategories\helper::question_fix_top_names ( array $categories,
bool $escape = true )
static

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

◆ question_is_only_child_of_top_category_in_context()

static qbank_managecategories\helper::question_is_only_child_of_top_category_in_context ( int $categoryid)
static

Checks whether this is the only child of a top category in a context.

Parameters
int$categoryida category id.
Return values
bool
Exceptions
dml_exception

◆ question_is_top_category()

static qbank_managecategories\helper::question_is_top_category ( int $categoryid)
static

Checks whether the category is a "Top" category (with no parent).

Parameters
int$categoryida category id.
Return values
bool
Exceptions
dml_exception

◆ question_remove_stale_questions_from_category()

static qbank_managecategories\helper::question_remove_stale_questions_from_category ( int $categoryid)
static

Remove stale questions from a category.

While questions should not be left behind when they are not used any more, it does happen, maybe via restore, or old logic, or uncovered scenarios. When this happens, the users are unable to delete the question category unless they move those stale questions to another one category, but to them the category is empty as it does not contain anything. The purpose of this function is to detect the questions that may have gone stale and remove them.

You will typically use this prior to checking if the category contains questions.

The stale questions (unused and hidden to the user) handled are:

  • hidden questions
  • random questions
Parameters
int$categoryidThe category ID.
Exceptions
dml_exception

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