Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Classes | Functions | Variables
questionlib.php File Reference

Code for handling and processing questions. More...

Classes

class  context_to_string_translator
 Converts contextlevels to strings and back to help with reading/writing contexts to/from import/export files. More...
 
class  question_edit_contexts
 Tracks all the contexts related to the one where we are currently editing questions, and provides helper methods to check permissions. More...
 

Functions

 _tidy_question ($question, $category, array $tagobjects=null, array $filtercourses=null)
 Private function to factor common code out of get_question_options(). More...
 
 add_indented_names ($categories, $nochildrenof=-1)
 Format categories into an indented list reflecting the tree structure. More...
 
 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. More...
 
 core_question_question_preview_pluginfile ($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options=array())
 
 flatten_category_tree (&$categories, $id, $depth=0, $nochildrenof=-1)
 Private method, only for the use of add_indented_names(). More...
 
 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. More...
 
 get_import_export_formats ($type)
 Get list of available import or export formats. More...
 
 get_question_options (&$questions, $loadtags=false, $filtercourses=null)
 Updates the question objects with question type specific information by calling get_question_options(). More...
 
 match_grade_options ($gradeoptionsfull, $grade, $matchgrades='error')
 Check whether a given grade is one of a list of allowed options. More...
 
 print_question_icon ($question)
 Print the icon for the question type. More...
 
 question_add_context_in_key ($categories)
 
 question_category_delete_safe ($category)
 Category is about to be deleted, 1/ All questions are deleted for this question category. More...
 
 question_category_in_use ($categoryid, $recursive=false)
 Tests whether any question in a category is used by any part of Moodle. More...
 
 question_category_options ($contexts, $top=false, $currentcat=0, $popupform=false, $nochildrenof=-1, $escapecontextnames=true)
 Output an array of question categories. More...
 
 question_category_select_menu ($contexts, $top=false, $currentcat=0, $selected="", $nochildrenof=-1)
 Output a select menu of question categories. More...
 
 question_categorylist ($categoryid)
 
 question_categorylist_parents (int $categoryid)
 Get all parent categories of a given question category in decending order. More...
 
 question_context_has_any_questions ($context)
 Determine whether there arey any questions belonging to this context, that is whether any of its question categories contain any questions. More...
 
 question_default_export_filename ($course, $category)
 Create a reasonable default file name for exporting questions from a particular category. More...
 
 question_delete_activity ($cm, $notused=false)
 All question categories and their questions are deleted for this activity. More...
 
 question_delete_context ($contextid)
 All question categories and their questions are deleted for this context id. More...
 
 question_delete_course ($course, $notused=false)
 All question categories and their questions are deleted for this course. More...
 
 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. More...
 
 question_delete_question ($questionid)
 Deletes question and all associated data from the database. More...
 
 question_edit_url ($context)
 
 question_extend_settings_navigation (navigation_node $navigationnode, $context)
 Adds question bank setting links to the given navigation node if caps are met. More...
 
 question_fix_top_names ($categories, $escape=true)
 Finds top categories in the given categories hierarchy and replace their name with a proper localised string. More...
 
 question_get_all_capabilities ()
 
 question_get_default_category ($contextid)
 
 question_get_export_single_question_url ($question)
 Get the URL to export a single question (exportone.php). More...
 
 question_get_question_capabilities ()
 
 question_get_top_categories_for_contexts ($contextids)
 Gets the list of top categories in the given contexts in the array("categoryid,categorycontextid") format. More...
 
 question_get_top_category ($contextid, $create=false)
 Gets the top category in the given context. More...
 
 question_has_capability_on ($questionorid, $cap, $notused=-1)
 Check capability on category. More...
 
 question_hash ($question)
 Creates a stamp that uniquely identifies this version of the question. More...
 
 question_load_questions ($questionids, $extrafields='', $join='')
 Load a set of questions, given a list of ids. More...
 
 question_make_default_categories ($contexts)
 Gets the default category in the most specific context. More...
 
 question_make_export_url ($contextid, $categoryid, $format, $withcategories, $withcontexts, $filename)
 Create url for question export. More...
 
 question_module_uses_questions ($modname)
 Does an activity module use the question bank? More...
 
 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. More...
 
 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. More...
 
 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. More...
 
 question_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types. More...
 
 question_pluginfile ($course, $context, $component, $filearea, $args, $forcedownload, array $options=array())
 
 question_preload_questions ($questionids=null, $extrafields='', $join='', $extraparams=array(), $orderby='')
 Given a list of ids, load the basic information about a set of questions from the questions table. More...
 
 question_preview_popup_params ()
 
 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. More...
 
 question_remove_stale_questions_from_category ($categoryid)
 Remove stale questions from a category. More...
 
 question_reorder_qtypes ($sortedqtypes, $tomove, $direction)
 Move one question type in a list of question types. More...
 
 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). More...
 
 question_rewrite_question_urls ($text, $file, $contextid, $component, $filearea, array $ids, $itemid, array $options=null)
 
 question_save_from_deletion ($questionids, $newcontextid, $oldplace, $newcategory=null)
 Enter description here... More...
 
object question_save_qtype_order ($neworder, $config=null)
 Save a new question type order to the config_plugins table. More...
 
 question_sort_tags ($tagobjects, $categorycontext, $filtercourses=null)
 Sort question tags by course or normal tags. More...
 
 questions_in_use ($questionids)
 FUNCTIONS //////////////////////////////////////////////////////. More...
 
 sort_categories_by_tree (&$categories, $id=0, $level=1)
 CATEGORY FUNCTIONS /////////////////////////////////////////////////////////////////. More...
 

Variables

const QUESTION_NUMANS 10
 CONSTANTS ///////////////////////////////////. More...
 
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

Code for handling and processing questions.

This is code that is module independent, i.e., can be used by any module that uses questions, like quiz, lesson, .. This script also loads the questiontype classes Code for handling the editing of questions is in question/editlib.php

TODO: separate those functions which form part of the API from the helper functions.

@subpackage questionbank

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later