Quiz1Repository
in package
Load and persist Quiz1 semantic records. Does not know about QTI XML.
Table of Contents
Methods
- acceptableLinkKey() : mixed
- adoptLinkKey() : mixed
- Point this quiz's link at $key when that key is free in the course.
- allocateLinkKey() : mixed
- Link key for a quiz created from now on. Not the primary key, and no ":", so the cartridge item identifier can be this string.
- appendQuestions() : array{0: int, 1: string[]}
- Append questions to an existing quiz (sequence continues after the last item).
- cartridgeIdentifierForLinkKey() : mixed
- Cartridge item identifier for this resource link id.
- deleteQuestion() : mixed
- deleteQuiz() : mixed
- ensureLink() : int|null
- The quiz's one lti_link. A new quiz gets this row unpublished.
- insertQuestion() : mixed
- insertQuiz() : mixed
- isLegacyLinkKey() : mixed
- True for the legacy quiz1:{quiz_id} form. A newer key is quiz1_k plus hex.
- isQuizLinkKey() : mixed
- True when this resource link id belongs to a quiz, including a legacy quiz1:{id} and a key minted as quiz1_k plus hex.
- linkKey() : mixed
- Legacy link key quiz1:{quiz_id}. Rows already stored this way keep it.
- linkKeyFromCartridgeIdentifier() : mixed
- Resource link id carried by a quiz item or resource identifier.
- listForContext() : array<string|int, Quiz1>
- load() : Quiz1|null
- loadByLink() : Quiz1|null
- The quiz whose launch link is $link_id in this course.
- loadQuestion() : Question|null
- loadQuestions() : array<string|int, Question>
- moveQuestion() : mixed
- publish() : int|null
- Mark the quiz's link published. The link already exists for a quiz created now.
- quizIdByLinkKey() : mixed
- Quiz in this course whose link uses $key, or 0.
- resourceLinkId() : mixed
- Resource link id lessons and the grade book use for this quiz.
- storedLinkKey() : mixed
- link_key stored on this quiz's link, or '' when it has no link.
- unpublish() : bool
- Soft-unpublish. The link row and quiz1_quiz.link_id stay.
- updateQuestion() : mixed
- updateQuizMeta() : mixed
- linkIdByKey() : mixed
- needsHexCartridgeId() : mixed
- A key that contains _colon_, ends in _R, or already looks like an rlhex_ encoding is stored as hex so those forms cannot import as each other.
- newLinkKey() : mixed
- Preferred key when it is free in this course, otherwise a new allocated key.
- questionFromRow() : mixed
- renumber() : mixed
- replaceAnswers() : mixed
- touchQuiz() : mixed
Methods
acceptableLinkKey()
public
static acceptableLinkKey(mixed $key) : mixed
Parameters
- $key : mixed
adoptLinkKey()
Point this quiz's link at $key when that key is free in the course.
public
static adoptLinkKey(int|string $quiz_id, int|string $context_id, mixed $key) : mixed
Import uses this so the new course keeps the source course's resource link id. A taken key is left alone. Returns the key stored afterward.
Parameters
- $quiz_id : int|string
- $context_id : int|string
- $key : mixed
allocateLinkKey()
Link key for a quiz created from now on. Not the primary key, and no ":", so the cartridge item identifier can be this string.
public
static allocateLinkKey() : mixed
appendQuestions()
Append questions to an existing quiz (sequence continues after the last item).
public
static appendQuestions(mixed $quiz_id, array<string|int, Question> $questions) : array{0: int, 1: string[]}
Best-effort: a failure on one question is recorded and the rest still save. A partial quiz is the intended outcome, not a rollback.
Parameters
- $quiz_id : mixed
- $questions : array<string|int, Question>
Return values
array{0: int, 1: string[]} —Inserted count and per-question errors
cartridgeIdentifierForLinkKey()
Cartridge item identifier for this resource link id.
public
static cartridgeIdentifierForLinkKey(mixed $linkKey) : mixed
":" is written as colon because an XML identifier cannot contain ":". A key that already contains the letters colon, or that ends in R, is stored as rlhex plus hex. Import would otherwise turn colon into ":" or drop a trailing _R that belongs to the id. Other underscores stay underscores. A key that is already a safe identifier, such as quiz1_k… or Q1_ca934192ea441d46, is kept.
Parameters
- $linkKey : mixed
deleteQuestion()
public
static deleteQuestion(mixed $question_id, mixed $context_id) : mixed
Parameters
- $question_id : mixed
- $context_id : mixed
deleteQuiz()
public
static deleteQuiz(mixed $quiz_id, mixed $context_id) : mixed
Parameters
- $quiz_id : mixed
- $context_id : mixed
ensureLink()
The quiz's one lti_link. A new quiz gets this row unpublished.
public
static ensureLink(mixed $quiz_id, mixed $context_id[, string|null $preferredKey = null ]) : int|null
The new row's key is not the quiz id. An existing row is left as stored.
Parameters
- $quiz_id : mixed
- $context_id : mixed
- $preferredKey : string|null = null
-
Import: the source course's resource link id, when it is free
Return values
int|null —link_id, or null when the quiz is not in this context
insertQuestion()
public
static insertQuestion(Question $question) : mixed
Parameters
- $question : Question
insertQuiz()
public
static insertQuiz(Quiz1 $quiz[, string|null $linkKey = null ]) : mixed
Parameters
- $quiz : Quiz1
- $linkKey : string|null = null
-
Cartridge resource link id to store on the new link. quiz1:42 is that id even when this row's quiz_id is not 42. Null mints a key that is not the primary key.
isLegacyLinkKey()
True for the legacy quiz1:{quiz_id} form. A newer key is quiz1_k plus hex.
public
static isLegacyLinkKey(mixed $key) : mixed
Parameters
- $key : mixed
isQuizLinkKey()
True when this resource link id belongs to a quiz, including a legacy quiz1:{id} and a key minted as quiz1_k plus hex.
public
static isQuizLinkKey(mixed $key) : mixed
Parameters
- $key : mixed
linkKey()
Legacy link key quiz1:{quiz_id}. Rows already stored this way keep it.
public
static linkKey(mixed $quiz_id) : mixed
A quiz with no link yet is still addressed this way until ensureLink runs.
Parameters
- $quiz_id : mixed
linkKeyFromCartridgeIdentifier()
Resource link id carried by a quiz item or resource identifier.
public
static linkKeyFromCartridgeIdentifier(mixed $identifier) : mixed
rlhex_ is the exact key, decoded before colon becomes ":". A plain underscore is left alone, so quiz1_k… and Q1_ca934192ea441d46 stay those strings. A resource identifier's trailing _R is the cartridge suffix, not part of the id.
Parameters
- $identifier : mixed
listForContext()
public
static listForContext(mixed $context_id) : array<string|int, Quiz1>
Parameters
- $context_id : mixed
Return values
array<string|int, Quiz1>load()
public
static load(mixed $quiz_id, mixed $context_id) : Quiz1|null
Parameters
- $quiz_id : mixed
- $context_id : mixed
Return values
Quiz1|nullloadByLink()
The quiz whose launch link is $link_id in this course.
public
static loadByLink(mixed $link_id, mixed $context_id) : Quiz1|null
Parameters
- $link_id : mixed
- $context_id : mixed
Return values
Quiz1|nullloadQuestion()
public
static loadQuestion(mixed $question_id, mixed $context_id) : Question|null
Parameters
- $question_id : mixed
- $context_id : mixed
Return values
Question|nullloadQuestions()
public
static loadQuestions(mixed $quiz_id) : array<string|int, Question>
Parameters
- $quiz_id : mixed
Return values
array<string|int, Question>moveQuestion()
public
static moveQuestion(mixed $question_id, mixed $context_id, mixed $direction) : mixed
Parameters
- $question_id : mixed
- $context_id : mixed
- $direction : mixed
publish()
Mark the quiz's link published. The link already exists for a quiz created now.
public
static publish(mixed $quiz_id, mixed $context_id) : int|null
Parameters
- $quiz_id : mixed
- $context_id : mixed
Return values
int|null —link_id, or null when the quiz is not in this context
quizIdByLinkKey()
Quiz in this course whose link uses $key, or 0.
public
static quizIdByLinkKey(int|string $context_id, mixed $key) : mixed
Parameters
- $context_id : int|string
- $key : mixed
resourceLinkId()
Resource link id lessons and the grade book use for this quiz.
public
static resourceLinkId(int|string $quiz_id, int|string $context_id) : mixed
The stored key wins. A quiz with no link yet still uses quiz1:{id}, unless that legacy key already belongs to a different quiz.
Parameters
- $quiz_id : int|string
- $context_id : int|string
storedLinkKey()
link_key stored on this quiz's link, or '' when it has no link.
public
static storedLinkKey(int|string $quiz_id, int|string $context_id) : mixed
Parameters
- $quiz_id : int|string
- $context_id : int|string
unpublish()
Soft-unpublish. The link row and quiz1_quiz.link_id stay.
public
static unpublish(mixed $quiz_id, mixed $context_id) : bool
Parameters
- $quiz_id : mixed
- $context_id : mixed
Return values
bool —False when the quiz has never been published or is not in this context.
updateQuestion()
public
static updateQuestion(Question $question) : mixed
Parameters
- $question : Question
updateQuizMeta()
public
static updateQuizMeta(Quiz1 $quiz) : mixed
Parameters
- $quiz : Quiz1
linkIdByKey()
private
static linkIdByKey(int $context_id, string $link_key) : mixed
Parameters
- $context_id : int
- $link_key : string
needsHexCartridgeId()
A key that contains _colon_, ends in _R, or already looks like an rlhex_ encoding is stored as hex so those forms cannot import as each other.
private
static needsHexCartridgeId(string $linkKey) : mixed
Parameters
- $linkKey : string
newLinkKey()
Preferred key when it is free in this course, otherwise a new allocated key.
private
static newLinkKey(mixed $context_id, mixed $preferredKey) : mixed
Parameters
- $context_id : mixed
- $preferredKey : mixed
questionFromRow()
private
static questionFromRow(array<string|int, mixed> $row) : mixed
Parameters
- $row : array<string|int, mixed>
renumber()
private
static renumber(mixed $quiz_id) : mixed
Parameters
- $quiz_id : mixed
replaceAnswers()
private
static replaceAnswers(Question $question) : mixed
Parameters
- $question : Question
touchQuiz()
private
static touchQuiz(mixed $quiz_id) : mixed
Parameters
- $quiz_id : mixed