Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 400 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: helper  - X-Ref

Class helper contains all the library functions.

Library functions used by qbank_managecategories.
This code is based on lib/questionlib.php by Martin Dougiamas.

question_remove_stale_questions_from_category(int $categoryid)   X-Ref
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

param: int $categoryid The category ID.

question_is_only_child_of_top_category_in_context(int $categoryid)   X-Ref
Checks whether this is the only child of a top category in a context.

param: int $categoryid a category id.
return: bool

question_is_top_category(int $categoryid)   X-Ref
Checks whether the category is a "Top" category (with no parent).

param: int $categoryid a category id.
return: bool

question_can_delete_cat(int $todelete)   X-Ref
Ensures that this user is allowed to delete this category.

param: int $todelete a category id.

flatten_category_tree(array &$categories, $id, int $depth = 0, int $nochildrenof = -1)   X-Ref
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.

param: array $categories an array of categories which has had childids
param: int $id the category to start the indenting process from.
param: int $depth the indent depth. Used in recursive calls.
param: int $nochildrenof
return: array a new array of categories, in the right order for the tree.

add_indented_names(array $categories, int $nochildrenof = -1)   X-Ref
Format categories into an indented list reflecting the tree structure.

param: array $categories An array of category objects, for example from the.
param: int $nochildrenof
return: array The formatted list of categories.

question_category_select_menu(array $contexts, bool $top = false, int $currentcat = 0,string $selected = "", int $nochildrenof = -1, bool $return = false)   X-Ref
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.

param: array $contexts
param: bool $top
param: int $currentcat
param: string $selected optionally, the id of a category to be selected by
param: int $nochildrenof
param: bool $return to return the string of the select menu or echo that from the method

get_categories_for_contexts($contexts, string $sortorder = 'parent, sortorder, name ASC',bool $top = false, int $showallversions = 0)   X-Ref
Get all the category objects, including a count of the number of questions in that category,
for all the categories in the lists $contexts.

param: context $contexts
param: string $sortorder used as the ORDER BY clause in the select statement.
param: bool $top Whether to return the top categories or not.
param: int $showallversions 1 to show all versions not only the latest.
return: array of category objects.

question_category_options(array $contexts, bool $top = false, int $currentcat = 0,bool $popupform = false, int $nochildrenof = -1,bool $escapecontextnames = true)   X-Ref
Output an array of question categories.

param: array $contexts The list of contexts.
param: bool $top Whether to return the top categories or not.
param: int $currentcat
param: bool $popupform
param: int $nochildrenof
param: bool $escapecontextnames Whether the returned name of the thing is to be HTML escaped or not.
return: array

question_add_context_in_key(array $categories)   X-Ref
Add context in categories key.

param: array $categories The list of categories.
return: array

question_fix_top_names(array $categories, bool $escape = true)   X-Ref
Finds top categories in the given categories hierarchy and replace their name with a proper localised string.

param: array $categories An array of question categories.
param: bool $escape Whether the returned name of the thing is to be HTML escaped or not.
return: array The same question category list given to the function, with the top category names being translated.