Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
|
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. | |
_tidy_question | ( | $question, | |
$category, | |||
array | $tagobjects = null, | ||
array | $filtercourses = null ) |
Private function to factor common code out of get_question_options().
object | $question | the question to tidy. |
stdClass | $category | The question_categories record for the given $question. |
core_tag_tag[] | null | $tagobjects | The tags for the given $question. |
stdClass[] | null | $filtercourses | The courses to filter the course tags by. |
add_indented_names | ( | $categories, | |
$nochildrenof = -1 ) |
Format categories into an indented list reflecting the tree structure.
array | $categories | An array of category objects, for example from the. |
int | $nochildrenof |
array | The formatted list of categories. |
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.
string | null | $oldidnumber | a question idnumber, or can be null. |
int | $categoryid | a question category id. |
string|null | suggested new idnumber for a question in that category, or null if one cannot be found. |
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.
context | $previewcontext | the context in which the preview is happening. |
int | $questionid | the question id. |
context | $filecontext | the file (question) context. |
string | $filecomponent | the component the file belongs to. |
string | $filearea | the file area. |
array | $args | remaining file args. |
bool | $forcedownload | |
array | $options | additional options affecting the file serving. |
delete_question_bank_entry | ( | $entryid | ) |
Check if there is more versions left for the entry.
If not delete the entry.
int | $entryid |
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.
array | $categories | an array of categories which has had childids fields added by flatten_category_tree(). Passed by reference for performance only. It is not modfied. |
int | $id | the category to start the indenting process from. |
int | $depth | the indent depth. Used in recursive calls. |
int | $nochildrenof |
array | a new array of categories, in the right order for the tree. |
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.
mixed | $contexts | either a single contextid, or a comma-separated list of context ids. |
string | $sortorder | used as the ORDER BY clause in the select statement. |
bool | $top | Whether to return the top categories or not. |
array | of category objects. |
get_import_export_formats | ( | $type | ) |
Get list of available import or export formats.
string | $type | 'import' if import list, otherwise export list assumed |
array | sorted list of import/export formats available |
get_next_version | ( | int | $questionbankentryid | ) |
Get the next version number to create base on a Question bank entry id.
int | $questionbankentryid | Question bank entry id. |
int | next version number. |
dml_exception |
get_question_bank_entry | ( | int | $questionid | ) |
Get the question_bank_entry object given a question id.
int | $questionid | Question id. |
false|mixed |
dml_exception |
get_question_options | ( | & | $questions, |
$loadtags = false, | |||
$filtercourses = null ) |
Updates the question objects with question type specific information by calling {.
Can be called either with an array of question objects or with a single question object.
mixed | $questions | Either an array of question objects to be updated or just a single question object |
bool | $loadtags | load the question tags from the tags table. Optional, default false. |
stdClass[] | $filtercourses | The courses to filter the course tags by. |
bool | Indicates success or failure. |
get_question_version | ( | $questionid | ) |
Get the question versions given a question id in a descending sort .
int | $questionid | Question id. |
array |
dml_exception |
idnumber_exist_in_question_category | ( | $questionidnumber, | |
$categoryid, | |||
$limitfrom = 0, | |||
$limitnum = 1 ) |
Check if an idnumber exist in the category.
int | $questionidnumber | |
int | $categoryid | |
int | $limitfrom | |
int | $limitnum |
array |
is_latest | ( | string | $version, |
string | $questionbankentryid ) |
Checks if question is the latest version.
string | $version | Question version to check. |
string | $questionbankentryid | Entry to check against. |
bool |
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.
array | $gradeoptionsfull | list of valid options |
int | $grade | grade to be tested |
string | $matchgrades | 'error' or 'nearest' |
false|int|string | either 'fixed' value or false if error. |
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.
int | $oldcategoryid | Old category to be moved. |
int | $newcatgoryid | New category that will receive the questions. |
int | $oldcontextid | Old context to be moved. |
int | $newcontextid | New context that will receive the questions. |
bool | $delete | If the action is delete. |
dml_exception |
print_question_icon | ( | $question | ) |
Print the icon for the question type.
object | $question | The question object for which the icon is required. Only $question->qtype is used. |
string | the HTML for the img tag. |
question_add_context_in_key | ( | $categories | ) |
Add context in categories key.
array | $categories | The list of categories. |
array |
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
object | core_course_category | $category | course category object |
question_category_in_use | ( | $categoryid, | |
$recursive = false ) |
Tests whether any question in a category is used by any part of Moodle.
integer | $categoryid | a question category id. |
boolean | $recursive | whether to check child categories too. |
boolean | whether any question in this category is in use. |
question_category_options | ( | $contexts, | |
$top = false, | |||
$currentcat = 0, | |||
$popupform = false, | |||
$nochildrenof = -1, | |||
$escapecontextnames = true ) |
Output an array of question categories.
array | $contexts | The list of contexts. |
bool | $top | Whether to return the top categories or not. |
int | $currentcat | |
bool | $popupform | |
int | $nochildrenof | |
boolean | $escapecontextnames | Whether the returned name of the thing is to be HTML escaped or not. |
array |
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.
array | $contexts | |
bool | $top | |
int | $currentcat | |
integer | $selected | optionally, the id of a category to be selected by default in the dropdown. |
int | $nochildrenof |
question_categorylist | ( | $categoryid | ) |
Get the list of categories.
int | $categoryid |
array | of question category ids of the category and all subcategories. |
question_categorylist_parents | ( | int | $categoryid | ) |
Get all parent categories of a given question category in descending order.
int | $categoryid | for which you want to find the parents. |
array | of question category ids of all parents categories. |
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.
mixed | $context | either a context object, or a context id. |
boolean | whether any of the question categories beloning to this context have any questions in them. |
question_default_export_filename | ( | $course, | |
$category ) |
Create a reasonable default file name for exporting questions from a particular category.
object | $course | the course the questions are in. |
object | $category | the question category. |
string | the filename. |
question_delete_activity | ( | $cm, | |
$notused = false ) |
All question categories and their questions are deleted for this activity.
object | $cm | the course module object representing the activity |
bool | $notused | the argument is not used any more. Kept for backwards compatibility. |
boolean |
question_delete_context | ( | $contextid | ) |
All question categories and their questions are deleted for this context id.
int | $contextid | The contextid to delete question categories from |
array | only returns an empty array for backwards compatibility. |
question_delete_course | ( | $course, | |
$notused = false ) |
All question categories and their questions are deleted for this course.
stdClass | $course | an object representing the activity |
bool | $notused | this argument is not used any more. Kept for backwards compatibility. |
bool | always true. |
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
stdClass | core_course_category | $category | course category object |
stdClass | core_course_category | $newcategory | empty means everything deleted, otherwise id of category where content moved |
bool | $notused | this argument is no longer used. Kept for backwards compatibility. |
boolean |
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.
int | $questionid | The id of the question being deleted |
question_edit_url | ( | $context | ) |
Gets the question edit url.
object | $context | a context |
string|bool | A URL for editing questions in this context. |
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.
navigation_node | $navigationnode | The navigation node to add the question branch to |
object | $context | |
string | $baseurl | the url of the base where the api is implemented from |
navigation_node | Returns the question branch that was added |
question_fix_top_names | ( | $categories, | |
$escape = true ) |
Finds top categories in the given categories hierarchy and replace their name with a proper localised string.
array | $categories | An array of question categories. |
boolean | $escape | Whether the returned name of the thing is to be HTML escaped or not. |
array | The same question category list given to the function, with the top category names being translated. |
question_get_all_capabilities | ( | ) |
Get the question bank caps.
array | all the question bank capabilities. |
question_get_default_category | ( | $contextid | ) |
Get the default category for the context.
integer | $contextid | a context id. |
object|bool | the default question category for that context, or false if none. |
question_get_export_single_question_url | ( | $question | ) |
Get the URL to export a single question (exportone.php).
stdClass | question_definition | $question | the question definition as obtained from question_bank\load_question_data() or question_bank\make_question(). (Only ->id and ->contextid are used.) |
moodle_url | the requested URL. |
question_get_question_capabilities | ( | ) |
Get the array of capabilities for question.
array | all the capabilities that relate to accessing particular questions. |
question_get_top_categories_for_contexts | ( | $contextids | ) |
Gets the list of top categories in the given contexts in the array("categoryid,categorycontextid") format.
array | $contextids | List of context ids |
array |
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.
int | $contextid | A context id. |
bool | $create | Whether create a top category if it doesn't exist. |
bool|stdClass | The top question category for that context, or false if none. |
question_has_capability_on | ( | $questionorid, | |
$cap, | |||
$notused = -1 ) |
Check capability on category.
int | stdClass | question_definition | $questionorid | object or id. If an object is passed, it should include ->contextid and ->createdby. |
string | $cap | 'add', 'edit', 'view', 'use', 'move' or 'tag'. |
int | $notused | no longer used. |
bool | this user has the capability $cap for this question $question? |
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.
object | $question |
string | A unique version stamp |
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.
array | $questionids | array of question ids. |
string | $extrafields | extra SQL code to be added to the query. |
string | $join | extra SQL code to be added to the query. |
array|string | question objects. |
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.
array | $contexts | The context objects for this context and all parent contexts. |
object | The default category - the category in the course context |
question_make_export_url | ( | $contextid, | |
$categoryid, | |||
$format, | |||
$withcategories, | |||
$withcontexts, | |||
$filename ) |
Create url for question export.
int | $contextid | |
int | $categoryid | |
string | $format | |
string | $withcategories | |
string | $withcontexts | |
string | $filename |
moodle_url | export file url |
question_module_uses_questions | ( | $modname | ) |
Does an activity module use the question bank?
string | $modname | The name of the module (without mod_ prefix). |
bool | true if the module uses questions. |
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.
integer | $categoryid | the id of the category being moved. |
integer | $oldcontextid | the old context id. |
integer | $newcontextid | the new context id. |
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.
stdClass[] | $questions | The list of question being moved (must include the id and contextid) |
context | $newcontext | The Moodle context the questions are being moved to |
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.
array | $questionids | of question ids. |
integer | $newcategoryid | the id of the category to move to. |
bool |
question_page_type_list | ( | $pagetype, | |
$parentcontext, | |||
$currentcontext ) |
Return a list of page types.
string | $pagetype | current page type |
stdClass | $parentcontext | Block's parent context |
stdClass | $currentcontext | Current context of block |
array |
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.
stdClass | $course | course settings object |
stdClass | $context | context object |
string | $component | the name of the component we are serving files for. |
string | $filearea | the name of the file area. |
array | $args | the remaining bits of the file path. |
bool | $forcedownload | whether the user must be forced to download the file. |
array | $options | additional options affecting the file serving |
array|bool |
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 {
array | $questionids | array of question ids to load. If null, then all questions matched by $join will be loaded. |
string | $extrafields | extra SQL code to be added to the query. |
string | $join | extra SQL code to be added to the query. |
array | $extraparams | values for any placeholders in $join. You must use named placeholders. |
string | $orderby | what to order the results by. Optional, default is unspecified order. |
array | partially complete question objects. You need to call get_question_options on them before they can be properly used. |
question_preview_popup_params | ( | ) |
Popup params for the question preview.
array | that can be passed as $params to the { |
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.
integer | $questionid | the question to preview. |
string | $preferredbehaviour | the behaviour to use for the preview. |
float | $maxmark | the maximum to mark the question out of. |
question_display_options | $displayoptions | the display options to use. |
int | $variant | the variant of the question to preview. If null, one will be picked randomly. |
object | $context | context to run the preview in (affects things like filter settings, theme, lang, etc.) Defaults to $PAGE->context. |
moodle_url | the URL. |
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:
int | $categoryid | The category ID. |
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.
array | $sortedqtypes | An array $qtype => anything. |
string | $tomove | one of the keys from $sortedqtypes |
integer | $direction | +1 or -1 |
array | an 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, | |
$cap ) |
Require capability on question.
int | stdClass | question_definition | $question | object or id. If an object is passed, it should include ->contextid and ->createdby. |
string | $cap | 'add', 'edit', 'view', 'use', 'move' or 'tag'. |
bool | true if the user has the capability. Throws exception if not. |
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).
string | $text | the question text. |
int | $questionid | the question id. |
int | $filecontextid | the context id of the question being displayed. |
string | $filecomponent | the component that owns the file area. |
string | $filearea | the file area name. |
int | null | $itemid | the file's itemid |
int | $previewcontextid | the context id where the preview is being displayed. |
string | $previewcomponent | component responsible for displaying the preview. |
array | $options | text and file options ('forcehttps'=>false) |
string\$questiontext | with URLs rewritten. |
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.
string | $text | text being processed |
string | $file | the php script used to serve files |
int | $contextid | context ID |
string | $component | component |
string | $filearea | filearea |
array | $ids | other IDs will be used to check file permission |
int | $itemid | item ID |
array | $options | options |
string |
question_save_from_deletion | ( | $questionids, | |
$newcontextid, | |||
$oldplace, | |||
$newcategory = null ) |
Creates a new category to save the questions in use.
array | $questionids | of question ids |
object | $newcontextid | the context to create the saved category in. |
string | $oldplace | a textual description of the think being deleted, e.g. from get_context_name |
object | $newcategory |
mixed | false on |
question_save_qtype_order | ( | $neworder, | |
$config = null ) |
Save a new question type order to the config_plugins table.
array | $neworder | An arra $index => $qtype. Indices should start at 0 and be in order. |
object | $config | get_config('question'), if you happen to have it around, to save one DB query. |
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.
core_tag_tag[] | $tagobjects | The tags for the given $question. |
stdClass | $categorycontext | The question categories context. |
stdClass[] | null | $filtercourses | The courses to filter the course tags by. |
stdClass\$sortedtagobjects | Sorted tag objects. |
questions_in_use | ( | $questionids | ) |
Check if the question is used.
array | $questionids | of question ids. |
boolean | whether any of these questions are being used by any part of Moodle. |
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.
array | $categories | |
int | $id | |
int | $level |
array |