Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Public Attributes | List of all members
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. More...
 
 add_category ($newparent, $newcategory, $newinfo, $return=false, $newinfoformat=FORMAT_HTML, $idnumber=null)
 Create a new category. More...
 
 delete_category ($categoryid)
 Deletes an existing question category. More...
 
 display_move_form ($questionsincategory, $category)
 
 display_user_interface ()
 Displays the user interface.
 
 edit_single_category ($categoryid)
 
 get_course_ids ($categories)
 gets all the courseids for the given categories More...
 
 get_question_categories ($parent=null, $sort="sortorder ASC")
 Gets question categories. More...
 
 initialize ($page, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)
 Initializes this classes general category-related variables.
 
 move_questions ($oldcat, $newcat)
 
 move_questions_and_delete_category ($oldcat, $newcat)
 
 output_edit_lists ()
 Outputs a list to allow editing/rearranging of existing categories. More...
 
 output_new_table ()
 Outputs a table to allow entry of a new category.
 
 question_category_object ($page, $pageurl, $contexts, $currentcat, $defaultcategory, $todelete, $addcontexts)
 Old syntax of class constructor. More...
 
 set_viable_parents (&$parentstrings, $category)
 Sets the viable parents. More...
 
 update_category ($updateid, $newparent, $newname, $newinfo, $newinfoformat=FORMAT_HTML, $idnumber=null, $redirect=true)
 Updates an existing category with given params. More...
 

Public Attributes

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

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

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

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

question_category_object::delete_category (   $categoryid)

Deletes an existing question category.

Parameters
intdeletecat id of category to delete

◆ get_course_ids()

question_category_object::get_course_ids (   $categories)

gets all the courseids for the given categories

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

◆ get_question_categories()

question_category_object::get_question_categories (   $parent = null,
  $sort = "sortorder ASC" 
)

Gets question categories.

Parameters
intparent - if given, restrict records to those with this parent id.
stringsort - [[sortfield [,sortfield]] {ASC|DESC}]
Return values
arraycategories

◆ output_edit_lists()

question_category_object::output_edit_lists ( )

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

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

◆ question_category_object()

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

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated:
since Moodle 3.1

◆ set_viable_parents()

question_category_object::set_viable_parents ( $parentstrings,
  $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
arrayparentstrings a list of parentstrings
objectcategory

◆ update_category()

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: