Functions

Add a quiz.

add_quiz(\SHORT_TEXT $name, \?integer $timeout, \LONG_TEXT $start_text, \LONG_TEXT $end_text, \LONG_TEXT $end_text_fail, \LONG_TEXT $notes, integer $percentage, \?TIME $open_time, \?TIME $close_time, integer $num_winners, integer $redo_time, \ID_TEXT $type, \BINARY $validated, string $text, \?MEMBER $submitter = null, integer $points_for_passing = 0, \?AUTO_LINK $tied_newsletter = null, \BINARY $reveal_answers = 0, \BINARY $shuffle_questions = 0, \BINARY $shuffle_answers = 0, \?TIME $add_time = null, \?SHORT_TEXT $meta_keywords = '', \?LONG_TEXT $meta_description = '') : \AUTO_LINK
package quizzes
set SURVEY COMPETITION TEST

Parameters

$name

\SHORT_TEXT

The name of the quiz

$timeout

\?integer

The number of minutes allowed for completion (null: NA)

$start_text

\LONG_TEXT

The text shown at the start of the quiz

$end_text

\LONG_TEXT

The text shown at the end of the quiz

$end_text_fail

\LONG_TEXT

The text shown at the end of the quiz on failure

$notes

\LONG_TEXT

Notes

$percentage

integer

Percentage correctness required for competition

$open_time

\?TIME

The time the quiz is opened (null: now)

$close_time

\?TIME

The time the quiz is closed (null: never)

$num_winners

integer

The number of winners for this if it is a competition

$redo_time

integer

The minimum number of hours between attempts

$type

\ID_TEXT

The type

$validated

\BINARY

Whether this is validated

$text

string

Text for questions

$submitter

\?MEMBER

The member adding it (null: current member)

$points_for_passing

integer

The number of points awarded for completing/passing the quiz/test

$tied_newsletter

\?AUTO_LINK

Newsletter for which a member must be on to enter (null: none)

$reveal_answers

\BINARY

Whether to reveal correct answers after the quiz is complete, so that the answerer can learn from the experience

$shuffle_questions

\BINARY

Whether to shuffle questions, to make cheating a bit harder

$shuffle_answers

\BINARY

Whether to shuffle multiple-choice answers, to make cheating a bit harder

$add_time

\?TIME

The add time (null: now)

$meta_keywords

\?SHORT_TEXT

Meta keywords for this resource (null: do not edit) (blank: implicit)

$meta_description

\?LONG_TEXT

Meta description for this resource (null: do not edit) (blank: implicit)

Returns

\AUTO_LINKThe ID

Delete a quiz.

delete_quiz(\AUTO_LINK $id) 
package quizzes

Parameters

$id

\AUTO_LINK

The ID

Edit a quiz.

edit_quiz(\AUTO_LINK $id, \SHORT_TEXT $name, \?integer $timeout, \LONG_TEXT $start_text, \LONG_TEXT $end_text, \LONG_TEXT $end_text_fail, \LONG_TEXT $notes, integer $percentage, \?TIME $open_time, \?TIME $close_time, integer $num_winners, integer $redo_time, \ID_TEXT $type, \BINARY $validated, string $text, \SHORT_TEXT $meta_keywords, \LONG_TEXT $meta_description, integer $points_for_passing = 0, \?AUTO_LINK $tied_newsletter = null, \BINARY $reveal_answers = 0, \BINARY $shuffle_questions = 0, \BINARY $shuffle_answers = 0, \?TIME $add_time = null, \?MEMBER $submitter = null, boolean $null_is_literal = false
package quizzes
set SURVEY COMPETITION TEST

Parameters

$id

\AUTO_LINK

The ID

$name

\SHORT_TEXT

The name of the quiz

$timeout

\?integer

The number of minutes allowed for completion (null: NA)

$start_text

\LONG_TEXT

The text shown at the start of the quiz

$end_text

\LONG_TEXT

The text shown at the end of the quiz

$end_text_fail

\LONG_TEXT

The text shown at the end of the quiz on failure

$notes

\LONG_TEXT

Notes

$percentage

integer

Percentage correctness required for competition

$open_time

\?TIME

The time the quiz is opened (null: now)

$close_time

\?TIME

The time the quiz is closed (null: never)

$num_winners

integer

The number of winners for this if it is a competition

$redo_time

integer

The minimum number of hours between attempts

$type

\ID_TEXT

The type

$validated

\BINARY

Whether this is validated

$text

string

Text for questions

$meta_keywords

\SHORT_TEXT

Meta keywords

$meta_description

\LONG_TEXT

Meta description

$points_for_passing

integer

The number of points awarded for completing/passing the quiz/test

$tied_newsletter

\?AUTO_LINK

Newsletter for which a member must be on to enter (null: none)

$reveal_answers

\BINARY

Whether to reveal correct answers after the quiz is complete, so that the answerer can learn from the experience

$shuffle_questions

\BINARY

Whether to shuffle questions, to make cheating a bit harder

$shuffle_answers

\BINARY

Whether to shuffle multiple-choice answers, to make cheating a bit harder

$add_time

\?TIME

Add time (null: do not change)

$submitter

\?MEMBER

Submitter (null: do not change)

$null_is_literal

boolean

Determines whether some NULLs passed mean 'use a default' or literally mean 'set to NULL'

Get quiz data for exporting it as a CSV.

get_quiz_data_for_csv(\AUTO_LINK $quiz_id) : array
package quizzes

Parameters

$quiz_id

\AUTO_LINK

Quiz ID

Returns

arrayQuiz data array

Load the questions for a quiz into a single string.

load_quiz_questions_to_string(\AUTO_LINK $id) : string
package quizzes

Parameters

$id

\AUTO_LINK

The quiz ID

Returns

stringThe text string

Parse a quiz question line, to find the question options.

parse_quiz_question_line(string $question, array $answers, string $question_extra_text = '', boolean $do_validation = true) : array
package quizzes

Parameters

$question

string

The quiz question line

$answers

array

List of possible answers (used for validation purposes)

$question_extra_text

string

The quiz question description

$do_validation

boolean

Whether to perform validation / corrections

Returns

arrayA tuple: Question, question type, required?, marked?, question extra text (description)

Get quiz data for exporting it as CSV.

render_quiz(array $questions) : \Tempcode
package quizzes

Parameters

$questions

array

The quiz questions

Returns

\TempcodeThe rendered quiz

Show a quiz box.

render_quiz_box(array $row, string $zone = '_SEARCH', boolean $give_context = true, \ID_TEXT $guid = '') : \Tempcode
package quizzes

Parameters

$row

array

The database row

$zone

string

The zone to show in

$give_context

boolean

Whether to include context (i.e. say WHAT this is, not just show the actual content)

$guid

\ID_TEXT

Overridden GUID to send to templates (blank: none)

Returns

\TempcodeThe rendered quiz link

Score a particular quiz entry.

score_quiz(\AUTO_LINK $entry_id, \?AUTO_LINK $quiz_id = null, \?array $quiz = null, \?array $questions = null, boolean $reveal_all = false) : array
package quizzes

Parameters

$entry_id

\AUTO_LINK

Entry ID

$quiz_id

\?AUTO_LINK

Quiz ID (null: look up from entry ID)

$quiz

\?array

Quiz row (null: look up from entry ID)

$questions

\?array

Question rows (null: look up from entry ID)

$reveal_all

boolean

Whether to show answers, regardless of whether the quiz is set to do so

Returns

arrayA tuple of quiz result details

Is a typed quiz answer correct?

typed_answer_is_correct(string $given_answer, array $all_answers, boolean $strict = false) : boolean
package quizzes

Parameters

$given_answer

string

The given (typed) answer

$all_answers

array

Answer rows

$strict

boolean

Whether to do a strict check

Returns

booleanWhether it is correct