Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/locallib.php File Reference

Go to the source code of this file.

Data Structures

class  mod_quiz_display_options
class  qubaids_for_quiz

Namespaces

namespace  mod
 

Local Library of functions for module scorm.


Enumerations

enum  QUIZ_SHOW_TIME_BEFORE_DEADLINE

Functions

 quiz_create_attempt ($quiz, $attemptnumber, $lastattempt, $timenow, $ispreview=false)
 Functions related to attempts /////////////////////////////////////////.
 quiz_get_user_attempt_unfinished ($quizid, $userid)
 quiz_delete_attempt ($attempt, $quiz)
 quiz_delete_previews ($quiz, $userid=null)
 quiz_has_attempts ($quizid)
 quiz_questions_in_quiz ($layout)
 Functions to do with quiz layout and pages ////////////////////////////////.
 quiz_number_of_pages ($layout)
 quiz_number_of_questions_in_quiz ($layout)
 quiz_repaginate ($layout, $perpage, $shuffle=false)
 quiz_get_all_question_grades ($quiz)
 Functions to do with quiz grades //////////////////////////////////////////.
 quiz_rescale_grade ($rawgrade, $quiz, $format=true)
 quiz_feedback_for_grade ($grade, $quiz, $context)
 quiz_has_feedback ($quiz)
 quiz_update_sumgrades ($quiz)
 quiz_update_all_attempt_sumgrades ($quiz)
 quiz_set_grade ($newgrade, $quiz)
 quiz_save_best_grade ($quiz, $userid=null, $attempts=array())
 quiz_calculate_best_grade ($quiz, $attempts)
 quiz_update_all_final_grades ($quiz)
 quiz_calculate_best_attempt ($quiz, $attempts)
 quiz_get_grading_options ()
 quiz_get_grading_option_name ($option)
 quiz_question_action_icons ($quiz, $cmid, $question, $returnurl)
 Other quiz functions ////////////////////////////////////////////////////.
 quiz_question_edit_button ($cmid, $question, $returnurl, $contentaftericon= '')
 quiz_question_preview_url ($quiz, $question)
 quiz_question_preview_button ($quiz, $question, $label=false)
 quiz_get_flag_option ($attempt, $context)
 quiz_attempt_state ($quiz, $attempt)
 quiz_get_review_options ($quiz, $attempt, $context)
 quiz_get_combined_reviewoptions ($quiz, $attempts)
 quiz_clean_layout ($layout, $removeemptypages=false)
 quiz_get_slot_for_question ($quiz, $questionid)
 quiz_send_confirmation ($recipient, $a)
 FUNCTIONS FOR SENDING NOTIFICATION MESSAGES ///////////////////////////////.
 quiz_send_notification ($recipient, $submitter, $a)
 quiz_send_notification_messages ($course, $quiz, $attempt, $context, $cm)
 quiz_attempt_submitted_handler ($event)
 quiz_get_js_module ()

Enumeration Type Documentation

We show the countdown timer if there is less than this amount of time left before the the quiz close date. (1 hour)

Definition at line 49 of file locallib.php.


Function Documentation

quiz_attempt_state ( quiz,
attempt 
)

Work out what state this quiz attempt is in.

Parameters:
object$quizthe quiz settings
object$attemptthe quiz_attempt database row.
Returns:
int one of the mod_quiz_display_options::DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.

Definition at line 937 of file locallib.php.

Here is the caller graph for this function:

Handle the quiz_attempt_submitted event.

This sends the confirmation and notification messages, if required.

Parameters:
object$eventthe event object.

Definition at line 1276 of file locallib.php.

Here is the call graph for this function:

quiz_calculate_best_attempt ( quiz,
attempts 
)

Return the attempt with the best grade for a quiz

Which attempt is the best depends on $quiz->grademethod. If the grade method is GRADEAVERAGE then this function simply returns the last attempt.

Returns:
object The attempt with the best grade
Parameters:
object$quizThe quiz for which the best grade is to be calculated
array$attemptsAn array of all the attempts of the user at the quiz

Definition at line 747 of file locallib.php.

quiz_calculate_best_grade ( quiz,
attempts 
)

Calculate the overall grade for a quiz given a number of attempts by a particular user.

Parameters:
object$quizthe quiz settings object.
array$attemptsan array of all the user's attempts at this quiz in order.
Returns:
float the overall grade

Definition at line 554 of file locallib.php.

Here is the caller graph for this function:

quiz_clean_layout ( layout,
removeemptypages = false 
)

Clean the question layout from various possible anomalies:

  • Remove consecutive ","'s
  • Remove duplicate question id's
  • Remove extra "," from beginning and end
  • Finally, add a ",0" in the end if there is none
Parameters:
$string$layout the quiz layout to clean up, usually from $quiz->questions.
bool$removeemptypagesIf true, remove empty pages from the quiz. False by default.
Returns:
$string the cleaned-up layout

Definition at line 1047 of file locallib.php.

Here is the caller graph for this function:

quiz_create_attempt ( quiz,
attemptnumber,
lastattempt,
timenow,
ispreview = false 
)

Functions related to attempts /////////////////////////////////////////.

Creates an object to represent a new attempt at a quiz

Creates an attempt object to represent an attempt at the quiz by the current user starting at the current time. The ->id field is not set. The object is NOT written to the database.

Parameters:
object$quizthe quiz to create an attempt for.
int$attemptnumberthe sequence number for the attempt.
object$lastattemptthe previous attempt by this user, if any. Only needed if $attemptnumber > 1 and $quiz->attemptonlast is true.
int$timenowthe time the attempt was started at.
bool$ispreviewwhether this new attempt is a preview.
Returns:
object the newly created attempt object.

Definition at line 69 of file locallib.php.

Here is the call graph for this function:

quiz_delete_attempt ( attempt,
quiz 
)

Delete a quiz attempt.

Parameters:
mixed$attemptan integer attempt id or an attempt object (row of the quiz_attempts table).
object$quizthe quiz object.

Definition at line 132 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_delete_previews ( quiz,
userid = null 
)

Delete all the preview attempts at a quiz, or possibly all the attempts belonging to one user.

Parameters:
object$quizthe quiz object.
int$userid(optional) if given, only delete the previews belonging to this user.

Definition at line 168 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_feedback_for_grade ( grade,
quiz,
context 
)

Get the feedback text that should be show to a student who got this grade on this quiz. The feedback is processed ready for diplay.

Parameters:
float$gradea grade on this quiz.
object$quizthe quiz settings.
object$contextthe quiz context.
Returns:
string the comment that corresponds to this grade (empty string if there is not one.

Definition at line 349 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Functions to do with quiz grades //////////////////////////////////////////.

Creates an array of maximum grades for a quiz

The grades are extracted from the quiz_question_instances table.

Parameters:
object$quizThe quiz settings.
Returns:
array of grades indexed by question id. These are the maximum possible grades that students can achieve for each of the questions.

Definition at line 280 of file locallib.php.

Here is the call graph for this function:

quiz_get_combined_reviewoptions ( quiz,
attempts 
)

Combines the review options from a number of different quiz attempts. Returns an array of two ojects, so the suggested way of calling this funciton is: list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)

Parameters:
object$quizthe quiz instance.
array$attemptsan array of attempt objects.
$contextthe roles and permissions context, normally the context for the quiz module instance.
Returns:
array of two options objects, one showing which options are true for at least one of the attempts, the other showing which options are true for all attempts.

Definition at line 1012 of file locallib.php.

Here is the call graph for this function:

quiz_get_flag_option ( attempt,
context 
)
Parameters:
object$attemptthe attempt.
object$contextthe quiz context.
Returns:
int whether flags should be shown/editable to the current user for this attempt.

Definition at line 919 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Parameters:
int$optionone of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE, QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST.
Returns:
the lang string for that option.

Definition at line 794 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
the options for calculating the quiz grade from the individual attempt grades.

Definition at line 780 of file locallib.php.

Here is the caller graph for this function:

Definition at line 1294 of file locallib.php.

Here is the caller graph for this function:

quiz_get_review_options ( quiz,
attempt,
context 
)

The the appropraite mod_quiz_display_options object for this attempt at this quiz right now.

Parameters:
object$quizthe quiz instance.
object$attemptthe attempt in question.
$contextthe quiz context.
Returns:
mod_quiz_display_options

Definition at line 959 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_get_slot_for_question ( quiz,
questionid 
)

Get the slot for a question with a particular id.

Parameters:
object$quizthe quiz settings.
int$questionidthe of a question in the quiz.
Returns:
int the corresponding slot. Null if the question is not in the quiz.

Definition at line 1093 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_get_user_attempt_unfinished ( quizid,
userid 
)

Returns an unfinished attempt (if there is one) for the given user on the given quiz. This function does not return preview attempts.

Parameters:
int$quizidthe id of the quiz.
int$useridthe id of the user.
Returns:
mixed the unfinished attempt if there is one, false if not.

Definition at line 117 of file locallib.php.

Here is the call graph for this function:

quiz_has_attempts ( quizid)
Parameters:
int$quizidThe quiz id.
Returns:
bool whether this quiz has any (non-preview) attempts.

Definition at line 184 of file locallib.php.

Here is the caller graph for this function:

quiz_has_feedback ( quiz)
Parameters:
object$quizthe quiz database row.
Returns:
bool Whether this quiz has any non-blank feedback text.

Definition at line 381 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_number_of_pages ( layout)

Returns the number of pages in a quiz layout

Parameters:
string$layoutThe string representing the quiz layout. Always ends in ,0
Returns:
int The number of pages in the quiz.

Definition at line 215 of file locallib.php.

Here is the caller graph for this function:

Returns the number of questions in the quiz layout

Parameters:
string$layoutthe string representing the quiz layout.
Returns:
int The number of questions in the quiz.

Definition at line 225 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_question_action_icons ( quiz,
cmid,
question,
returnurl 
)

Other quiz functions ////////////////////////////////////////////////////.

Parameters:
object$quizthe quiz.
int$cmidthe course_module object for this quiz.
object$questionthe question.
string$returnurlurl to return to after action is done.
Returns:
string html for a number of icons linked to action pages for a question - preview and edit / view icons depending on user capabilities.

Definition at line 809 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_question_edit_button ( cmid,
question,
returnurl,
contentaftericon = '' 
)
Parameters:
int$cmidthe course_module.id for this quiz.
object$questionthe question.
string$returnurlurl to return to after action is done.
string$contentbeforeiconsome HTML content to be added inside the link, before the icon.
Returns:
the HTML for an edit icon, view icon, or nothing for a question (depending on permissions).

Definition at line 823 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_question_preview_button ( quiz,
question,
label = false 
)
Parameters:
object$quizthe quiz settings
object$questionthe question
bool$labelif true, show the preview question label after the icon
Returns:
the HTML for a preview question icon.

Definition at line 890 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_question_preview_url ( quiz,
question 
)
Parameters:
object$quizthe quiz settings
object$questionthe question
Returns:
moodle_url to preview this question with the options from this quiz.

Definition at line 869 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_questions_in_quiz ( layout)

Functions to do with quiz layout and pages ////////////////////////////////.

Returns a comma separated list of question ids for the quiz

Parameters:
string$layoutThe string representing the quiz layout. Each page is represented as a comma separated list of question ids and 0 indicating page breaks. So 5,2,0,3,0 means questions 5 and 2 on page 1 and question 3 on page 2
Returns:
string comma separated list of question ids, without page breaks.

Definition at line 200 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_repaginate ( layout,
perpage,
shuffle = false 
)

Re-paginates the quiz layout

Parameters:
string$layoutThe string representing the quiz layout. If there is if there is any doubt about the quality of the input data, call quiz_clean_layout before you call this function.
int$perpageThe number of questions per page
bool$shuffleShould the questions be reordered randomly?
Returns:
string the new layout string

Definition at line 244 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_rescale_grade ( rawgrade,
quiz,
format = true 
)

Convert the raw grade stored in $attempt into a grade out of the maximum grade for this quiz.

Parameters:
float$rawgradethe unadjusted grade, fof example $attempt->sumgrades
object$quizthe quiz object. Only the fields grade, sumgrades and decimalpoints are used.
bool | string$formatwhether to format the results for display or 'question' to format a question grade (different number of decimal places.
Returns:
float|string the rescaled grade, or null/the lang string 'notyetgraded' if the $grade is null.

Definition at line 324 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_save_best_grade ( quiz,
userid = null,
attempts = array() 
)

Save the overall grade for a user at a quiz in the quiz_grades table

Parameters:
object$quizThe quiz for which the best grade is to be calculated and then saved.
int$useridThe userid to calculate the grade for. Defaults to the current user.
array$attemptsThe attempts of this user. Useful if you are looping through many users. Attempts can be fetched in one master query to avoid repeated querying.
Returns:
bool Indicates success or failure.

Definition at line 510 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_send_confirmation ( recipient,
a 
)

FUNCTIONS FOR SENDING NOTIFICATION MESSAGES ///////////////////////////////.

Sends a confirmation message to the student confirming that the attempt was processed.

Parameters:
object$alots of useful information that can be used in the message subject and body.
Returns:
int|false as for message_send().

Definition at line 1113 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_send_notification ( recipient,
submitter,
a 
)

Sends notification messages to the interested parties that assign the role capability

Parameters:
object$recipientuser object of the intended recipient
object$aassociative array of replaceable fields for the templates
Returns:
int|false as for message_send().

Definition at line 1149 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_send_notification_messages ( course,
quiz,
attempt,
context,
cm 
)

Send all the requried messages when a quiz attempt is submitted.

Parameters:
object$coursethe course
object$quizthe quiz
object$attemptthis attempt just finished
object$contextthe quiz context
object$cmthe coursemodule for this quiz
Returns:
bool true if all necessary messages were sent successfully, else false.

Definition at line 1188 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_set_grade ( newgrade,
quiz 
)

The quiz grade is the maximum that student's results are marked out of. When it changes, the corresponding data in quiz_grades and quiz_feedback needs to be rescaled. After calling this function, you probably need to call quiz_update_all_attempt_sumgrades, quiz_update_all_final_grades and quiz_update_grades.

Parameters:
float$newgradethe new maximum grade for the quiz.
object$quizthe quiz we are updating. Passed by reference so its grade field can be updated too.
Returns:
bool indicating success or failure.

Definition at line 455 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Update the sumgrades field of the attempts at a quiz.

Parameters:
object$quiza quiz.

Definition at line 428 of file locallib.php.

Here is the caller graph for this function:

Update the final grade at this quiz for all students.

This function is equivalent to calling quiz_save_best_grade for all users, but much more efficient.

Parameters:
object$quizthe quiz settings.

Definition at line 600 of file locallib.php.

Here is the caller graph for this function:

quiz_update_sumgrades ( quiz)

Update the sumgrades field of the quiz. This needs to be called whenever the grading structure of the quiz is changed. For example if a question is added or removed, or a question weight is changed.

You should call quiz_delete_previews() before you call this function.

Parameters:
object$quiza quiz.

Definition at line 402 of file locallib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

 All Data Structures Namespaces Files Functions Variables Enumerations