Moodle  2.2.1
http://www.collinsharper.com
qtype_random Class Reference
Inheritance diagram for qtype_random:
Collaboration diagram for qtype_random:

Public Member Functions

 menu_name ()
 is_manual_graded ()
 is_usable_by_random ()
 is_question_manual_graded ($question, $otherquestionsinuse)
 display_question_editing_page ($mform, $question, $wizardnow)
 get_question_options ($question)
 question_name ($category, $includesubcategories)
 save_question ($question, $form)
 save_question_options ($question)
 get_available_questions_from_category ($categoryid, $subcategories)
 make_question ($questiondata)
 choose_other_question ($questiondata, $excludedquestions, $allowshuffle=true)
 get_random_guess_score ($questiondata)

Protected Member Functions

 init_qtype_lists ()
 set_selected_question_name ($question, $randomname)

Protected Attributes

 $excludedqtypes = null
 $manualqtypes = null

Detailed Description

The random question type.

This question type does not have a question definition class, nor any renderers. When you load a question of this type, it actually loads a question chosen randomly from a particular category in the question bank.

Definition at line 42 of file questiontype.php.


Member Function Documentation

choose_other_question ( questiondata,
excludedquestions,
allowshuffle = true 
)

Load the definition of another question picked randomly by this question.

Parameters:
object$questiondatathe data defining a random question.
array$excludedquestionsof question ids. We will no pick any question whose id is in this list.
bool$allowshuffleif false, then any shuffle option on the selected quetsion is disabled.
Returns:
question_definition|null the definition of the question that was selected, or null if no suitable question could be found.

Definition at line 220 of file questiontype.php.

Here is the call graph for this function:

Here is the caller graph for this function:

display_question_editing_page ( mform,
question,
wizardnow 
)

This method should be overriden if you want to include a special heading or some other html on a question editing page besides the question editing form.

Parameters:
question_edit_form$mforma child of question_edit_form
object$question
string$wizardnowis '' for first page.

Reimplemented from question_type.

Definition at line 118 of file questiontype.php.

Here is the call graph for this function:

get_available_questions_from_category ( categoryid,
subcategories 
)

Get all the usable questions from a particular question category.

Parameters:
int$categoryidthe id of a question category.
boolwhether to include questions from subcategories.
string$questionsinusecomma-separated list of question ids to exclude from consideration.
Returns:
array of question records.

Definition at line 188 of file questiontype.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_question_options ( question)

Loads the question type specific options for the question.

This function loads any question type specific options for the question from the database into the question object. This information is placed in the $question->options field. A question type is free, however, to decide on a internal structure of the options field.

Returns:
bool Indicates success or failure.
Parameters:
object$questionThe question object for the question. This object should be updated to include the question type specific information (it is passed by reference).

Reimplemented from question_type.

Definition at line 125 of file questiontype.php.

get_random_guess_score ( questiondata)
Parameters:
object$question
Returns:
number|null either a fraction estimating what the student would score by guessing, or null, if it is not possible to estimate.

Reimplemented from question_type.

Definition at line 237 of file questiontype.php.

init_qtype_lists ( ) [protected]

This method needs to be called before the ->excludedqtypes and ->manualqtypes fields can be used.

Definition at line 100 of file questiontype.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
bool true if this question type sometimes requires manual grading.

Reimplemented from question_type.

Definition at line 61 of file questiontype.php.

is_question_manual_graded ( question,
otherquestionsinuse 
)
Parameters:
object$questiona question of this type.
string$otherquestionsinusecomma-separate list of other question ids in this attempt.
Returns:
bool true if a particular instance of this question requires manual grading.

Reimplemented from question_type.

Definition at line 69 of file questiontype.php.

Here is the call graph for this function:

Returns:
bool true if this question type can be used by the random question type.

Reimplemented from question_type.

Definition at line 65 of file questiontype.php.

make_question ( questiondata)

Create an appropriate question_definition for the question of this type using data loaded from the database.

Parameters:
object$questiondatathe question data loaded from the database.
Returns:
question_definition the corresponding question_definition.

Reimplemented from question_type.

Definition at line 206 of file questiontype.php.

Here is the call graph for this function:

menu_name ( )

The name this question should appear as in the create new question dropdown. Override this method to return false if you don't want your question type to be createable, for example if it is an abstract base type, otherwise, you should not need to override this method.

Returns:
mixed the desired string, or false to hide this question type in the menu.

Reimplemented from question_type.

Definition at line 56 of file questiontype.php.

question_name ( category,
includesubcategories 
)

Random questions always get a question name that is Random (cateogryname). This function is a centralised place to calculate that, given the category.

Parameters:
object$categorythe category this question picks from. (Only ->name is used.)
bool$includesubcategorieswhether this question also picks from subcategories.
Returns:
string the name this question should have.

Definition at line 136 of file questiontype.php.

Here is the call graph for this function:

Here is the caller graph for this function:

save_question ( question,
form 
)

Saves (creates or updates) a question.

Given some question info and some data about the answers this function parses, organises and saves the question It is used by question.php when saving new data from a form, and also by import.php when importing questions This function in turn calls save_question_options to save question-type specific data.

Whether we are saving a new question or updating an existing one can be determined by testing !empty($question->id). If it is not empty, we are updating.

The question will be saved in category $form->category.

Parameters:
object$questionthe question object which should be updated. For a new question will be mostly empty.
object$formthe object containing the information to save, as if from the question editing form.
object$coursenot really used any more.
Returns:
object On success, return the new question object. On failure, return an object as follows. If the error object has an errors field, display that as an error message. Otherwise, the editing form will be redisplayed with validation errors, from validation_errors field, which is itself an object, shown next to the form fields. (I don't think this is accurate any more.)

Question already exists, update.

Reimplemented from question_type.

Definition at line 152 of file questiontype.php.

save_question_options ( question)

Saves question-type specific options

This is called by save_question() to save the question-type specific data

Returns:
object $result->error or $result->noticeyesno or $result->notice
Parameters:
object$questionThis holds the information from the editing form, it is not a standard question object.

Reimplemented from question_type.

Definition at line 162 of file questiontype.php.

Here is the call graph for this function:

set_selected_question_name ( question,
randomname 
) [protected]

Definition at line 145 of file questiontype.php.

Here is the caller graph for this function:


Field Documentation

$excludedqtypes = null [protected]

Definition at line 44 of file questiontype.php.

$manualqtypes = null [protected]

Definition at line 47 of file questiontype.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations