Moodle  2.2.1
http://www.collinsharper.com
quiz_attempt Class Reference

Public Member Functions

 __construct ($attempt, $quiz, $cm, $course, $loadquestions=true)
 get_quiz ()
 get_quizobj ()
 get_courseid ()
 get_course ()
 get_quizid ()
 get_quiz_name ()
 get_cm ()
 get_cmid ()
 is_preview_user ()
 get_num_attempts_allowed ()
 get_num_pages ()
 get_access_manager ($timenow)
 get_attemptid ()
 get_uniqueid ()
 get_attempt ()
 get_attempt_number ()
 get_userid ()
 is_finished ()
 is_preview ()
 is_own_attempt ()
 is_own_preview ()
 is_review_allowed ()
 get_overall_feedback ($grade)
 has_capability ($capability, $userid=null, $doanything=true)
 require_capability ($capability, $userid=null, $doanything=true)
 check_review_capability ()
 get_attempt_state ()
 get_display_options ($reviewing)
 get_display_options_with_edit_link ($reviewing, $slot, $thispageurl)
 is_last_page ($page)
 get_slots ($page= 'all')
 get_question_attempt ($slot)
 is_real_question ($slot)
 is_question_flagged ($slot)
 get_question_number ($slot)
 get_question_name ($slot)
 get_question_status ($slot, $showcorrectness)
 get_question_state_class ($slot, $showcorrectness)
 get_question_mark ($slot)
 get_question_action_time ($slot)
 view_url ()
 start_attempt_url ($slot=null, $page=-1)
 attempt_url ($slot=null, $page=-1, $thispage=-1)
 summary_url ()
 processattempt_url ()
 review_url ($slot=null, $page=-1, $showall=false, $thispage=-1)
 cannot_review_message ($short=false)
 get_html_head_contributions ($page= 'all', $showall=false)
 get_question_html_head_contributions ($slot)
 restart_preview_button ()
 render_question ($slot, $reviewing, $thispageurl=null)
 render_question_at_step ($slot, $seq, $reviewing, $thispageurl= '')
 render_question_for_commenting ($slot)
 check_file_access ($slot, $reviewing, $contextid, $component, $filearea, $args, $forcedownload)
 get_navigation_panel (mod_quiz_renderer $output, $panelclass, $page, $showall=false)
 links_to_other_attempts (moodle_url $url)
 process_all_actions ($timestamp)
 save_question_flags ()
 finish_attempt ($timestamp)
 question_print_comment_fields ($slot, $prefix)

Static Public Member Functions

static create ($attemptid)
static create_from_usage_id ($usageid)

Protected Member Functions

 page_and_question_url ($script, $slot, $page, $showall, $thispage)

Static Protected Member Functions

static create_helper ($conditions)

Protected Attributes

 $quizobj
 $attempt
 $quba
 $pagelayout
 $reviewoptions = null

Detailed Description

This class extends the quiz class to hold data about the state of a particular attempt, in addition to the data about the quiz.

Since:
Moodle 2.0

Definition at line 408 of file attemptlib.php.


Constructor & Destructor Documentation

__construct ( attempt,
quiz,
cm,
course,
loadquestions = true 
)

Constructor assuming we already have the necessary data loaded.

Parameters:
object$attemptthe row of the quiz_attempts table.
object$quizthe quiz object for this attempt and user.
object$cmthe course_module object for this quiz.
object$coursethe row from the course table for the course we belong to.
bool$loadquestions(optional) if true, the default, load all the details of the state of each question. Else just set up the basic details of the attempt.

Definition at line 429 of file attemptlib.php.

Here is the call graph for this function:


Member Function Documentation

attempt_url ( slot = null,
page = -1,
thispage = -1 
)
Parameters:
int$slotif speified, the slot number of a specific question to link to.
int$pageif specified, a particular page to link to. If not givem deduced from $slot, or goes to the first page.
int$questionida question id. If set, will add a fragment to the URL to jump to a particuar question on the page.
int$thispageif not -1, the current page. Will cause links to other things on this page to be output as only a fragment.
Returns:
string the URL to continue this attempt.

Definition at line 930 of file attemptlib.php.

Here is the call graph for this function:

cannot_review_message ( short = false)

If $reviewoptions->attempt is false, meaning that students can't review this attempt at the moment, return an appropriate string explaining why.

Parameters:
bool$shortif true, return a shorter string.
Returns:
string an appropraite message.

Definition at line 971 of file attemptlib.php.

Here is the call graph for this function:

check_file_access ( slot,
reviewing,
contextid,
component,
filearea,
args,
forcedownload 
)

Check wheter access should be allowed to a particular file.

Parameters:
int$idthe id of a question in this quiz attempt.
bool$reviewingis the being printed on an attempt or a review page.
string$thispageurlthe URL of the page this question is being printed on.
Returns:
string HTML for the question in its current state.

Definition at line 1068 of file attemptlib.php.

Here is the call graph for this function:

Check the appropriate capability to see whether this user may review their own attempt. If not, prints an error.

Definition at line 696 of file attemptlib.php.

Here is the call graph for this function:

static create ( attemptid) [static]

Static function to create a new quiz_attempt object given an attemptid.

Parameters:
int$attemptidthe attempt id.
Returns:
quiz_attempt the new quiz_attempt object

Definition at line 466 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static create_from_usage_id ( usageid) [static]

Static function to create a new quiz_attempt object given a usage id.

Parameters:
int$usageidthe attempt usage id.
Returns:
quiz_attempt the new quiz_attempt object

Definition at line 476 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static create_helper ( conditions) [static, protected]

Used by {create()} and {create_from_usage_id()}.

Parameters:
array$conditionspassed to $DB->get_record('quiz_attempts', $conditions).

Definition at line 446 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

finish_attempt ( timestamp)

Definition at line 1150 of file attemptlib.php.

Here is the call graph for this function:

get_access_manager ( timenow)
Parameters:
int$timenowthe current time as a unix timestamp.
Returns:
quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time.

Definition at line 581 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
object the row from the quiz_attempts table.

Definition at line 596 of file attemptlib.php.

Returns:
int the number of this attemp (is it this user's first, second, ... attempt).

Definition at line 601 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
int one of the mod_quiz_display_options::DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.

Definition at line 710 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
int the attempt id.

Definition at line 586 of file attemptlib.php.

get_cm ( )
Returns:
object the course_module object.

Definition at line 549 of file attemptlib.php.

Here is the caller graph for this function:

get_cmid ( )
Returns:
object the course_module object.

Definition at line 554 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
int the course id.

Definition at line 534 of file attemptlib.php.

Returns:
int the course id.

Definition at line 529 of file attemptlib.php.

Here is the caller graph for this function:

get_display_options ( reviewing)

Wrapper that the correct mod_quiz_display_options for this quiz at the moment.

Returns:
question_display_options the render options for this user on this attempt.

Definition at line 720 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_display_options_with_edit_link ( reviewing,
slot,
thispageurl 
)

Wrapper that the correct mod_quiz_display_options for this quiz at the moment.

Parameters:
bool$reviewingtrue for review page, else attempt page.
int$slotwhich question is being displayed.
moodle_url$thispageurlto return to after the editing form is submitted or cancelled. If null, no edit link will be generated.
Returns:
question_display_options the render options for this user on this attempt, with extra info to generate an edit link, if applicable.

Definition at line 748 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_html_head_contributions ( page = 'all',
showall = false 
)

Initialise the JS etc. required all the questions on a page..

Parameters:
mixed$pagea page number, or 'all'.

Definition at line 980 of file attemptlib.php.

Here is the call graph for this function:

get_navigation_panel ( mod_quiz_renderer output,
panelclass,
page,
showall = false 
)

Get the navigation panel object for this attempt.

Parameters:
$panelclassThe type of panel, quiz_attempt_nav_panel or quiz_review_nav_panel
$pagethe current page number.
$showallwhether we are showing the whole quiz on one page. (Used by review.php)
Returns:
quiz_nav_panel_base the requested object.

Definition at line 1082 of file attemptlib.php.

Here is the call graph for this function:

Returns:
int the number of attempts allowed at this quiz (0 = infinite).

Definition at line 567 of file attemptlib.php.

Returns:
int number fo pages in this quiz.

Definition at line 572 of file attemptlib.php.

get_overall_feedback ( grade)

Get the overall feedback corresponding to a particular mark.

Parameters:
$gradea particular grade.

Definition at line 673 of file attemptlib.php.

Here is the call graph for this function:

Get the time of the most recent action performed on a question.

Parameters:
int$slotthe number used to identify this question within this usage.
Returns:
int timestamp.

Definition at line 896 of file attemptlib.php.

get_question_attempt ( slot)

Get the question_attempt object for a particular question in this attempt.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
question_attempt

Definition at line 802 of file attemptlib.php.

Initialise the JS etc. required by one question.

Parameters:
int$questionidthe question id.

Definition at line 996 of file attemptlib.php.

Here is the call graph for this function:

get_question_mark ( slot)

Return the grade obtained on a particular question. You must previously have called load_question_states to load the state data about this question.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
string the formatted grade, to the number of decimal places specified by the quiz.

Definition at line 887 of file attemptlib.php.

Here is the call graph for this function:

get_question_name ( slot)

Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
string the formatted grade, to the number of decimal places specified by the quiz.

Definition at line 846 of file attemptlib.php.

get_question_number ( slot)

Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
string the formatted grade, to the number of decimal places specified by the quiz.

Definition at line 833 of file attemptlib.php.

get_question_state_class ( slot,
showcorrectness 
)

Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question.

Parameters:
int$slotthe number used to identify this question within this attempt.
bool$showcorrectnessWhether right/partial/wrong states should be distinguised.
Returns:
string class name for this state.

Definition at line 875 of file attemptlib.php.

get_question_status ( slot,
showcorrectness 
)

Return the grade obtained on a particular question, if the user is permitted to see it. You must previously have called load_question_states to load the state data about this question.

Parameters:
int$slotthe number used to identify this question within this attempt.
bool$showcorrectnessWhether right/partial/wrong states should be distinguised.
Returns:
string the formatted grade, to the number of decimal places specified by the quiz.

Definition at line 861 of file attemptlib.php.

get_quiz ( )

Definition at line 520 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
string the name of this quiz.

Definition at line 544 of file attemptlib.php.

Returns:
int the quiz id.

Definition at line 539 of file attemptlib.php.

Here is the caller graph for this function:

Definition at line 524 of file attemptlib.php.

get_slots ( page = 'all')

Return the list of question ids for either a given page of the quiz, or for the whole quiz.

Parameters:
mixed$pagestring 'all' or integer page number.
Returns:
array the reqested list of question ids.

Definition at line 785 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
int the attempt unique id.

Definition at line 591 of file attemptlib.php.

Returns:
int the id of the user this attempt belongs to.

Definition at line 606 of file attemptlib.php.

Here is the caller graph for this function:

has_capability ( capability,
userid = null,
doanything = true 
)

Wrapper round the has_capability funciton that automatically passes in the quiz context.

Definition at line 681 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
bool whether this attempt has been finished (true) or is still in progress (false).

Definition at line 614 of file attemptlib.php.

is_last_page ( page)
Parameters:
int$pagepage number
Returns:
bool true if this is the last page of the quiz.

Definition at line 774 of file attemptlib.php.

Is this a student dealing with their own attempt/teacher previewing, or someone with 'mod/quiz:viewreports' reviewing someone elses attempt.

Returns:
bool whether this situation should be treated as someone looking at their own attempt. The distinction normally only matters when an attempt is being reviewed.

Definition at line 630 of file attemptlib.php.

Here is the call graph for this function:

Returns:
bool whether this attempt is a preview belonging to the current user.

Definition at line 639 of file attemptlib.php.

Here is the call graph for this function:

Returns:
bool whether this attempt is a preview attempt.

Definition at line 619 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
bool wether the current user is someone who previews the quiz, rather than attempting it.

Definition at line 562 of file attemptlib.php.

Here is the caller graph for this function:

is_question_flagged ( slot)

Is a particular question in this attempt a real question, or something like a description.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
bool whether that question is a real question.

Definition at line 820 of file attemptlib.php.

is_real_question ( slot)

Is a particular question in this attempt a real question, or something like a description.

Parameters:
int$slotthe number used to identify this question within this attempt.
Returns:
bool whether that question is a real question.

Definition at line 811 of file attemptlib.php.

Is the current user allowed to review this attempt. This applies when is_own_attempt() returns false.

Returns:
bool whether the review should be allowed.

Definition at line 650 of file attemptlib.php.

Here is the call graph for this function:

Given a URL containing attempt={this attempt id}, return an array of variant URLs

Parameters:
moodle_url$urla URL.
Returns:
string HTML fragment. Comma-separated list of links to the other attempts with the attempt number as the link text. The curent attempt is included but is not a link.

Definition at line 1100 of file attemptlib.php.

Here is the call graph for this function:

page_and_question_url ( script,
slot,
page,
showall,
thispage 
) [protected]

Get a URL for a particular question on a particular page of the quiz. Used by attempt_url() and review_url().

Parameters:
string$script,.Used in the URL like /mod/quiz/$script.php
int$slotidentifies the specific question on the page to jump to. 0 to just use the $page parameter.
int$page-1 to look up the page number from the slot, otherwise the page number to go to.
bool$showallif true, return a URL with showall=1, and not page number
int$thispagethe page we are currently on. Links to questions on this page will just be a fragment #q123. -1 to disable this.
Returns:
The requested URL.

Definition at line 1215 of file attemptlib.php.

Here is the caller graph for this function:

process_all_actions ( timestamp)

Process all the actions that were submitted as part of the current request.

Parameters:
int$timestampthe timestamp that should be stored as the modifed time in the database for these actions. If null, will use the current time.

Definition at line 1125 of file attemptlib.php.

Here is the call graph for this function:

Returns:
string the URL of this quiz's summary page.

Definition at line 944 of file attemptlib.php.

question_print_comment_fields ( slot,
prefix 
)

Print the fields of the comment form for questions in this attempt.

Parameters:
$slotwhich question to output the fields for.
$prefixPrefix to add to all field names.

Definition at line 1187 of file attemptlib.php.

Here is the call graph for this function:

render_question ( slot,
reviewing,
thispageurl = null 
)

Generate the HTML that displayes the question in its current state, with the appropriate display options.

Parameters:
int$idthe id of a question in this quiz attempt.
bool$reviewingis the being printed on an attempt or a review page.
moodle_url$thispageurlthe URL of the page this question is being printed on.
Returns:
string HTML for the question in its current state.

Definition at line 1025 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

render_question_at_step ( slot,
seq,
reviewing,
thispageurl = '' 
)

Like render_question() but displays the question at the past step indicated by $seq, rather than showing the latest step.

Parameters:
int$idthe id of a question in this quiz attempt.
int$seqthe seq number of the past state to display.
bool$reviewingis the being printed on an attempt or a review page.
string$thispageurlthe URL of the page this question is being printed on.
Returns:
string HTML for the question in its current state.

Definition at line 1041 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Wrapper round print_question from lib/questionlib.php.

Parameters:
int$idthe id of a question in this quiz attempt.

Definition at line 1052 of file attemptlib.php.

Here is the call graph for this function:

require_capability ( capability,
userid = null,
doanything = true 
)

Wrapper round the require_capability funciton that automatically passes in the quiz context.

Definition at line 688 of file attemptlib.php.

Here is the caller graph for this function:

Print the HTML for the start new preview button, if the current user is allowed to see one.

Definition at line 1005 of file attemptlib.php.

Here is the call graph for this function:

review_url ( slot = null,
page = -1,
showall = false,
thispage = -1 
)
Parameters:
int$slotindicates which question to link to.
int$pageif specified, the URL of this particular page of the attempt, otherwise the URL will go to the first page. If -1, deduce $page from $slot.
bool$showallif true, the URL will be to review the entire attempt on one page, and $page will be ignored.
int$thispageif not -1, the current page. Will cause links to other things on this page to be output as only a fragment.
Returns:
string the URL to review this attempt.

Definition at line 958 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Update the flagged state for all question_attempts in this usage, if their flagged state was changed in the request.

Definition at line 1145 of file attemptlib.php.

Here is the call graph for this function:

start_attempt_url ( slot = null,
page = -1 
)
Returns:
string the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.

Definition at line 911 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
string the URL of this quiz's summary page.

Definition at line 937 of file attemptlib.php.

view_url ( )
Returns:
string quiz view url.

Definition at line 904 of file attemptlib.php.

Here is the caller graph for this function:


Field Documentation

$attempt [protected]

Definition at line 411 of file attemptlib.php.

$pagelayout [protected]

Definition at line 415 of file attemptlib.php.

$quba [protected]

Definition at line 412 of file attemptlib.php.

$quizobj [protected]

Definition at line 410 of file attemptlib.php.

$reviewoptions = null [protected]

Definition at line 416 of file attemptlib.php.


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