Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
qbank_managecategories\question_category_object Class Reference

Class for performing operations on question categories. More...

Public Member Functions

 __construct ($page, $pageurl, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)
 Constructor.
 
 add_category ($newparent, $newcategory, $newinfo, $return=false, $newinfoformat=FORMAT_HTML, $idnumber=null)
 Create a new category.
 
 delete_category (int $categoryid)
 Deletes an existing question category.
 
 display_move_form ($questionsincategory, $category)
 Display the form to move a category.
 
 display_user_interface ()
 Displays the user interface.
 
 edit_single_category (int $categoryid)
 Edit a category, or add a new one if the id is zero.
 
 get_course_ids (array $categories)
 Gets all the courseids for the given categories.
 
 get_question_categories (int $parent=null, string $sort="sortorder ASC")
 Gets question categories.
 
 get_real_question_ids_in_category (int $categoryid)
 Returns ids of the question in the given question category.
 
 initialize ($page, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)
 Initializes this classes general category-related variables.
 
 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.
 
 output_edit_lists ()
 Outputs a list to allow editing/rearranging of existing categories.
 
 output_new_table ()
 Outputs a table to allow entry of a new category.
 
 set_viable_parents (array &$parentstrings, object $category)
 Sets the viable parents.
 
 update_category ($updateid, $newparent, $newname, $newinfo, $newinfoformat=FORMAT_HTML, $idnumber=null, $redirect=true)
 Updates an existing category with given params.
 

Public Attributes

question_category_edit_form $catform
 Object representing form for adding / editing categories.
 
array $editlists = []
 nested lists to display categories.
 
moodle_url $pageurl
 Object representing url for this page.
 
array $str
 common language strings.
 
string $tab
 tab.
 
int $tabsize = 3
 tab size.
 

Detailed Description

Class for performing operations on question categories.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

qbank_managecategories\question_category_object::__construct ( $page,
$pageurl,
$contexts,
$currentcat,
$defaultcategory,
$todelete,
$addcontexts )

Constructor.

Parameters
int$pagepage number.
moodle_url$pageurlbase URL of the display categories page. Used for redirects.
context[]$contextscontexts where the current user can edit categories.
int$currentcatid of the category to be edited. 0 if none.
int | null$defaultcategoryid of the current category. null if none.
int$todeleteid of the category to delete. 0 if none.
context[]$addcontextscontexts where the current user can add questions.

Member Function Documentation

◆ add_category()

qbank_managecategories\question_category_object::add_category ( $newparent,
$newcategory,
$newinfo,
$return = false,
$newinfoformat = FORMAT_HTML,
$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.
bool$returnif true, return rather than redirecting.
int | string$newinfoformatdescription format. One of the FORMAT_ constants.
null$idnumberthe idnumber. '' is converted to null.
Return values
bool|intNew category id if successful, else false.

◆ delete_category()

qbank_managecategories\question_category_object::delete_category ( int $categoryid)

Deletes an existing question category.

Parameters
int$categoryidid of category to delete.

◆ display_move_form()

qbank_managecategories\question_category_object::display_move_form ( $questionsincategory,
$category )

Display the form to move a category.

Parameters
int$questionsincategory
object$category
Exceptions
coding_exception
Deprecated
No longer used by internal code and not recommended since Moodle 4.2 MDL-77299.

◆ edit_single_category()

qbank_managecategories\question_category_object::edit_single_category ( int $categoryid)

Edit a category, or add a new one if the id is zero.

Parameters
int$categoryidCategory id.

◆ get_course_ids()

qbank_managecategories\question_category_object::get_course_ids ( array $categories)

Gets all the courseids for the given categories.

Parameters
array$categoriescontains category objects in a tree representation
Return values
arraycourseids flat array in form categoryid=>courseid

◆ get_question_categories()

qbank_managecategories\question_category_object::get_question_categories ( int $parent = null,
string $sort = "sortorder ASC" )

Gets question categories.

Parameters
int | null$parent- if given, restrict records to those with this parent id.
string$sort- [[sortfield [,sortfield]] {ASC|DESC}].
Return values
arraycategories.

◆ get_real_question_ids_in_category()

qbank_managecategories\question_category_object::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.

◆ initialize()

qbank_managecategories\question_category_object::initialize ( $page,
$contexts,
$currentcat,
$defaultcategory,
$todelete,
$addcontexts )

Initializes this classes general category-related variables.

Parameters
int$pagepage number.
context[]$contextscontexts where the current user can edit categories.
int$currentcatid of the category to be edited. 0 if none.
int | null$defaultcategoryid of the current category. null if none.
int$todeleteid of the category to delete. 0 if none.
context[]$addcontextscontexts where the current user can add questions.

◆ move_questions()

qbank_managecategories\question_category_object::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()

qbank_managecategories\question_category_object::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.

◆ output_edit_lists()

qbank_managecategories\question_category_object::output_edit_lists ( )

Outputs a list to allow editing/rearranging of existing categories.

$this->initialize() must have already been called

◆ set_viable_parents()

qbank_managecategories\question_category_object::set_viable_parents ( array & $parentstrings,
object $category )

Sets the viable parents.

Viable parents are any except for the category itself, or any of it's descendants The parentstrings parameter is passed by reference and changed by this function.

Parameters
array$parentstringsa list of parentstrings
object$categoryCategory object

◆ update_category()

qbank_managecategories\question_category_object::update_category ( $updateid,
$newparent,
$newname,
$newinfo,
$newinfoformat = FORMAT_HTML,
$idnumber = null,
$redirect = true )

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.
int$newparent'categoryid,contextid' of the parent category to set.
string$newnamecategory name.
string$newinfocategory description.
int | string$newinfoformatdescription format. One of the FORMAT_ constants.
int$idnumberthe idnumber. '' is converted to null.
bool$redirectif true, will redirect once the DB is updated (default).

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