Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
files

Functions

 _tidy_question ($question, $category, array $tagobjects=null, array $filtercourses=null)
 Private function to factor common code out of get_question_options().
 
 add_indented_names ($categories, $nochildrenof=-1)
 Format categories into an indented list reflecting the tree structure.
 
 core_question_find_next_unused_idnumber (?string $oldidnumber, int $categoryid)
 If $oldidnumber ends in some digits then return the next available idnumber of the same form.
 
 core_question_question_preview_pluginfile ($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options=[])
 Serve questiontext files in the question text when they are displayed in this report.
 
 delete_question_bank_entry ($entryid)
 Check if there is more versions left for the entry.
 
 flatten_category_tree (&$categories, $id, $depth=0, $nochildrenof=-1)
 Private method, only for the use of add_indented_names().
 
 get_categories_for_contexts ($contexts, $sortorder='parent, sortorder, name ASC', $top=false)
 Get all the category objects, including a count of the number of questions in that category, for all the categories in the lists $contexts.
 
 get_import_export_formats ($type)
 Get list of available import or export formats.
 
 get_next_version (int $questionbankentryid)
 Get the next version number to create base on a Question bank entry id.
 
 get_question_bank_entry (int $questionid)
 Get the question_bank_entry object given a question id.
 
 get_question_options (&$questions, $loadtags=false, $filtercourses=null)
 Updates the question objects with question type specific information by calling {.
 
 get_question_version ($questionid)
 Get the question versions given a question id in a descending sort .
 
 idnumber_exist_in_question_category ($questionidnumber, $categoryid, $limitfrom=0, $limitnum=1)
 Check if an idnumber exist in the category.
 
 is_latest (string $version, string $questionbankentryid)
 Checks if question is the latest version.
 
 match_grade_options ($gradeoptionsfull, $grade, $matchgrades='error')
 Check whether a given grade is one of a list of allowed options.
 
 move_question_set_references (int $oldcategoryid, int $newcatgoryid, int $oldcontextid, int $newcontextid, bool $delete=false)
 Update the questioncontextid field for all question_set_references records given a new context id.
 
 print_question_icon ($question)
 Print the icon for the question type.
 
 question_add_context_in_key ($categories)
 Add context in categories key.
 
 question_category_delete_safe ($category)
 Category is about to be deleted, 1/ All questions are deleted for this question category.
 
 question_category_in_use ($categoryid, $recursive=false)
 Tests whether any question in a category is used by any part of Moodle.
 
 question_category_options ($contexts, $top=false, $currentcat=0, $popupform=false, $nochildrenof=-1, $escapecontextnames=true)
 Output an array of question categories.
 
 question_category_select_menu ($contexts, $top=false, $currentcat=0, $selected="", $nochildrenof=-1)
 Output a select menu of question categories.
 
 question_categorylist ($categoryid)
 Get the list of categories.
 
 question_categorylist_parents (int $categoryid)
 Get all parent categories of a given question category in descending order.
 
 question_context_has_any_questions ($context)
 Determine whether there are any questions belonging to this context, that is whether any of its question categories contain any questions.
 
 question_default_export_filename ($course, $category)
 Create a reasonable default file name for exporting questions from a particular category.
 
 question_delete_activity ($cm, $notused=false)
 All question categories and their questions are deleted for this activity.
 
 question_delete_context ($contextid)
 All question categories and their questions are deleted for this context id.
 
 question_delete_course ($course, $notused=false)
 All question categories and their questions are deleted for this course.
 
 question_delete_course_category ($category, $newcategory, $notused=false)
 Category is about to be deleted, 1/ All question categories and their questions are deleted for this course category.
 
 question_delete_question ($questionid)
 Deletes question and all associated data from the database.
 
 question_edit_url ($context)
 Gets the question edit url.
 
 question_extend_settings_navigation (navigation_node $navigationnode, $context, $baseurl='/question/edit.php')
 Adds question bank setting links to the given navigation node if caps are met and loads the navigation from the plugins.
 
 question_fix_top_names ($categories, $escape=true)
 Finds top categories in the given categories hierarchy and replace their name with a proper localised string.
 
 question_get_all_capabilities ()
 Get the question bank caps.
 
 question_get_default_category ($contextid)
 Get the default category for the context.
 
 question_get_export_single_question_url ($question)
 Get the URL to export a single question (exportone.php).
 
 question_get_question_capabilities ()
 Get the array of capabilities for question.
 
 question_get_top_categories_for_contexts ($contextids)
 Gets the list of top categories in the given contexts in the array("categoryid,categorycontextid") format.
 
 question_get_top_category ($contextid, $create=false)
 Gets the top category in the given context.
 
 question_has_capability_on ($questionorid, $cap, $notused=-1)
 Check capability on category.
 
 question_hash ($question)
 Creates a stamp that uniquely identifies this version of the question.
 
 question_load_questions ($questionids, $extrafields='', $join='')
 Load a set of questions, given a list of ids.
 
 question_make_default_categories ($contexts)
 Gets the default category in the most specific context.
 
 question_make_export_url ($contextid, $categoryid, $format, $withcategories, $withcontexts, $filename)
 Create url for question export.
 
 question_module_uses_questions ($modname)
 Does an activity module use the question bank?
 
 question_move_category_to_context ($categoryid, $oldcontextid, $newcontextid)
 This function helps move a question cateogry to a new context by moving all the files belonging to all the questions to the new context.
 
 question_move_question_tags_to_new_context (array $questions, context $newcontext)
 This function will handle moving all tag instances to a new context for a given list of questions.
 
 question_move_questions_to_category ($questionids, $newcategoryid)
 This function should be considered private to the question bank, it is called from question/editlib.php question/contextmoveq.php and a few similar places to to the work of actually moving questions and associated data.
 
 question_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 question_pluginfile ($course, $context, $component, $filearea, $args, $forcedownload, $options=[])
 Called by pluginfile.php to serve files related to the 'question' core component and for files belonging to qtypes.
 
 question_preload_questions ($questionids=null, $extrafields='', $join='', $extraparams=[], $orderby='')
 Given a list of ids, load the basic information about a set of questions from the questions table.
 
 question_preview_popup_params ()
 Popup params for the question preview.
 
 question_preview_url ($questionid, $preferredbehaviour=null, $maxmark=null, $displayoptions=null, $variant=null, $context=null)
 Generate the URL for starting a new preview of a given question with the given options.
 
 question_remove_stale_questions_from_category ($categoryid)
 Remove stale questions from a category.
 
 question_reorder_qtypes ($sortedqtypes, $tomove, $direction)
 Move one question type in a list of question types.
 
 question_require_capability_on ($question, $cap)
 Require capability on question.
 
 question_rewrite_question_preview_urls ($text, $questionid, $filecontextid, $filecomponent, $filearea, $itemid, $previewcontextid, $previewcomponent, $options=null)
 Rewrite the PLUGINFILE urls in part of the content of a question, for use when viewing the question outside an attempt (for example, in the question bank listing or in the quiz statistics report).
 
 question_rewrite_question_urls ($text, $file, $contextid, $component, $filearea, array $ids, $itemid, array $options=null)
 Helps call file_rewrite_pluginfile_urls with the right parameters.
 
 question_save_from_deletion ($questionids, $newcontextid, $oldplace, $newcategory=null)
 Creates a new category to save the questions in use.
 
 question_save_qtype_order ($neworder, $config=null)
 Save a new question type order to the config_plugins table.
 
 question_sort_tags ($tagobjects, $categorycontext, $filtercourses=null)
 Sort question tags by course or normal tags.
 
 questions_in_use ($questionids)
 Check if the question is used.
 
 sort_categories_by_tree (&$categories, $id=0, $level=1)
 Returns the categories with their names ordered following parent-child relationships.
 

Variables

const QUESTION_NUMANS 10
 Constant determines the number of answer boxes supplied in the editing form for multiple choice and similar question types.
 
const QUESTION_NUMANS_ADD 3
 Constant determines the number of answer boxes to add in the editing form for multiple choice and similar question types when the user presses 'add form fields button'.
 
const QUESTION_NUMANS_START 3
 Constant determines the number of answer boxes supplied in the editing form for multiple choice and similar question types to start with, with the option of adding QUESTION_NUMANS_ADD more answers.
 

Detailed Description

Function Documentation

◆ _tidy_question()

_tidy_question ( $question,
$category,
array $tagobjects = null,
array $filtercourses = null )

Private function to factor common code out of get_question_options().

Parameters
object$questionthe question to tidy.
stdClass$categoryThe question_categories record for the given $question.
core_tag_tag[] | null$tagobjectsThe tags for the given $question.
stdClass[] | null$filtercoursesThe courses to filter the course tags by.

◆ add_indented_names()

add_indented_names ( $categories,
$nochildrenof = -1 )

Format categories into an indented list reflecting the tree structure.

Parameters
array$categoriesAn array of category objects, for example from the.
int$nochildrenof
Return values
arrayThe formatted list of categories.
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ core_question_find_next_unused_idnumber()

core_question_find_next_unused_idnumber ( ?string $oldidnumber,
int $categoryid )

If $oldidnumber ends in some digits then return the next available idnumber of the same form.

So idnum -> null (no digits at the end) idnum0099 -> idnum0100 (if that is unused, else whichever of idnum0101, idnume0102, ... is unused. idnum9 -> idnum10.

Parameters
string | null$oldidnumbera question idnumber, or can be null.
int$categoryida question category id.
Return values
string|nullsuggested new idnumber for a question in that category, or null if one cannot be found.

◆ core_question_question_preview_pluginfile()

core_question_question_preview_pluginfile ( $previewcontext,
$questionid,
$filecontext,
$filecomponent,
$filearea,
$args,
$forcedownload,
$options = [] )

Serve questiontext files in the question text when they are displayed in this report.

Parameters
context$previewcontextthe context in which the preview is happening.
int$questionidthe question id.
context$filecontextthe file (question) context.
string$filecomponentthe component the file belongs to.
string$fileareathe file area.
array$argsremaining file args.
bool$forcedownload
array$optionsadditional options affecting the file serving.

◆ delete_question_bank_entry()

delete_question_bank_entry ( $entryid)

Check if there is more versions left for the entry.

If not delete the entry.

Parameters
int$entryid

◆ flatten_category_tree()

flatten_category_tree ( & $categories,
$id,
$depth = 0,
$nochildrenof = -1 )

Private method, only for the use of add_indented_names().

Recursively adds an indentedname field to each category, starting with the category with id $id, and dealing with that category and all its children, and return a new array, with those categories in the right order.

Parameters
array$categoriesan array of categories which has had childids fields added by flatten_category_tree(). Passed by reference for performance only. It is not modfied.
int$idthe category to start the indenting process from.
int$depththe indent depth. Used in recursive calls.
int$nochildrenof
Return values
arraya new array of categories, in the right order for the tree.
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ get_categories_for_contexts()

get_categories_for_contexts ( $contexts,
$sortorder = 'parent,
sortorder ,
name ASC' ,
$top = false )

Get all the category objects, including a count of the number of questions in that category, for all the categories in the lists $contexts.

Parameters
mixed$contextseither a single contextid, or a comma-separated list of context ids.
string$sortorderused as the ORDER BY clause in the select statement.
bool$topWhether to return the top categories or not.
Return values
arrayof category objects.
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ get_import_export_formats()

get_import_export_formats ( $type)

Get list of available import or export formats.

Parameters
string$type'import' if import list, otherwise export list assumed
Return values
arraysorted list of import/export formats available

◆ get_next_version()

get_next_version ( int $questionbankentryid)

Get the next version number to create base on a Question bank entry id.

Parameters
int$questionbankentryidQuestion bank entry id.
Return values
intnext version number.
Exceptions
dml_exception

◆ get_question_bank_entry()

get_question_bank_entry ( int $questionid)

Get the question_bank_entry object given a question id.

Parameters
int$questionidQuestion id.
Return values
false|mixed
Exceptions
dml_exception

◆ get_question_options()

get_question_options ( & $questions,
$loadtags = false,
$filtercourses = null )

Updates the question objects with question type specific information by calling {.

See also
get_question_options()}

Can be called either with an array of question objects or with a single question object.

Parameters
mixed$questionsEither an array of question objects to be updated or just a single question object
bool$loadtagsload the question tags from the tags table. Optional, default false.
stdClass[]$filtercoursesThe courses to filter the course tags by.
Return values
boolIndicates success or failure.

◆ get_question_version()

get_question_version ( $questionid)

Get the question versions given a question id in a descending sort .

Parameters
int$questionidQuestion id.
Return values
array
Exceptions
dml_exception

◆ idnumber_exist_in_question_category()

idnumber_exist_in_question_category ( $questionidnumber,
$categoryid,
$limitfrom = 0,
$limitnum = 1 )

Check if an idnumber exist in the category.

Parameters
int$questionidnumber
int$categoryid
int$limitfrom
int$limitnum
Return values
array

◆ is_latest()

is_latest ( string $version,
string $questionbankentryid )

Checks if question is the latest version.

Parameters
string$versionQuestion version to check.
string$questionbankentryidEntry to check against.
Return values
bool

◆ match_grade_options()

match_grade_options ( $gradeoptionsfull,
$grade,
$matchgrades = 'error' )

Check whether a given grade is one of a list of allowed options.

If not, depending on $matchgrades, either return the nearest match, or return false to signal an error.

Parameters
array$gradeoptionsfulllist of valid options
int$gradegrade to be tested
string$matchgrades'error' or 'nearest'
Return values
false|int|stringeither 'fixed' value or false if error.

◆ move_question_set_references()

move_question_set_references ( int $oldcategoryid,
int $newcatgoryid,
int $oldcontextid,
int $newcontextid,
bool $delete = false )

Update the questioncontextid field for all question_set_references records given a new context id.

Parameters
int$oldcategoryidOld category to be moved.
int$newcatgoryidNew category that will receive the questions.
int$oldcontextidOld context to be moved.
int$newcontextidNew context that will receive the questions.
bool$deleteIf the action is delete.
Exceptions
dml_exception

◆ print_question_icon()

print_question_icon ( $question)

Print the icon for the question type.

Parameters
object$questionThe question object for which the icon is required. Only $question->qtype is used.
Return values
stringthe HTML for the img tag.

◆ question_add_context_in_key()

question_add_context_in_key ( $categories)

Add context in categories key.

Parameters
array$categoriesThe list of categories.
Return values
array
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_category_delete_safe()

question_category_delete_safe ( $category)

Category is about to be deleted, 1/ All questions are deleted for this question category.

2/ Any questions that can't be deleted are moved to a new category NOTE: this function is called from lib/db/upgrade.php

Parameters
object | core_course_category$categorycourse category object

◆ question_category_in_use()

question_category_in_use ( $categoryid,
$recursive = false )

Tests whether any question in a category is used by any part of Moodle.

Parameters
integer$categoryida question category id.
boolean$recursivewhether to check child categories too.
Return values
booleanwhether any question in this category is in use.

◆ question_category_options()

question_category_options ( $contexts,
$top = false,
$currentcat = 0,
$popupform = false,
$nochildrenof = -1,
$escapecontextnames = true )

Output an array of question categories.

Parameters
array$contextsThe list of contexts.
bool$topWhether to return the top categories or not.
int$currentcat
bool$popupform
int$nochildrenof
boolean$escapecontextnamesWhether the returned name of the thing is to be HTML escaped or not.
Return values
array
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_category_select_menu()

question_category_select_menu ( $contexts,
$top = false,
$currentcat = 0,
$selected = "",
$nochildrenof = -1 )

Output a select menu of question categories.

Categories from this course and (optionally) published categories from other courses are included. Optionally, only categories the current user may edit can be included.

Parameters
array$contexts
bool$top
int$currentcat
integer$selectedoptionally, the id of a category to be selected by default in the dropdown.
int$nochildrenof
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_categorylist()

question_categorylist ( $categoryid)

Get the list of categories.

Parameters
int$categoryid
Return values
arrayof question category ids of the category and all subcategories.

◆ question_categorylist_parents()

question_categorylist_parents ( int $categoryid)

Get all parent categories of a given question category in descending order.

Parameters
int$categoryidfor which you want to find the parents.
Return values
arrayof question category ids of all parents categories.

◆ question_context_has_any_questions()

question_context_has_any_questions ( $context)

Determine whether there are any questions belonging to this context, that is whether any of its question categories contain any questions.

This will return true even if all the questions are hidden.

Parameters
mixed$contexteither a context object, or a context id.
Return values
booleanwhether any of the question categories beloning to this context have any questions in them.

◆ question_default_export_filename()

question_default_export_filename ( $course,
$category )

Create a reasonable default file name for exporting questions from a particular category.

Parameters
object$coursethe course the questions are in.
object$categorythe question category.
Return values
stringthe filename.

◆ question_delete_activity()

question_delete_activity ( $cm,
$notused = false )

All question categories and their questions are deleted for this activity.

Parameters
object$cmthe course module object representing the activity
bool$notusedthe argument is not used any more. Kept for backwards compatibility.
Return values
boolean

◆ question_delete_context()

question_delete_context ( $contextid)

All question categories and their questions are deleted for this context id.

Parameters
int$contextidThe contextid to delete question categories from
Return values
arrayonly returns an empty array for backwards compatibility.

◆ question_delete_course()

question_delete_course ( $course,
$notused = false )

All question categories and their questions are deleted for this course.

Parameters
stdClass$coursean object representing the activity
bool$notusedthis argument is not used any more. Kept for backwards compatibility.
Return values
boolalways true.

◆ question_delete_course_category()

question_delete_course_category ( $category,
$newcategory,
$notused = false )

Category is about to be deleted, 1/ All question categories and their questions are deleted for this course category.

2/ All questions are moved to new category

Parameters
stdClass | core_course_category$categorycourse category object
stdClass | core_course_category$newcategoryempty means everything deleted, otherwise id of category where content moved
bool$notusedthis argument is no longer used. Kept for backwards compatibility.
Return values
boolean

◆ question_delete_question()

question_delete_question ( $questionid)

Deletes question and all associated data from the database.

It will not delete a question if it is used somewhere, instead it will just delete the reference.

Parameters
int$questionidThe id of the question being deleted

◆ question_edit_url()

question_edit_url ( $context)

Gets the question edit url.

Parameters
object$contexta context
Return values
string|boolA URL for editing questions in this context.

◆ question_extend_settings_navigation()

question_extend_settings_navigation ( navigation_node $navigationnode,
$context,
$baseurl = '/question/edit.php' )

Adds question bank setting links to the given navigation node if caps are met and loads the navigation from the plugins.

Qbank plugins can extend the navigation_plugin_base and add their own navigation node, this method will help to autoload those nodes in the question bank navigation.

Parameters
navigation_node$navigationnodeThe navigation node to add the question branch to
object$context
string$baseurlthe url of the base where the api is implemented from
Return values
navigation_nodeReturns the question branch that was added

◆ question_fix_top_names()

question_fix_top_names ( $categories,
$escape = true )

Finds top categories in the given categories hierarchy and replace their name with a proper localised string.

Parameters
array$categoriesAn array of question categories.
boolean$escapeWhether the returned name of the thing is to be HTML escaped or not.
Return values
arrayThe same question category list given to the function, with the top category names being translated.
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_get_all_capabilities()

question_get_all_capabilities ( )

Get the question bank caps.

Return values
arrayall the question bank capabilities.

◆ question_get_default_category()

question_get_default_category ( $contextid)

Get the default category for the context.

Parameters
integer$contextida context id.
Return values
object|boolthe default question category for that context, or false if none.

◆ question_get_export_single_question_url()

question_get_export_single_question_url ( $question)

Get the URL to export a single question (exportone.php).

Parameters
stdClass | question_definition$questionthe question definition as obtained from question_bank\load_question_data() or question_bank\make_question(). (Only ->id and ->contextid are used.)
Return values
moodle_urlthe requested URL.
Deprecated
since Moodle 4.0
See also
qbank_exporttoxml\helper\question_get_export_single_question_url()
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_get_question_capabilities()

question_get_question_capabilities ( )

Get the array of capabilities for question.

Return values
arrayall the capabilities that relate to accessing particular questions.

◆ question_get_top_categories_for_contexts()

question_get_top_categories_for_contexts ( $contextids)

Gets the list of top categories in the given contexts in the array("categoryid,categorycontextid") format.

Parameters
array$contextidsList of context ids
Return values
array

◆ question_get_top_category()

question_get_top_category ( $contextid,
$create = false )

Gets the top category in the given context.

This function can optionally create the top category if it doesn't exist.

Parameters
int$contextidA context id.
bool$createWhether create a top category if it doesn't exist.
Return values
bool|stdClassThe top question category for that context, or false if none.

◆ question_has_capability_on()

question_has_capability_on ( $questionorid,
$cap,
$notused = -1 )

Check capability on category.

Parameters
int | stdClass | question_definition$questionoridobject or id. If an object is passed, it should include ->contextid and ->createdby.
string$cap'add', 'edit', 'view', 'use', 'move' or 'tag'.
int$notusedno longer used.
Return values
boolthis user has the capability $cap for this question $question?

◆ question_hash()

question_hash ( $question)

Creates a stamp that uniquely identifies this version of the question.

In future we want this to use a hash of the question data to guarantee that identical versions have the same version stamp.

Parameters
object$question
Return values
stringA unique version stamp
Deprecated
since Moodle 4.0
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_load_questions()

question_load_questions ( $questionids,
$extrafields = '',
$join = '' )

Load a set of questions, given a list of ids.

The $join and $extrafields arguments can be used together to pull in extra data. See, for example, the usage in mod/quiz/attempt.php, and read the code below to see how the SQL is assembled. Throws exceptions on error.

Parameters
array$questionidsarray of question ids.
string$extrafieldsextra SQL code to be added to the query.
string$joinextra SQL code to be added to the query.
Return values
array|stringquestion objects.

◆ question_make_default_categories()

question_make_default_categories ( $contexts)

Gets the default category in the most specific context.

If no categories exist yet then default ones are created in all contexts.

Parameters
array$contextsThe context objects for this context and all parent contexts.
Return values
objectThe default category - the category in the course context

◆ question_make_export_url()

question_make_export_url ( $contextid,
$categoryid,
$format,
$withcategories,
$withcontexts,
$filename )

Create url for question export.

Parameters
int$contextid
int$categoryid
string$format
string$withcategories
string$withcontexts
string$filename
Return values
moodle_urlexport file url
Deprecated
since Moodle 4.0 MDL-71573
See also
qbank_exportquestions\exportquestions_helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_module_uses_questions()

question_module_uses_questions ( $modname)

Does an activity module use the question bank?

Parameters
string$modnameThe name of the module (without mod_ prefix).
Return values
booltrue if the module uses questions.

◆ question_move_category_to_context()

question_move_category_to_context ( $categoryid,
$oldcontextid,
$newcontextid )

This function helps move a question cateogry to a new context by moving all the files belonging to all the questions to the new context.

Also moves subcategories.

Parameters
integer$categoryidthe id of the category being moved.
integer$oldcontextidthe old context id.
integer$newcontextidthe new context id.

◆ question_move_question_tags_to_new_context()

question_move_question_tags_to_new_context ( array $questions,
context $newcontext )

This function will handle moving all tag instances to a new context for a given list of questions.

Questions can be tagged in up to two contexts: 1.) The context the question exists in. 2.) The course context (if the question context is a higher context. E.g. course category context or system context.

This means a question that exists in a higher context (e.g. course cat or system context) may have multiple groups of tags in any number of child course contexts.

Questions in the course category context can be move "down" a context level into one of their child course contexts or activity contexts which affects the availability of that question in other courses / activities.

In this case it makes the questions no longer available in the other course or activity contexts so we need to make sure that the tag instances in those other contexts are removed.

Parameters
stdClass[]$questionsThe list of question being moved (must include the id and contextid)
context$newcontextThe Moodle context the questions are being moved to

◆ question_move_questions_to_category()

question_move_questions_to_category ( $questionids,
$newcategoryid )

This function should be considered private to the question bank, it is called from question/editlib.php question/contextmoveq.php and a few similar places to to the work of actually moving questions and associated data.

However, callers of this function also have to do other work, which is why you should not call this method directly from outside the questionbank.

Parameters
array$questionidsof question ids.
integer$newcategoryidthe id of the category to move to.
Return values
bool

◆ question_page_type_list()

question_page_type_list ( $pagetype,
$parentcontext,
$currentcontext )

Return a list of page types.

Parameters
string$pagetypecurrent page type
stdClass$parentcontextBlock's parent context
stdClass$currentcontextCurrent context of block
Return values
array

◆ question_pluginfile()

question_pluginfile ( $course,
$context,
$component,
$filearea,
$args,
$forcedownload,
$options = [] )

Called by pluginfile.php to serve files related to the 'question' core component and for files belonging to qtypes.

For files that relate to questions in a question_attempt, then we delegate to a function in the component that owns the attempt (for example in the quiz, or in core question preview) to get necessary inforation.

(Note that, at the moment, all question file areas relate to questions in attempts, so the If at the start of the last paragraph is always true.)

Does not return, either calls send_file_not_found(); or serves the file.

Parameters
stdClass$coursecourse settings object
stdClass$contextcontext object
string$componentthe name of the component we are serving files for.
string$fileareathe name of the file area.
array$argsthe remaining bits of the file path.
bool$forcedownloadwhether the user must be forced to download the file.
array$optionsadditional options affecting the file serving
Return values
array|bool

◆ question_preload_questions()

question_preload_questions ( $questionids = null,
$extrafields = '',
$join = '',
$extraparams = [],
$orderby = '' )

Given a list of ids, load the basic information about a set of questions from the questions table.

The $join and $extrafields arguments can be used together to pull in extra data. See, for example, the usage in {

See also
mod_quiz\quiz_attempt}, and read the code below to see how the SQL is assembled. Throws exceptions on error.
Parameters
array$questionidsarray of question ids to load. If null, then all questions matched by $join will be loaded.
string$extrafieldsextra SQL code to be added to the query.
string$joinextra SQL code to be added to the query.
array$extraparamsvalues for any placeholders in $join. You must use named placeholders.
string$orderbywhat to order the results by. Optional, default is unspecified order.
Return values
arraypartially complete question objects. You need to call get_question_options on them before they can be properly used.

◆ question_preview_popup_params()

question_preview_popup_params ( )

Popup params for the question preview.

Return values
arraythat can be passed as $params to the {
See also
popup_action()} constructor.
Deprecated
since Moodle 4.0
See also
qbank_previewquestion\previewquestion_helper\question_preview_popup_params()
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_preview_url()

question_preview_url ( $questionid,
$preferredbehaviour = null,
$maxmark = null,
$displayoptions = null,
$variant = null,
$context = null )

Generate the URL for starting a new preview of a given question with the given options.

Parameters
integer$questionidthe question to preview.
string$preferredbehaviourthe behaviour to use for the preview.
float$maxmarkthe maximum to mark the question out of.
question_display_options$displayoptionsthe display options to use.
int$variantthe variant of the question to preview. If null, one will be picked randomly.
object$contextcontext to run the preview in (affects things like filter settings, theme, lang, etc.) Defaults to $PAGE->context.
Return values
moodle_urlthe URL.
Deprecated
since Moodle 4.0
See also
qbank_previewquestion\helper\question_preview_url()
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_remove_stale_questions_from_category()

question_remove_stale_questions_from_category ( $categoryid)

Remove stale questions from a category.

While questions should not be left behind when they are not used any more, it does happen, maybe via restore, or old logic, or uncovered scenarios. When this happens, the users are unable to delete the question category unless they move those stale questions to another one category, but to them the category is empty as it does not contain anything. The purpose of this function is to detect the questions that may have gone stale and remove them.

You will typically use this prior to checking if the category contains questions.

The stale questions (unused and hidden to the user) handled are:

  • hidden questions
  • random questions
Parameters
int$categoryidThe category ID.
Deprecated
since Moodle 4.0 MDL-71585
See also
qbank_managecategories\helper
Todo
Final deprecation on Moodle 4.4 MDL-72438

◆ question_reorder_qtypes()

question_reorder_qtypes ( $sortedqtypes,
$tomove,
$direction )

Move one question type in a list of question types.

If you try to move one element off of the end, nothing will change.

Parameters
array$sortedqtypesAn array $qtype => anything.
string$tomoveone of the keys from $sortedqtypes
integer$direction+1 or -1
Return values
arrayan array $index => $qtype, with $index from 0 to n in order, and the $qtypes in the same order as $sortedqtypes, except that $tomove will have been moved one place.

◆ question_require_capability_on()

question_require_capability_on ( $question,
$cap )

Require capability on question.

Parameters
int | stdClass | question_definition$questionobject or id. If an object is passed, it should include ->contextid and ->createdby.
string$cap'add', 'edit', 'view', 'use', 'move' or 'tag'.
Return values
booltrue if the user has the capability. Throws exception if not.

◆ question_rewrite_question_preview_urls()

question_rewrite_question_preview_urls ( $text,
$questionid,
$filecontextid,
$filecomponent,
$filearea,
$itemid,
$previewcontextid,
$previewcomponent,
$options = null )

Rewrite the PLUGINFILE urls in part of the content of a question, for use when viewing the question outside an attempt (for example, in the question bank listing or in the quiz statistics report).

Parameters
string$textthe question text.
int$questionidthe question id.
int$filecontextidthe context id of the question being displayed.
string$filecomponentthe component that owns the file area.
string$fileareathe file area name.
int | null$itemidthe file's itemid
int$previewcontextidthe context id where the preview is being displayed.
string$previewcomponentcomponent responsible for displaying the preview.
array$optionstext and file options ('forcehttps'=>false)
Return values
string\$questiontextwith URLs rewritten.

◆ question_rewrite_question_urls()

question_rewrite_question_urls ( $text,
$file,
$contextid,
$component,
$filearea,
array $ids,
$itemid,
array $options = null )

Helps call file_rewrite_pluginfile_urls with the right parameters.

Parameters
string$texttext being processed
string$filethe php script used to serve files
int$contextidcontext ID
string$componentcomponent
string$fileareafilearea
array$idsother IDs will be used to check file permission
int$itemiditem ID
array$optionsoptions
Return values
string

◆ question_save_from_deletion()

question_save_from_deletion ( $questionids,
$newcontextid,
$oldplace,
$newcategory = null )

Creates a new category to save the questions in use.

Parameters
array$questionidsof question ids
object$newcontextidthe context to create the saved category in.
string$oldplacea textual description of the think being deleted, e.g. from get_context_name
object$newcategory
Return values
mixedfalse on

◆ question_save_qtype_order()

question_save_qtype_order ( $neworder,
$config = null )

Save a new question type order to the config_plugins table.

Parameters
array$neworderAn arra $index => $qtype. Indices should start at 0 and be in order.
object$configget_config('question'), if you happen to have it around, to save one DB query.

◆ question_sort_tags()

question_sort_tags ( $tagobjects,
$categorycontext,
$filtercourses = null )

Sort question tags by course or normal tags.

This function also search tag instances that may have a context id that don't match either a course or question context and fix the data setting the correct context id.

Parameters
core_tag_tag[]$tagobjectsThe tags for the given $question.
stdClass$categorycontextThe question categories context.
stdClass[] | null$filtercoursesThe courses to filter the course tags by.
Return values
stdClass\$sortedtagobjectsSorted tag objects.

◆ questions_in_use()

questions_in_use ( $questionids)

Check if the question is used.

Parameters
array$questionidsof question ids.
Return values
booleanwhether any of these questions are being used by any part of Moodle.

◆ sort_categories_by_tree()

sort_categories_by_tree ( & $categories,
$id = 0,
$level = 1 )

Returns the categories with their names ordered following parent-child relationships.

finally it tries to return pending categories (those being orphaned, whose parent is incorrect) to avoid missing any category from original array.

Parameters
array$categories
int$id
int$level
Return values
array