Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403]

QUESTION_PAGE_LENGTH - Number of categories to display on page.

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

Defines 1 class


Class: question_category_object  - X-Ref

Class for performing operations on question categories.

__construct($page, $pageurl, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)   X-Ref
Constructor.

param: int $page page number.
param: moodle_url $pageurl base URL of the display categories page. Used for redirects.
param: context[] $contexts contexts where the current user can edit categories.
param: int $currentcat id of the category to be edited. 0 if none.
param: int|null $defaultcategory id of the current category. null if none.
param: int $todelete id of the category to delete. 0 if none.
param: context[] $addcontexts contexts where the current user can add questions.

initialize($page, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)   X-Ref
Initializes this classes general category-related variables

param: int $page page number.
param: context[] $contexts contexts where the current user can edit categories.
param: int $currentcat id of the category to be edited. 0 if none.
param: int|null $defaultcategory id of the current category. null if none.
param: int $todelete id of the category to delete. 0 if none.
param: context[] $addcontexts contexts where the current user can add questions.

display_user_interface()   X-Ref
Displays the user interface.


output_new_table()   X-Ref
Outputs a table to allow entry of a new category


output_edit_lists()   X-Ref
Outputs a list to allow editing/rearranging of existing categories.

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


get_course_ids(array $categories)   X-Ref
Gets all the courseids for the given categories.

param: array $categories contains category objects in  a tree representation
return: array courseids flat array in form categoryid=>courseid

edit_single_category(int $categoryid)   X-Ref
Edit a category, or add a new one if the id is zero.

param: int $categoryid Category id.

set_viable_parents(array &$parentstrings, object $category)   X-Ref
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.

param: array $parentstrings a list of parentstrings
param: object $category Category object

get_question_categories(int $parent = null, string $sort = "sortorder ASC")   X-Ref
Gets question categories.

param: int|null $parent - if given, restrict records to those with this parent id.
param: string $sort - [[sortfield [,sortfield]] {ASC|DESC}].
return: array categories.

delete_category(int $categoryid)   X-Ref
Deletes an existing question category.

param: int $categoryid id of category to delete.

move_questions_and_delete_category(int $oldcat, int $newcat)   X-Ref
Move questions and then delete the category.

param: int $oldcat id of the old category.
param: int $newcat id of the new category.

display_move_form($questionsincategory, $category)   X-Ref
Display the form to move a category.

param: int $questionsincategory
param: object $category

move_questions(int $oldcat, int $newcat)   X-Ref
Move questions to another category.

param: int $oldcat id of the old category.
param: int $newcat id of the new category.

add_category($newparent, $newcategory, $newinfo, $return = false, $newinfoformat = FORMAT_HTML,$idnumber = null)   X-Ref
Create a new category.

Data is expected to come from question_category_edit_form.

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

param: string $newparent 'categoryid,contextid' of the parent category.
param: string $newcategory the name.
param: string $newinfo the description.
param: bool $return if true, return rather than redirecting.
param: int|string $newinfoformat description format. One of the FORMAT_ constants.
param: null $idnumber the idnumber. '' is converted to null.
return: bool|int New category id if successful, else false.

update_category($updateid, $newparent, $newname, $newinfo, $newinfoformat = FORMAT_HTML,$idnumber = null, $redirect = true)   X-Ref
Updates an existing category with given params.

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

param: int $updateid id of the category to update.
param: int $newparent 'categoryid,contextid' of the parent category to set.
param: string $newname category name.
param: string $newinfo category description.
param: int|string $newinfoformat description format. One of the FORMAT_ constants.
param: int $idnumber the idnumber. '' is converted to null.
param: bool $redirect if true, will redirect once the DB is updated (default).

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

param: int $categoryid id of the category.
return: int[] array of question ids.