Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
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. | |
Class for performing operations on question categories.
qbank_managecategories\question_category_object::__construct | ( | $page, | |
$pageurl, | |||
$contexts, | |||
$currentcat, | |||
$defaultcategory, | |||
$todelete, | |||
$addcontexts ) |
Constructor.
int | $page | page number. |
moodle_url | $pageurl | base URL of the display categories page. Used for redirects. |
context[] | $contexts | contexts where the current user can edit categories. |
int | $currentcat | id of the category to be edited. 0 if none. |
int | null | $defaultcategory | id of the current category. null if none. |
int | $todelete | id of the category to delete. 0 if none. |
context[] | $addcontexts | contexts where the current user can add questions. |
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.
string | $newparent | 'categoryid,contextid' of the parent category. |
string | $newcategory | the name. |
string | $newinfo | the description. |
bool | $return | if true, return rather than redirecting. |
int | string | $newinfoformat | description format. One of the FORMAT_ constants. |
null | $idnumber | the idnumber. '' is converted to null. |
bool|int | New category id if successful, else false. |
qbank_managecategories\question_category_object::delete_category | ( | int | $categoryid | ) |
Deletes an existing question category.
int | $categoryid | id of category to delete. |
qbank_managecategories\question_category_object::display_move_form | ( | $questionsincategory, | |
$category ) |
Display the form to move a category.
int | $questionsincategory | |
object | $category |
coding_exception |
qbank_managecategories\question_category_object::edit_single_category | ( | int | $categoryid | ) |
Edit a category, or add a new one if the id is zero.
int | $categoryid | Category id. |
qbank_managecategories\question_category_object::get_course_ids | ( | array | $categories | ) |
Gets all the courseids for the given categories.
array | $categories | contains category objects in a tree representation |
array | courseids flat array in form categoryid=>courseid |
qbank_managecategories\question_category_object::get_question_categories | ( | int | $parent = null, |
string | $sort = "sortorder ASC" ) |
Gets question categories.
int | null | $parent | - if given, restrict records to those with this parent id. |
string | $sort | - [[sortfield [,sortfield]] {ASC|DESC}]. |
array | categories. |
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.
int | $categoryid | id of the category. |
int[] | array of question ids. |
qbank_managecategories\question_category_object::initialize | ( | $page, | |
$contexts, | |||
$currentcat, | |||
$defaultcategory, | |||
$todelete, | |||
$addcontexts ) |
Initializes this classes general category-related variables.
int | $page | page number. |
context[] | $contexts | contexts where the current user can edit categories. |
int | $currentcat | id of the category to be edited. 0 if none. |
int | null | $defaultcategory | id of the current category. null if none. |
int | $todelete | id of the category to delete. 0 if none. |
context[] | $addcontexts | contexts where the current user can add questions. |
qbank_managecategories\question_category_object::move_questions | ( | int | $oldcat, |
int | $newcat ) |
Move questions to another category.
int | $oldcat | id of the old category. |
int | $newcat | id of the new category. |
dml_exception |
qbank_managecategories\question_category_object::move_questions_and_delete_category | ( | int | $oldcat, |
int | $newcat ) |
Move questions and then delete the category.
int | $oldcat | id of the old category. |
int | $newcat | id of the new category. |
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
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.
array | $parentstrings | a list of parentstrings |
object | $category | Category object |
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!
int | $updateid | id of the category to update. |
int | $newparent | 'categoryid,contextid' of the parent category to set. |
string | $newname | category name. |
string | $newinfo | category description. |
int | string | $newinfoformat | description format. One of the FORMAT_ constants. |
int | $idnumber | the idnumber. '' is converted to null. |
bool | $redirect | if true, will redirect once the DB is updated (default). |