Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
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. | |
|
static |
Format categories into an indented list reflecting the tree structure.
array | $categories | An array of category objects, for example from the. |
int | $nochildrenof |
array | The formatted list of categories. |
|
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.
array | $categories | an array of categories which has had childids fields added by flatten_category_tree(). Passed by reference for performance only. It is not modfied. |
int | $id | the category to start the indenting process from. |
int | $depth | the indent depth. Used in recursive calls. |
int | $nochildrenof |
array | a new array of categories, in the right order for the tree. |
|
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.
context | $contexts | |
string | $sortorder | used as the ORDER BY clause in the select statement. |
bool | $top | Whether to return the top categories or not. |
int | $showallversions | 1 to show all versions not only the latest. |
array | of category objects. |
dml_exception |
Reimplemented in mod_quiz\question\bank\filter\custom_category_condition_helper.
|
static |
Add context in categories key.
array | $categories | The list of categories. |
array |
|
static |
Ensures that this user is allowed to delete this category.
int | $todelete | a category id. |
required_capability_exception | |
dml_exception|moodle_exception |
|
static |
Output an array of question categories.
array | $contexts | The list of contexts. |
bool | $top | Whether to return the top categories or not. |
int | $currentcat | |
bool | $popupform | |
int | $nochildrenof | |
bool | $escapecontextnames | Whether the returned name of the thing is to be HTML escaped or not. |
array |
coding_exception|dml_exception |
Reimplemented in mod_quiz\question\bank\filter\custom_category_condition_helper.
|
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.
array | $contexts | |
bool | $top | |
int | $currentcat | |
string | $selected | optionally, the id of a category to be selected by default in the dropdown. |
int | $nochildrenof | |
bool | $return | to return the string of the select menu or echo that from the method |
coding_exception|dml_exception |
|
static |
Finds top categories in the given categories hierarchy and replace their name with a proper localised string.
array | $categories | An array of question categories. |
bool | $escape | Whether the returned name of the thing is to be HTML escaped or not. |
array | The same question category list given to the function, with the top category names being translated. |
coding_exception |
|
static |
Checks whether this is the only child of a top category in a context.
int | $categoryid | a category id. |
bool |
dml_exception |
|
static |
Checks whether the category is a "Top" category (with no parent).
int | $categoryid | a category id. |
bool |
dml_exception |
|
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:
int | $categoryid | The category ID. |
dml_exception |