Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

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: 609 lines (25 kb)
Included or required:0 times
Referenced: 5 times
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:: (14 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()


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).