Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

A class for representing question categories.

Copyright: 1999 onwards Martin Dougiamas {@link http://moodle.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 624 lines (26 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 4 classes

question_category_list:: (4 methods):
  __construct()
  get_records()
  get_top_level_parent_id()
  process_actions()

question_category_list_item:: (2 methods):
  set_icon_html()
  item_html()

question_category_object:: (2 methods):
  __construct()
  question_category_object()

name:: (15 methods):
  initialize()
  display_user_interface()
  output_new_table()
  output_edit_lists()
  get_course_ids()
  edit_single_category()
  set_viable_parents()
  get_question_categories()
  delete_category()
  move_questions_and_delete_category()
  display_move_form()
  move_questions()
  add_category()
  update_category()
  get_real_question_ids_in_category()


Class: question_category_list  - X-Ref

Class representing a list of question categories

__construct($type='ul', $attributes='', $editable = false, $pageurl=null, $page = 0, $pageparamname = 'page', $itemsperpage = 20, $context = null)   X-Ref


get_records()   X-Ref
No description

get_top_level_parent_id($item)   X-Ref
Returns the highest category id that the $item can have as its parent.
Note: question categories cannot go higher than the TOP category.

param: list_item $item The item which its top level parent is going to be returned.
return: int

process_actions($left, $right, $moveup, $movedown)   X-Ref
process any actions.

param: integer $left id of item to move left
param: integer $right id of item to move right
param: integer $moveup id of item to move up
param: integer $movedown id of item to move down
return: void

Class: question_category_list_item  - X-Ref

An item in a list of question categories.

set_icon_html($first, $last, $lastitem)   X-Ref
No description

item_html($extraargs = array()   X-Ref
No description

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.

question_category_object($page, $pageurl, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

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


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($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($categoryid)   X-Ref
No description

set_viable_parents(&$parentstrings, $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

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

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

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

param: int deletecat id of category to delete

move_questions_and_delete_category($oldcat, $newcat)   X-Ref
No description

display_move_form($questionsincategory, $category)   X-Ref
No description

move_questions($oldcat, $newcat)   X-Ref
No description

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.