Moodle PHP Documentation 4.5
Moodle 4.5.5+ (Build: 20250711) (ce34e8ff087)
core_question\category_manager Class Reference

Public Member Functions

 add_category (string $newparent, string $newcategory, string $newinfo, string $newinfoformat=FORMAT_HTML, ?string $idnumber=null,)
 Create a new category.
 
 delete_category (int $categoryid)
 Deletes an existing question category.
 
 get_max_sortorder (int $parentid)
 Get current max sort in a given parent.
 
 get_real_question_ids_in_category (int $categoryid)
 Returns ids of the question in the given question category.
 
 idnumber_is_unique_in_context (?string $idnumber, int $contextid, ?int $excludecategoryid=null)
 Check there is no question category with the given ID number in the given context.
 
 is_only_child_of_top_category_in_context (int $categoryid)
 Checks whether this is the only child of a top category in a context.
 
 is_top_category (int $categoryid)
 Checks whether the category is a "Top" category (with no parent).
 
 move_questions (int $oldcat, int $newcat)
 Move questions to another category.
 
 move_questions_and_delete_category (int $oldcat, int $newcat)
 Move questions and then delete the category.
 
 require_can_delete_category (int $todelete)
 Ensures that this user is allowed to delete this category.
 
 require_manage_category (context $context)
 Check the user can manage categories in the given context.
 
 update_category (int $updateid, string $newparent, string $newname, string $newinfo, string $newinfoformat=FORMAT_HTML, ?string $idnumber=null, ?int $sortorder=null,)
 Updates an existing category with given params.
 

Protected Attributes

array array $managedcontexts = []
 Cached checks for managecategories permissions in each context.
 

Member Function Documentation

◆ add_category()

core_question\category_manager::add_category ( string $newparent,
string $newcategory,
string $newinfo,
string $newinfoformat = FORMAT_HTML,
?string $idnumber = null )

Create a new category.

Data is expected to come from question_category_edit_form.

By default redirects on success, unless $return is true.

Parameters
string$newparent'categoryid,contextid' of the parent category.
string$newcategorythe name.
string$newinfothe description.
string$newinfoformatdescription format. One of the FORMAT_ constants.
?string$idnumberthe idnumber. '' is converted to null.
Return values
intNew category id.

◆ delete_category()

core_question\category_manager::delete_category ( int $categoryid)

Deletes an existing question category.

Parameters
int$categoryidid of category to delete.

◆ get_max_sortorder()

core_question\category_manager::get_max_sortorder ( int $parentid)

Get current max sort in a given parent.

Parameters
int$parentidThe ID of the parent category.
Return values
intcurrent max sort order

◆ get_real_question_ids_in_category()

core_question\category_manager::get_real_question_ids_in_category ( int $categoryid)

Returns ids of the question in the given question category.

This method only returns the real question. It does not include subquestions of question types like multianswer.

Parameters
int$categoryidid of the category.
Return values
int[]array of question ids.

◆ idnumber_is_unique_in_context()

core_question\category_manager::idnumber_is_unique_in_context ( ?string $idnumber,
int $contextid,
?int $excludecategoryid = null )

Check there is no question category with the given ID number in the given context.

Parameters
?string$idnumberThe ID number to look for.
int$contextidThe context to check the categories in.
?int$excludecategoryidIf set, exclude this category from the check (e.g. if this is the one being edited).
Return values
bool
Exceptions
dml_exception

◆ is_only_child_of_top_category_in_context()

core_question\category_manager::is_only_child_of_top_category_in_context ( int $categoryid)

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

◆ is_top_category()

core_question\category_manager::is_top_category ( int $categoryid)

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

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

◆ move_questions()

core_question\category_manager::move_questions ( int $oldcat,
int $newcat )

Move questions to another category.

Parameters
int$oldcatid of the old category.
int$newcatid of the new category.
Exceptions
dml_exception

◆ move_questions_and_delete_category()

core_question\category_manager::move_questions_and_delete_category ( int $oldcat,
int $newcat )

Move questions and then delete the category.

Parameters
int$oldcatid of the old category.
int$newcatid of the new category.

◆ require_can_delete_category()

core_question\category_manager::require_can_delete_category ( int $todelete)

Ensures that this user is allowed to delete this category.

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

◆ require_manage_category()

core_question\category_manager::require_manage_category ( context $context)

Check the user can manage categories in the given context.

This caches a successful check in $this->managedcontexts in case we check the same context multiple times.

Parameters
context$context
Return values
void
Exceptions
required_capability_exception

◆ update_category()

core_question\category_manager::update_category ( int $updateid,
string $newparent,
string $newname,
string $newinfo,
string $newinfoformat = FORMAT_HTML,
?string $idnumber = null,
?int $sortorder = null )

Updates an existing category with given params.

Warning! parameter order and meaning confusingly different from add_category in some ways!

Parameters
int$updateidid of the category to update.
string$newparent'categoryid,contextid' of the parent category to set.
string$newnamecategory name.
string$newinfocategory description.
string$newinfoformatdescription format. One of the FORMAT_ constants.
?string$idnumberthe idnumber. '' is converted to null.
?int$sortorderThe updated sortorder. Not updated if null.

Member Data Documentation

◆ $managedcontexts

array array core_question\category_manager::$managedcontexts = []
protected

Cached checks for managecategories permissions in each context.

$managedcontexts;


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