Class helper contains all the library functions.
More...
|
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.
|
|
|
const | PLUGINNAME = 'qbank_managecategories' |
| Name of this plugin.
|
|
Class helper contains all the library functions.
Library functions used by qbank_managecategories. This code is based on lib/questionlib.php by Martin Dougiamas.
- Copyright
- 2021 Catalyst IT Australia Pty Ltd
- Author
- Guillermo Gomez Arias guill.nosp@m.ermo.nosp@m.gomez.nosp@m.@cat.nosp@m.alyst.nosp@m.-au..nosp@m.net
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ 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 | $categories | An array of category objects, for example from the. |
int | $nochildrenof | |
- Return values
-
array | The 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 | $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 | |
- Return values
-
array | a 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 | $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. |
- Return values
-
array | of category objects. |
- Exceptions
-
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 | $categories | The list of categories. |
- Return values
-
◆ 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 | $todelete | a category id. |
- Exceptions
-
◆ 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 | $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. |
- Return values
-
- 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 | $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 |
- 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 | $categories | An array of question categories. |
bool | $escape | Whether the returned name of the thing is to be HTML escaped or not. |
- Return values
-
array | The same question category list given to the function, with the top category names being translated. |
- Exceptions
-
◆ 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 | $categoryid | a category id. |
- Return values
-
- Exceptions
-
◆ 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 | $categoryid | a category id. |
- Return values
-
- Exceptions
-
◆ 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 | $categoryid | The category ID. |
- Exceptions
-
The documentation for this class was generated from the following file: