Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/questionlib.php File Reference

Go to the source code of this file.

Data Structures

class  context_to_string_translator
class  question_edit_contexts

Namespaces

namespace  moodlecore

Enumerations

enum  QUESTION_NUMANS
 CONSTANTS ///////////////////////////////////. More...
enum  QUESTION_NUMANS_START
enum  QUESTION_NUMANS_ADD

Functions

 question_reorder_qtypes ($sortedqtypes, $tomove, $direction)
 question_save_qtype_order ($neworder, $config=null)
 question_list_instances ($questionid)
 FUNCTIONS //////////////////////////////////////////////////////.
 questions_in_use ($questionids)
 question_context_has_any_questions ($context)
 get_grade_options ()
 match_grade_options ($gradeoptionsfull, $grade, $matchgrades='error')
 question_category_isused ($categoryid, $recursive=false)
 question_category_in_use ($categoryid, $recursive=false)
 question_delete_question ($questionid)
 question_delete_course ($course, $feedback=true)
 question_delete_course_category ($category, $newcategory, $feedback=true)
 question_save_from_deletion ($questionids, $newcontextid, $oldplace, $newcategory=null)
 question_delete_activity ($cm, $feedback=true)
 question_move_questions_to_category ($questionids, $newcategoryid)
 question_move_category_to_context ($categoryid, $oldcontextid, $newcontextid)
 question_preview_url ($questionid, $preferredbehaviour=null, $maxmark=null, $displayoptions=null, $variant=null, $context=null)
 question_preview_popup_params ()
 question_preload_questions ($questionids, $extrafields= '', $join= '', $extraparams=array())
 question_load_questions ($questionids, $extrafields= '', $join= '')
 _tidy_question ($question, $loadtags=false)
 get_question_options (&$questions, $loadtags=false)
 print_question_icon ($question)
 question_hash ($question)
 save_question_options ($question)
 FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////.
 sort_categories_by_tree (&$categories, $id=0, $level=1)
 CATEGORY FUNCTIONS /////////////////////////////////////////////////////////////////.
 flatten_category_tree (&$categories, $id, $depth=0, $nochildrenof=-1)
 add_indented_names ($categories, $nochildrenof=-1)
 question_category_select_menu ($contexts, $top=false, $currentcat=0, $selected="", $nochildrenof=-1)
 question_get_default_category ($contextid)
 question_make_default_categories ($contexts)
 get_categories_for_contexts ($contexts, $sortorder= 'parent, sortorder, name ASC')
 question_category_options ($contexts, $top=false, $currentcat=0, $popupform=false, $nochildrenof=-1)
 question_add_context_in_key ($categories)
 question_add_tops ($categories, $pcontexts)
 question_categorylist ($categoryid)
 get_import_export_formats ($type)
 question_default_export_filename ($course, $category)
 question_has_capability_on ($question, $cap, $cachecat=-1)
 question_require_capability_on ($question, $cap)
 question_get_real_state ($state)
 question_edit_url ($context)
 question_extend_settings_navigation (navigation_node $navigationnode, $context)
 question_get_question_capabilities ()
 question_get_all_capabilities ()
 question_rewrite_question_urls ($text, $file, $contextid, $component, $filearea, array $ids, $itemid, array $options=null)
 question_rewrite_questiontext_preview_urls ($questiontext, $contextid, $component, $questionid, $options=null)
 question_send_questiontext_file ($questionid, $args, $forcedownload)
 question_pluginfile ($course, $context, $component, $filearea, $args, $forcedownload)
 core_question_questiontext_preview_pluginfile ($context, $questionid, $args, $forcedownload)
 question_make_export_url ($contextid, $categoryid, $format, $withcategories, $withcontexts, $filename)
 question_page_type_list ($pagetype, $parentcontext, $currentcontext)

Enumeration Type Documentation

CONSTANTS ///////////////////////////////////.

Constant determines the number of answer boxes supplied in the editing form for multiple choice and similar question types.

Definition at line 48 of file questionlib.php.

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

Definition at line 62 of file questionlib.php.

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.

Definition at line 55 of file questionlib.php.


Function Documentation

_tidy_question ( question,
loadtags = false 
)

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

Parameters:
object$questionthe question to tidy.
boolean$loadtagsload the question tags from the tags table. Optional, default false.

Definition at line 781 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.
Returns:
array The formatted list of categories.

Definition at line 937 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

core_question_questiontext_preview_pluginfile ( context,
questionid,
args,
forcedownload 
)

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

Parameters:
context$contextthe context
int$questionidthe question id
array$argsremaining file args
bool$forcedownload

Definition at line 1848 of file questionlib.php.

Here is the call graph for this function:

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.
Returns:
array a new array of categories, in the right order for the tree.

Definition at line 909 of file questionlib.php.

Here is the caller graph for this function:

get_categories_for_contexts ( contexts,
sortorder = 'parent,
sortorder  ,
name ASC'   
)

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.
Returns:
array of category objects.

Definition at line 1071 of file questionlib.php.

Here is the caller graph for this function:

Returns list of 'allowed' grades for grade selection formatted suitably for dropdown box function

Deprecated:
since 2.1. Use question_bank::fraction_options() or question_bank::fraction_options_full() instead.
Returns:
object ->gradeoptionsfull full array ->gradeoptions +ve only

Definition at line 203 of file questionlib.php.

Here is the call graph for this function:

Get list of available import or export formats

Parameters:
string$type'import' if import list, otherwise export list assumed
Returns:
array sorted list of import/export formats available

Definition at line 1184 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_question_options ( &$  questions,
loadtags = false 
)

Updates the question objects with question type specific information by calling 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
boolean$loadtagsload the question tags from the tags table. Optional, default false.
Returns:
bool Indicates success or failure.

Definition at line 809 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

match grade options if no match return error or match nearest

Parameters:
array$gradeoptionsfulllist of valid options
int$gradegrade to be tested
string$matchgrades'error' or 'nearest'
Returns:
mixed either 'fixed' value or false if erro

Definition at line 219 of file questionlib.php.

Here is the caller graph for this function:

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.
Returns:
string the HTML for the img tag.

Definition at line 827 of file questionlib.php.

Here is the caller graph for this function:

question_add_context_in_key ( categories)

Definition at line 1134 of file questionlib.php.

Here is the caller graph for this function:

question_add_tops ( categories,
pcontexts 
)

Definition at line 1144 of file questionlib.php.

Here is the caller graph for this function:

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.
Returns:
boolean whether any question in this category is in use.

Definition at line 266 of file questionlib.php.

Here is the call graph for this function:

question_category_isused ( categoryid,
recursive = false 
)
Deprecated:
Since Moodle 2.1. Use question_category_in_use instead.
Parameters:
integer$categoryida question category id.
boolean$recursivewhether to check child categories too.
Returns:
boolean whether any question in this category is in use.

Definition at line 254 of file questionlib.php.

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

Output an array of question categories.

Definition at line 1084 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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:
integer$courseidthe id of the course to get the categories for.
integer$publishedif true, include publised categories from other courses.
integer$only_editableif true, exclude categories this user is not allowed to edit.
integer$selectedoptionally, the id of a category to be selected by default in the dropdown.

Definition at line 981 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_categorylist ( categoryid)
Returns:
array of question category ids of the category and all subcategories.

Definition at line 1161 of file questionlib.php.

Here is the caller graph for this function:

Determine whether there arey 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.
Returns:
boolean whether any of the question categories beloning to this context have any questions in them.

Definition at line 179 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.
Returns:
string the filename.

Definition at line 1218 of file questionlib.php.

Here is the call graph for this function:

question_delete_activity ( cm,
feedback = true 
)

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

Parameters:
object$cmthe course module object representing the activity
boolean$feedbackto specify if the process must output a summary of its work
Returns:
boolean

Definition at line 524 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_delete_course ( course,
feedback = true 
)

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

Parameters:
stdClass$coursean object representing the activity
boolean$feedbackto specify if the process must output a summary of its work
Returns:
boolean

Definition at line 350 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_delete_course_category ( category,
newcategory,
feedback = true 
)

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:
object$categorycourse category object
object$newcategoryempty means everything deleted, otherwise id of category where content moved
boolean$feedbackto specify if the process must output a summary of its work
Returns:
boolean

Definition at line 407 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_delete_question ( questionid)

Deletes question and all associated data from the database

It will not delete a question if it is used by an activity module

Parameters:
object$questionThe question being deleted

Definition at line 299 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_edit_url ( context)
Parameters:
object$contexta context
Returns:
string A URL for editing questions in this context.

Definition at line 1386 of file questionlib.php.

Here is the call graph for this function:

question_extend_settings_navigation ( navigation_node navigationnode,
context 
)

Adds question bank setting links to the given navigation node if caps are met.

Parameters:
navigation_node$navigationnodeThe navigation node to add the question branch to
object$context
Returns:
navigation_node Returns the question branch that was added

Definition at line 1418 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
array all the question bank capabilities.

Definition at line 1477 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Parameters:
integer$contextida context id.
Returns:
object the default question category for that context, or false if none.

Definition at line 1003 of file questionlib.php.

Here is the caller graph for this function:

Returns:
array all the capabilities that relate to accessing particular questions.

Definition at line 1460 of file questionlib.php.

Here is the caller graph for this function:

Get the real state - the correct question id and answer - for a random question.

Parameters:
object$statewith property answer.
Returns:
mixed return integer real question id or false if there was an error..

Definition at line 1368 of file questionlib.php.

question_has_capability_on ( question,
cap,
cachecat = -1 
)

Check capability on category

Parameters:
mixed$questionobject or id
string$cap'add', 'edit', 'view', 'use', 'move'
integer$cachecatuseful to cache all question records in a category
Returns:
boolean this user has the capability $cap for this question $question?

Definition at line 1299 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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
Returns:
string A unique version stamp

Definition at line 841 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_list_instances ( questionid)

FUNCTIONS //////////////////////////////////////////////////////.

Returns an array of names of activity modules that use this question

Deprecated:
since Moodle 2.1. Use questions_in_use instead.
Parameters:
object$questionid
Returns:
array of strings

Definition at line 125 of file questionlib.php.

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.
array$extraparamsvalues for any placeholders in $join. You are strongly recommended to use named placeholder.
Returns:
array question objects.

Definition at line 764 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.
Returns:
object The default category - the category in the course context

Definition at line 1021 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Create url for question export

Parameters:
int$contextid,currentcontext
int$categoryid,categoryid
string$format
string$withcategories
string$ithcontexts
moodle_urlexport file url

Definition at line 1878 of file questionlib.php.

Here is the call graph for this function:

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.

Definition at line 616 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 577 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1893 of file questionlib.php.

Here is the call graph for this function:

question_pluginfile ( course,
context,
component,
filearea,
args,
forcedownload 
)

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:
object$coursecourse settings object
object$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.

Definition at line 1739 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_preload_questions ( questionids,
extrafields = '',
join = '',
extraparams = array() 
)

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 mod/quiz/attemptlib.php, and read the code below to see how the SQL is assembled. Throws exceptions on error.

object object

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.
array$extraparamsvalues for any placeholders in $join. You are strongly recommended to use named placeholder.
Returns:
array partially complete question objects. You need to call get_question_options on them before they can be properly used.

Definition at line 714 of file questionlib.php.

Here is the caller graph for this function:

Returns:
array that can be passed as $params to the popup_action constructor.

Definition at line 690 of file questionlib.php.

Here is the caller graph for this function:

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.
Returns:
string the URL.

Definition at line 647 of file questionlib.php.

Here is the caller graph for this function:

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
Returns:
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.

Definition at line 75 of file questionlib.php.

Here is the caller graph for this function:

question_require_capability_on ( question,
cap 
)

Require capability on question.

Definition at line 1354 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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$contextid
string$componentcomponent
string$fileareafilearea
array$idsother IDs will be used to check file permission
int$itemid
array$options
Returns:
string

Definition at line 1662 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_rewrite_questiontext_preview_urls ( questiontext,
contextid,
component,
questionid,
options = null 
)

Rewrite the PLUGINFILE urls in the questiontext, when viewing the question text outside and attempt (for example, in the question bank listing or in the quiz statistics report).

Parameters:
string$questiontextthe question text.
int$contextidthe context the text is being displayed in.
string$componentcomponent
array$idsother IDs will be used to check file permission
array$options
Returns:
string $questiontext with URLs rewritten.

Definition at line 1688 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Enter description here...

Parameters:
array$questionidsof question ids
object$newcontextthe context to create the saved category in.
string$oldplacea textual description of the think being deleted, e.g. from get_context_name
object$newcategory
Returns:
mixed false on

Definition at line 494 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

question_save_qtype_order ( neworder,
config = null 
)

Save a new question type order to the config_plugins table. object

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

Definition at line 100 of file questionlib.php.

Here is the call graph for this function:

question_send_questiontext_file ( questionid,
args,
forcedownload 
)

Send a file from the question text of a question.

Parameters:
int$questionidthe question id
array$argsthe remaining file arguments (file path).
bool$forcedownloadwhether the user must be forced to download the file.

Definition at line 1701 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

questions_in_use ( questionids)
Parameters:
array$questionidsof question ids.
Returns:
boolean whether any of these questions are being used by any part of Moodle.

Definition at line 134 of file questionlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

save_question_options ( question)

FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////.

Saves question options

Simply calls the question type specific save_question_options() method.

Definition at line 851 of file questionlib.php.

Here is the call graph for this function:

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

CATEGORY FUNCTIONS /////////////////////////////////////////////////////////////////.

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.

Definition at line 862 of file questionlib.php.

Here is the caller graph for this function:

 All Data Structures Namespaces Files Functions Variables Enumerations