File/sloodle/mod/quiz-1.0/locallib.1.9.php

Description

Library of functions used by the quiz module.

This contains functions that are called from within the quiz module only Functions that are also called by core Moodle are in lib.php This script also loads the code in questionlib.php which holds the module-indpendent code for handling questions and which in turn initialises all the questiontype classes.

Includes
 require_once ($CFG->dirroot.'/question/editlib.php') (line 23)
 require_once ($CFG->dirroot.'/mod/quiz/lib.php') (line 22)

Include those library functions that are also used by core Moodle or other modules

Constants
QUIZ_ATTEMPTFIRST = "3" (line 33)

Options determining how the grades from individual attempts are combined to give

the overall grade for a user

QUIZ_ATTEMPTLAST = "4" (line 34)

Options determining how the grades from individual attempts are combined to give

the overall grade for a user

QUIZ_GRADEAVERAGE = "2" (line 32)

Options determining how the grades from individual attempts are combined to give

the overall grade for a user

QUIZ_GRADEHIGHEST = "1" (line 31)

Options determining how the grades from individual attempts are combined to give

the overall grade for a user

QUIZ_STATE_CLOSED = 'closed' (line 43)

Constants to describe the various states a quiz attempt can be in.

QUIZ_STATE_DURING = 'during' (line 40)

Constants to describe the various states a quiz attempt can be in.

QUIZ_STATE_IMMEDIATELY = 'immedately' (line 41)

Constants to describe the various states a quiz attempt can be in.

QUIZ_STATE_OPEN = 'open' (line 42)

Constants to describe the various states a quiz attempt can be in.

QUIZ_STATE_TEACHERACCESS = 'teacheraccess' (line 44)

Constants to describe the various states a quiz attempt can be in.

Functions
quiz_calculate_best_attempt (line 526)

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.

  • return: attempt with the best grade
object The quiz_calculate_best_attempt (object $quiz, array $attempts)
  • object $quiz: The quiz for which the best grade is to be calculated
  • array $attempts: An array of all the attempts of the user at the quiz
quiz_calculate_best_grade (line 480)

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

  • return: The overall grade
float quiz_calculate_best_grade (object $quiz, array $attempts)
  • object $quiz: The quiz for which the best grade is to be calculated
  • array $attempts: An array of all the attempts of the user at the quiz
quiz_create_attempt (line 59)

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.

  • return: newly created attempt object.
object The quiz_create_attempt (object $quiz, integer $attemptnumber)
  • object $quiz: The quiz to create an attempt for.
  • integer $attemptnumber: The sequence number for the attempt.
quiz_delete_attempt (line 106)

Delete a quiz attempt.

void quiz_delete_attempt ( $attempt,  $quiz)
  • $attempt
  • $quiz
quiz_feedback_for_grade (line 340)

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.

  • return: the comment that corresponds to this grade (empty string if there is not one.
string quiz_feedback_for_grade (float $grade, integer $quizid)
  • float $grade: a grade on this quiz.
  • integer $quizid: the id of the quiz object.
quiz_first_questionnumber (line 181)

Returns the first question number for the current quiz page

  • return: The number of the first question
integer quiz_first_questionnumber (string $quizlayout, string $pagelayout)
  • string $quizlayout: The string representing the layout for the whole quiz
  • string $pagelayout: The string representing the layout for the current page
quiz_get_all_question_grades (line 267)

Creates an array of maximum grades for a quiz

The grades are extracted from the quiz_question_instances table.

  • return: Array of grades indexed by question id These are the maximum possible grades that students can achieve for each of the questions
array quiz_get_all_question_grades (integer $quiz)
  • integer $quiz: The quiz object
quiz_get_best_grade (line 301)

Get the best current grade for a particular user in a quiz.

  • return: the user's current grade for this quiz.
float quiz_get_best_grade (object $quiz, integer $userid)
  • object $quiz: the quiz object.
  • integer $userid: the id of the user.
quiz_get_combined_reviewoptions (line 754)

Combines the review options from a number of different quiz attempts.

Returns an array of two ojects, so he suggested way of calling this funciton is: list($someoptions, $alloptions) = quiz_get_combined_reviewoptions(...)

  • return: 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.
array quiz_get_combined_reviewoptions (object $quiz, array $attempts, [$context $context = null])
  • object $quiz: the quiz instance.
  • array $attempts: an array of attempt objects.
  • $context $context: the roles and permissions context, normally the context for the quiz module instance.
quiz_get_grading_options (line 559)
  • return: options for calculating the quiz grade from the individual attempt grades.
the quiz_get_grading_options ()
quiz_get_grading_option_name (line 571)
  • return: lang string for that option.
the quiz_get_grading_option_name (int $option)
  • int $option: one of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE, QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST.
quiz_get_renderoptions (line 648)

Determine render options

void quiz_get_renderoptions (int $reviewoptions, object $state)
  • int $reviewoptions
  • object $state
quiz_get_reviewoptions (line 689)

Determine review options

  • return: object with boolean fields responses, scores, feedback, correct_responses, solutions and general feedback
object an quiz_get_reviewoptions (object $quiz, object $attempt, [$context $context = null])
  • object $quiz: the quiz instance.
  • object $attempt: the attempt in question.
  • $context $context: the roles and permissions context, normally the context for the quiz module instance.
quiz_get_user_attempt_unfinished (line 94)

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

  • return: the unfinished attempt if there is one, false if not.
mixed quiz_get_user_attempt_unfinished (integer $quizid, integer $userid)
  • integer $quizid: the id of the quiz.
  • integer $userid: the id of the user.
quiz_has_feedback (line 360)
  • return: Whether this quiz has any non-blank feedback text.
boolean quiz_has_feedback (integer $quizid)
  • integer $quizid: the id of the quiz object.
quiz_number_of_pages (line 170)

Returns the number of pages in the quiz layout

  • return: Comma separated list of question ids
integer quiz_number_of_pages (string $layout)
  • string $layout: The string representing the quiz layout.
quiz_parse_fieldname (line 581)

Parse field names used for the replace options on question edit forms

void quiz_parse_fieldname ( $name, [ $nameprefix = 'question'])
  • $name
  • $nameprefix
quiz_print_navigation_panel (line 229)

Print navigation panel for quiz attempt and review pages

void quiz_print_navigation_panel (integer $page, integer $pages)
  • integer $page: The number of the current page (counting from 0).
  • integer $pages: The total number of pages.
quiz_questions_in_quiz (line 160)

Returns a comma separated list of question ids for the quiz

  • return: Comma separated list of question ids
string quiz_questions_in_quiz (string $layout)
  • string $layout: The 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
quiz_questions_on_page (line 147)

Returns a comma separated list of question ids for the current page

  • return: Comma separated list of question ids
string quiz_questions_on_page (string $layout, integer $page)
  • string $layout: The 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
  • integer $page: The number of the current page.
quiz_question_preview_button (line 630)
  • return: HTML for a preview question icon.
the quiz_question_preview_button (object $quiz, object $question)
  • object $quiz: the quiz
  • object $question: the question
quiz_repaginate (line 203)

Re-paginates the quiz layout

  • return: The new layout string
string quiz_repaginate (string $layout, integer $perpage, [boolean $shuffle = false])
  • string $layout: The string representing the quiz layout.
  • integer $perpage: The number of questions per page
  • boolean $shuffle: Should the questions be reordered randomly?
quiz_rescale_grade (line 320)

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

  • return: the rescaled grade.
float quiz_rescale_grade (float $rawgrade, object $quiz, [ $round = true])
  • float $rawgrade: the unadjusted grade, fof example $attempt->sumgrades
  • object $quiz: the quiz object. Only the fields grade, sumgrades and decimalpoints are used.
  • $round
quiz_save_best_grade (line 433)

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

  • return: Indicates success or failure.
boolean quiz_save_best_grade (object $quiz, [integer $userid = null])
  • object $quiz: The quiz for which the best grade is to be calculated and then saved.
  • integer $userid: The userid to calculate the grade for. Defaults to the current user.
quiz_send_confirmation (line 781)

Sends confirmation email to the student taking the course

  • return: result of email_to_user()
bool|string quiz_send_confirmation (stdClass $a)
  • stdClass $a: associative array of replaceable fields for the templates
quiz_send_notification (line 806)

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

  • return: result of email_to_user()
bool|string quiz_send_notification (object $recipient, stdClass $a)
  • object $recipient: user object of the intended recipient
  • stdClass $a: associative array of replaceable fields for the templates
quiz_send_notification_emails (line 835)

Takes a bunch of information to format into an email and send to the specified recipient.

  • return: number of emails sent
int quiz_send_notification_emails (object $course, object $quiz, object $attempt, object $context, object $cm)
  • object $course: the course
  • object $quiz: the quiz
  • object $attempt: this attempt just finished
  • object $context: the quiz context
  • object $cm: the coursemodule for this quiz
quiz_set_grade (line 378)

The quiz grade is the score that student's results are marked out of. When it changes, the corresponding data in quiz_grades and quiz_feedback needs to be rescaled.

  • return: indicating success or failure.
boolean quiz_set_grade (float $newgrade,  &$quiz, object $quiz)
  • float $newgrade: the new maximum grade for the quiz.
  • object $quiz: the quiz we are updating. Passed by reference so its grade field can be updated too.
  • &$quiz
quiz_upgrade_states (line 599)

Upgrade states for an attempt to Moodle 1.5 model

Any state that does not yet have its timestamp set to nonzero has not yet been upgraded from Moodle 1.4 The reason these are still around is that for large sites it would have taken too long to upgrade all states at once. This function sets the timestamp field and creates an entry in the question_sessions table.

void quiz_upgrade_states (object $attempt)
  • object $attempt: The attempt whose states need upgrading

Documentation generated on Mon, 16 Jun 2008 15:56:36 +0100 by phpDocumentor 1.4.0