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

Go to the source code of this file.

Namespaces

namespace  mod
 

Local Library of functions for module scorm.


Enumerations

enum  QUIZ_MAX_ATTEMPT_OPTION
enum  QUIZ_MAX_QPP_OPTION
enum  QUIZ_MAX_DECIMAL_OPTION
enum  QUIZ_MAX_Q_DECIMAL_OPTION
enum  QUIZ_GRADEHIGHEST
enum  QUIZ_GRADEAVERAGE
enum  QUIZ_ATTEMPTFIRST
enum  QUIZ_ATTEMPTLAST
enum  QUIZ_MAX_EVENT_LENGTH

Functions

 quiz_add_instance ($quiz)
 quiz_update_instance ($quiz, $mform)
 quiz_delete_instance ($id)
 quiz_delete_override ($quiz, $overrideid)
 quiz_delete_all_overrides ($quiz)
 quiz_update_effective_access ($quiz, $userid)
 quiz_delete_all_attempts ($quiz)
 quiz_get_best_grade ($quiz, $userid)
 quiz_has_grades ($quiz)
 quiz_user_outline ($course, $user, $mod, $quiz)
 quiz_user_complete ($course, $user, $mod, $quiz)
 quiz_cron ()
 quiz_get_user_attempts ($quizid, $userid, $status= 'finished', $includepreviews=false)
 quiz_get_user_grades ($quiz, $userid=0)
 quiz_format_grade ($quiz, $grade)
 quiz_format_question_grade ($quiz, $grade)
 quiz_update_grades ($quiz, $userid=0, $nullifnone=true)
 quiz_upgrade_grades ()
 quiz_grade_item_update ($quiz, $grades=null)
 quiz_grade_item_delete ($quiz)
 quiz_get_participants ($quizid)
 quiz_refresh_events ($courseid=0)
 quiz_get_recent_mod_activity (&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0)
 quiz_print_recent_mod_activity ($activity, $courseid, $detail, $modnames)
 quiz_process_options ($quiz)
 quiz_review_option_form_to_db ($fromform, $field)
 quiz_after_add_or_update ($quiz)
 quiz_update_events ($quiz, $override=null)
 quiz_get_view_actions ()
 quiz_get_post_actions ()
 quiz_questions_in_use ($questionids)
 quiz_reset_course_form_definition ($mform)
 quiz_reset_course_form_defaults ($course)
 quiz_reset_gradebook ($courseid, $type='')
 quiz_reset_userdata ($data)
 quiz_check_file_access ($attemptuniqueid, $questionid, $context=null)
 quiz_print_overview ($courses, &$htmlarray)
 quiz_num_attempt_summary ($quiz, $cm, $returnzero=false, $currentgroup=0)
 quiz_attempt_summary_link_to_reports ($quiz, $cm, $context, $returnzero=false, $currentgroup=0)
 quiz_supports ($feature)
 quiz_get_extra_capabilities ()
 quiz_extend_navigation ($quiznode, $course, $module, $cm)
 quiz_extend_settings_navigation ($settings, $quiznode)
 quiz_pluginfile ($course, $cm, $context, $filearea, $args, $forcedownload)
 mod_quiz_question_pluginfile ($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload)
 quiz_page_type_list ($pagetype, $parentcontext, $currentcontext)

Enumeration Type Documentation

Definition at line 51 of file lib.php.

Definition at line 52 of file lib.php.

Definition at line 50 of file lib.php.

#@- #@+ Options determining how the grades from individual attempts are combined to give the overall grade for a user

Definition at line 49 of file lib.php.

#@+ Option controlling what options are offered on the quiz settings form.

Definition at line 39 of file lib.php.

Definition at line 41 of file lib.php.

#@- If start and end date for the quiz are more than this many seconds apart they will be represented by two separate events in the calendar

Definition at line 59 of file lib.php.

Definition at line 42 of file lib.php.

Definition at line 40 of file lib.php.


Function Documentation

mod_quiz_question_pluginfile ( course,
context,
component,
filearea,
qubaid,
slot,
args,
forcedownload 
)

Called via pluginfile.php -> question_pluginfile to serve files belonging to a question in a question_attempt when that attempt is a quiz attempt.

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.
Returns:
bool false if file not found, does not return if found - justsend the file

Definition at line 1721 of file lib.php.

Here is the call graph for this function:

quiz_add_instance ( quiz)

Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will create a new instance and return the id number of the new instance.

Parameters:
object$quizthe data that came from the form.
Returns:
mixed the id of the new instance on success, false or a string error message on failure.

Definition at line 71 of file lib.php.

Here is the call graph for this function:

This function is called at the end of quiz_add_instance and quiz_update_instance, to do the common processing.

Parameters:
object$quizthe quiz object.

Definition at line 1055 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_attempt_summary_link_to_reports ( quiz,
cm,
context,
returnzero = false,
currentgroup = 0 
)

Returns the same as quiz_num_attempt_summary() but wrapped in a link to the quiz reports.

Parameters:
object$quizthe quiz object. Only $quiz->id is used at the moment.
object$cmthe cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
object$contextthe quiz context.
bool$returnzeroif false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'.
int$currentgroupif there is a concept of current group where this method is being called (e.g. a report) pass it in here. Default 0 which means no current group.
Returns:
string HTML fragment for the link.

Definition at line 1516 of file lib.php.

Here is the call graph for this function:

quiz_check_file_access ( attemptuniqueid,
questionid,
context = null 
)

Checks whether the current user is allowed to view a file uploaded in a quiz. Teachers can view any from their courses, students can only view their own.

Parameters:
int$attemptuniqueidint attempt id
int$questionidint question id
Returns:
bool to indicate access granted or denied

Definition at line 1348 of file lib.php.

Here is the call graph for this function:

quiz_cron ( )

Function to be run periodically according to the moodle cron This function searches for things that need to be done, such as sending out mail, toggling flags etc ...

Definition at line 442 of file lib.php.

Here is the call graph for this function:

Delete all the attempts belonging to a quiz.

Parameters:
object$quizThe quiz object.

Definition at line 313 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Deletes all quiz overrides from the database and clears any corresponding calendar events

Parameters:
object$quizThe quiz object.

Definition at line 201 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Given an ID of an instance of this module, this function will permanently delete the instance and any data that depends on it.

Parameters:
int$idthe id of the quiz to delete.
Returns:
bool success or failure.

Definition at line 148 of file lib.php.

Here is the call graph for this function:

quiz_delete_override ( quiz,
overrideid 
)

Deletes a quiz override from the database and clears any corresponding calendar events

Parameters:
object$quizThe quiz object.
int$overrideidThe id of the override being deleted
Returns:
bool true on success

Definition at line 178 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_extend_navigation ( quiznode,
course,
module,
cm 
)

This fucntion extends the global navigation for the site. It is important to note that you should not rely on PAGE objects within this body of code as there is no guarantee that during an AJAX request they are available

Parameters:
navigation_node$quiznodeThe quiz node within the global navigation
object$courseThe course object returned from the DB
object$moduleThe module object returned from the DB
object$cmThe course module instance returned from the DB

Definition at line 1572 of file lib.php.

Here is the call graph for this function:

quiz_extend_settings_navigation ( settings,
quiznode 
)

This function extends the settings navigation block for the site.

It is safe to rely on PAGE here as we will only ever be within the module context when this is called

Parameters:
settings_navigation$settings
navigation_node$quiznode

Require questionlib.php Included here as we only ever want to include this file if we really need to.

Definition at line 1612 of file lib.php.

Here is the call graph for this function:

quiz_format_grade ( quiz,
grade 
)

Round a grade to to the correct number of decimal places, and format it for display.

Parameters:
object$quizThe quiz table row, only $quiz->decimalpoints is used.
float$gradeThe grade to round.
Returns:
float

Definition at line 543 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_format_question_grade ( quiz,
grade 
)

Round a grade to to the correct number of decimal places, and format it for display.

Parameters:
object$quizThe quiz table row, only $quiz->decimalpoints is used.
float$gradeThe grade to round.
Returns:
float

Definition at line 557 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_get_best_grade ( quiz,
userid 
)

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

Parameters:
object$quizthe quiz settings.
int$useridthe id of the user.
Returns:
float the user's current grade for this quiz, or null if this user does not have a grade on this quiz.

Definition at line 329 of file lib.php.

Returns:
array all other caps used in module

Definition at line 1553 of file lib.php.

Here is the call graph for this function:

quiz_get_participants ( quizid)

Returns an array of users who have data in a given quiz

Todo:
: deprecated - to be deleted in 2.2
Parameters:
int$quizidthe quiz id.
Returns:
array of userids.

Definition at line 733 of file lib.php.

Returns:
array

Definition at line 1222 of file lib.php.

quiz_get_recent_mod_activity ( &$  activities,
&$  index,
timestart,
courseid,
cmid,
userid = 0,
groupid = 0 
)

Returns all quiz graded users since a given time for specified quiz

Definition at line 775 of file lib.php.

Here is the call graph for this function:

quiz_get_user_attempts ( quizid,
userid,
status = 'finished',
includepreviews = false 
)
Parameters:
int$quizidthe quiz id.
int$useridthe userid.
string$status'all', 'finished' or 'unfinished' to control
bool$includepreviews
Returns:
an array of all the user's attempts at this quiz. Returns an empty array if there are none.

Definition at line 486 of file lib.php.

Here is the caller graph for this function:

quiz_get_user_grades ( quiz,
userid = 0 
)

Return grade for given user or all users.

Parameters:
int$quizidid of quiz
int$useridoptional user id, 0 means all users
Returns:
array array of grades, false if none. These are raw grades. They should be processed with quiz_format_grade for display.

Definition at line 510 of file lib.php.

Here is the caller graph for this function:

Returns:
array

Definition at line 1215 of file lib.php.

Delete grade item for given quiz

Parameters:
object$quizobject
Returns:
object quiz

Definition at line 717 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_grade_item_update ( quiz,
grades = null 
)

Create grade item for given quiz

Parameters:
object$quizobject with extra cmidnumber
mixed$gradesoptional array/object of grade(s); 'reset' means reset grades in gradebook
Returns:
int 0 if ok, error code otherwise

Definition at line 630 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_has_grades ( quiz)

Is this a graded quiz? If this method returns true, you can assume that $quiz->grade and $quiz->sumgrades are non-zero (for example, if you want to divide by them).

Parameters:
object$quiza row from the quiz table.
Returns:
bool whether this is a graded quiz.

Definition at line 350 of file lib.php.

Here is the caller graph for this function:

quiz_num_attempt_summary ( quiz,
cm,
returnzero = false,
currentgroup = 0 
)

Return a textual summary of the number of attempts that have been made at a particular quiz, returns '' if no attempts have been made yet, unless $returnzero is passed as true.

Parameters:
object$quizthe quiz object. Only $quiz->id is used at the moment.
object$cmthe cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
bool$returnzeroif false (default), when no attempts have been made '' is returned instead of 'Attempts: 0'.
int$currentgroupif there is a concept of current group where this method is being called (e.g. a report) pass it in here. Default 0 which means no current group.
Returns:
string a string like "Attempts: 123", "Attemtps 123 (45 from your groups)" or "Attemtps 123 (45 from this group)".

Definition at line 1473 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_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 1763 of file lib.php.

quiz_pluginfile ( course,
cm,
context,
filearea,
args,
forcedownload 
)

Serves the quiz files.

Parameters:
object$course
object$cm
object$context
string$filearea
array$args
bool$forcedownload
Returns:
bool false if file not found, does not return if found - justsend the file

Definition at line 1676 of file lib.php.

Here is the call graph for this function:

quiz_print_overview ( courses,
&$  htmlarray 
)

Prints quiz summaries on MyMoodle Page

Parameters:
arry$courses
array$htmlarray

Definition at line 1394 of file lib.php.

Here is the call graph for this function:

quiz_print_recent_mod_activity ( activity,
courseid,
detail,
modnames 
)

Definition at line 893 of file lib.php.

Here is the call graph for this function:

quiz_process_options ( quiz)

Pre-process the quiz options form data, making any necessary adjustments. Called by add/update instance in this file.

Parameters:
object$quizThe variables set on the form.

Definition at line 938 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_questions_in_use ( questionids)
Parameters:
array$questionidsof question ids.
Returns:
bool whether any of these questions are used by any instance of this module.

Definition at line 1231 of file lib.php.

Here is the call graph for this function:

quiz_refresh_events ( courseid = 0)

This standard function will check all instances of this module and make sure there are up-to-date events created for each of them. If courseid = 0, then every quiz event in the site is checked, else only quiz events belonging to the course specified are checked. This function is used, in its new format, by restore_refresh_events()

Parameters:
int$courseid
Returns:
bool

Definition at line 752 of file lib.php.

Here is the call graph for this function:

Course reset form defaults.

Returns:
array the defaults.

Definition at line 1257 of file lib.php.

Implementation of the function for printing the form elements that control whether the course reset functionality affects the quiz.

Parameters:
$mformthe course reset form that is being built.

Definition at line 1247 of file lib.php.

quiz_reset_gradebook ( courseid,
type = '' 
)

Removes all grades from gradebook

Parameters:
int$courseid
stringoptional type

Definition at line 1267 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_reset_userdata ( data)

Actual implementation of the reset course functionality, delete all the quiz attempts for course $data->courseid, if $data->reset_quiz_attempts is set and true.

Also, move the quiz open and close dates, if the course start date is changing.

Parameters:
object$datathe data submitted from the reset course.
Returns:
array status array

Definition at line 1292 of file lib.php.

Here is the call graph for this function:

quiz_review_option_form_to_db ( fromform,
field 
)

Helper function for quiz_process_options().

Parameters:
object$fromformthe sumbitted form date.
string$fieldone of the review option field names.

Definition at line 1029 of file lib.php.

Here is the caller graph for this function:

quiz_supports ( feature)
Parameters:
string$featureFEATURE_xx constant for requested feature
Returns:
bool True if quiz supports feature

Definition at line 1534 of file lib.php.

quiz_update_effective_access ( quiz,
userid 
)

Updates a quiz object with override information for a user.

Algorithm: For each quiz setting, if there is a matching user-specific override, then use that otherwise, if there are group-specific overrides, return the most lenient combination of them. If neither applies, leave the quiz setting unchanged.

Special case: if there is more than one password that applies to the user, then quiz->extrapasswords will contain an array of strings giving the remaining passwords.

Parameters:
object$quizThe quiz object.
int$useridThe userid.
Returns:
object $quiz The updated quiz object.

Definition at line 225 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_update_events ( quiz,
override = null 
)

This function updates the events associated to the quiz. If $override is non-zero, then it updates only the events associated with the specified override.

QUIZ_MAX_EVENT_LENGTH

Parameters:
object$quizthe quiz object.
objectoptional $override limit to a specific override

Definition at line 1101 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_update_grades ( quiz,
userid = 0,
nullifnone = true 
)

Update grades in central gradebook

Parameters:
object$quizthe quiz settings.
int$useridspecific user only, 0 means all users.

Definition at line 574 of file lib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

quiz_update_instance ( quiz,
mform 
)

Given an object containing all the necessary data, (defined by the form in mod_form.php) this function will update an existing instance with new data.

Parameters:
object$quizthe data that came from the form.
Returns:
mixed true on success, false or a string error message on failure.

Definition at line 100 of file lib.php.

Here is the call graph for this function:

Update all grades in gradebook.

Definition at line 598 of file lib.php.

Here is the call graph for this function:

quiz_user_complete ( course,
user,
mod,
quiz 
)

Print a detailed representation of what a user has done with a given particular instance of this module, for user activity reports.

object

Parameters:
object$course
object$user
object$mod
object$quiz
Returns:
bool

Definition at line 405 of file lib.php.

Here is the call graph for this function:

quiz_user_outline ( course,
user,
mod,
quiz 
)

Return a small object with summary information about what a user has done with a given particular instance of this module Used for user activity reports. $return->time = the time they did it $return->info = a short text description

Parameters:
object$course
object$user
object$mod
object$quiz
Returns:
object|null

Definition at line 367 of file lib.php.

Here is the call graph for this function:

 All Data Structures Namespaces Files Functions Variables Enumerations