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

Public Member Functions

 __construct ($quiz, $cm, $course, $getcontext=true)
 preload_questions ()
 load_questions ($questionids=null)
 get_courseid ()
 get_course ()
 get_quizid ()
 get_quiz ()
 get_quiz_name ()
 get_num_attempts_allowed ()
 get_cmid ()
 get_cm ()
 get_context ()
 is_preview_user ()
 has_questions ()
 get_question ($id)
 get_questions ($questionids=null)
 get_access_manager ($timenow)
 has_capability ($capability, $userid=null, $doanything=true)
 require_capability ($capability, $userid=null, $doanything=true)
 view_url ()
 edit_url ()
 attempt_url ($attemptid, $page=0)
 start_attempt_url ($page=0)
 review_url ($attemptid)
 confirm_start_attempt_message ($unfinished)
 cannot_review_message ($when, $short=false)
 navigation ($title)

Static Public Member Functions

static create ($quizid, $userid)

Protected Member Functions

 ensure_question_loaded ($id)

Protected Attributes

 $course
 $cm
 $quiz
 $context
 $questionids
 $questions = null
 $accessmanager = null
 $ispreviewuser = null

Detailed Description

A class encapsulating a quiz and the questions it contains, and making the information available to scripts like view.php.

Initially, it only loads a minimal amout of information about each question - loading extra information only when necessary or when asked. The class tracks which questions are loaded.

Since:
Moodle 2.0

Definition at line 63 of file attemptlib.php.


Constructor & Destructor Documentation

__construct ( quiz,
cm,
course,
getcontext = true 
)

Constructor, assuming we already have the necessary data loaded.

Parameters:
object$quizthe row from the quiz table.
object$cmthe course_module object for this quiz.
object$coursethe row from the course table for the course we belong to.
bool$getcontextintended for testing - stops the constructor getting the context.

Definition at line 85 of file attemptlib.php.

Here is the call graph for this function:


Member Function Documentation

attempt_url ( attemptid,
page = 0 
)
Parameters:
int$attemptidthe id of an attempt.
int$pageoptional page number to go to in the attempt.
Returns:
string the URL of that attempt.

Definition at line 294 of file attemptlib.php.

cannot_review_message ( when,
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:
int$whenOne of the mod_quiz_display_options::DURING, IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.
bool$shortif true, return a shorter string.
Returns:
string an appropraite message.

Definition at line 354 of file attemptlib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

confirm_start_attempt_message ( unfinished)
Parameters:
bool$unfinishedwhether there is currently an unfinished attempt active.
Returns:
string if the quiz policies merit it, return a warning string to be displayed in a javascript alert on the start attempt button.

Definition at line 329 of file attemptlib.php.

static create ( quizid,
userid 
) [static]

Static function to create a new quiz object for a specific user.

Parameters:
int$quizidthe the quiz id.
int$useridthe the userid.
Returns:
quiz the new quiz object

Definition at line 108 of file attemptlib.php.

Here is the call graph for this function:

edit_url ( )
Returns:
string the URL of this quiz's edit page.

Definition at line 284 of file attemptlib.php.

Here is the caller graph for this function:

ensure_question_loaded ( id) [protected]

Check that the definition of a particular question is loaded, and if not throw an exception.

Parameters:
$ida questionid.

Definition at line 392 of file attemptlib.php.

Here is the caller 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 250 of file attemptlib.php.

Here is the call graph for this function:

get_cm ( )
Returns:
object the course_module object.

Definition at line 192 of file attemptlib.php.

Here is the caller graph for this function:

get_cmid ( )
Returns:
int the course_module id.

Definition at line 187 of file attemptlib.php.

Returns:
object the module context for this quiz.

Definition at line 197 of file attemptlib.php.

Returns:
object the row of the course table.

Definition at line 162 of file attemptlib.php.

Returns:
int the course id.

Definition at line 157 of file attemptlib.php.

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

Definition at line 182 of file attemptlib.php.

Here is the caller graph for this function:

get_question ( id)
Parameters:
int$idthe question id.
Returns:
object the question object with that id.

Definition at line 223 of file attemptlib.php.

get_questions ( questionids = null)
Parameters:
array$questionidsquestion ids of the questions to load. null for all.

Definition at line 230 of file attemptlib.php.

Here is the call graph for this function:

get_quiz ( )
Returns:
object the row of the quiz table.

Definition at line 172 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
string the name of this quiz.

Definition at line 177 of file attemptlib.php.

Returns:
int the quiz id.

Definition at line 167 of file attemptlib.php.

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

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

Definition at line 261 of file attemptlib.php.

Here is the caller graph for this function:

Returns:
whether any questions have been added to this quiz.

Definition at line 215 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 205 of file attemptlib.php.

Here is the call graph for this function:

load_questions ( questionids = null)

Fully load some or all of the questions for this quiz. You must call preload_questions() first.

Parameters:
array$questionidsquestion ids of the questions to load. null for all.

Definition at line 142 of file attemptlib.php.

Here is the call graph for this function:

navigation ( title)
Parameters:
string$titlethe name of this particular quiz page.
Returns:
array the data that needs to be sent to print_header_simple as the $navigation parameter.

Definition at line 381 of file attemptlib.php.

Load just basic information about all the questions in this quiz.

Definition at line 126 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 268 of file attemptlib.php.

review_url ( attemptid)
Parameters:
int$attemptidthe id of an attempt.
Returns:
string the URL of the review of that attempt.

Definition at line 318 of file attemptlib.php.

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

Definition at line 306 of file attemptlib.php.

Here is the call graph for this function:

view_url ( )
Returns:
string the URL of this quiz's view page.

Definition at line 276 of file attemptlib.php.

Here is the caller graph for this function:


Field Documentation

$accessmanager = null [protected]

Definition at line 73 of file attemptlib.php.

$cm [protected]

Definition at line 66 of file attemptlib.php.

$context [protected]

Definition at line 68 of file attemptlib.php.

$course [protected]

Definition at line 65 of file attemptlib.php.

$ispreviewuser = null [protected]

Definition at line 74 of file attemptlib.php.

$questionids [protected]

Definition at line 69 of file attemptlib.php.

$questions = null [protected]

Definition at line 72 of file attemptlib.php.

$quiz [protected]

Definition at line 67 of file attemptlib.php.


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