Documentation

QuizSubmission extends AbstractBaseApi
in package

Canvas LMS Quiz Submissions API

Provides functionality to manage quiz submissions and attempts in Canvas LMS. This class handles creating, reading, updating quiz submissions for a specific quiz.

Usage Examples:

// Set course and quiz context (required for all operations)
$course = Course::find(123);
$quiz = Quiz::find(456);
QuizSubmission::setCourse($course);
QuizSubmission::setQuiz($quiz);

// Start a new quiz submission
$submission = QuizSubmission::start(['access_code' => 'secret123']);

// Get current user's submission
$submission = QuizSubmission::getCurrentUserSubmission();

// List all submissions for the quiz
$submissions = QuizSubmission::fetchAll();

// Get submissions with specific parameters
$submissions = QuizSubmission::fetchAll(['include' => ['user', 'quiz']]);

// Find specific submission
$submission = QuizSubmission::find(789);

// Update submission scores manually
$updatedSubmission = QuizSubmission::update(789, [
    'fudge_points' => 2.5,
    'quiz_submissions' => [
        ['attempt' => 1, 'fudge_points' => 2.5]
    ]
]);

// Complete a submission
$submission = QuizSubmission::find(789);
$success = $submission->complete();

// Check submission state
if ($submission->isComplete()) {
    echo "Submission completed with score: " . $submission->getScore();
}

Table of Contents

Properties

$attempt  : int|null
Attempt number (1-based)
$endAt  : string|null
When the submission will end (time limit)
$extraAttempts  : int|null
Extra attempts allowed for this user
$extraTime  : int|null
Extra time allowed for this user (in minutes)
$finishedAt  : string|null
When the submission was finished
$fudgePoints  : float|null
Fudge points added to the score
$hasSeenResults  : bool|null
Whether user has seen the results
$id  : int|null
Quiz submission unique identifier
$keptScore  : float|null
Score kept after regrade
$manuallyUnlocked  : bool|null
Whether submission was manually unlocked
$overdueAndNeedsSubmission  : bool|null
Whether submission is overdue and needs submission
$quizData  : array<string|int, mixed>|null
Associated quiz data (when included)
$quizId  : int|null
Quiz ID this submission belongs to
$score  : float|null
Current score for the submission
$scoreBeforeRegrade  : float|null
Score before any regrade
$startedAt  : string|null
When the submission was started
$submission  : array<string|int, mixed>|null
Associated submission data (when included)
$submissionId  : int|null
Associated submission ID
$timeSpent  : int|null
Time spent on the quiz (in seconds)
$user  : array<string|int, mixed>|null
Associated user data (when included)
$userId  : int|null
User ID who made the submission
$validationToken  : string|null
Validation token for submission completion
$workflowState  : string|null
Workflow state (untaken, pending_review, complete, settings_only, preview)
$apiClient  : HttpClientInterface
$course  : Course
$methodAliases  : array<string|int, mixed>
Define method aliases
$quiz  : Quiz

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
BaseApi constructor.
canBeRetaken()  : bool
Check if submission can be retaken
complete()  : bool
Complete a quiz submission
create()  : self
fetchAll()  : array<string|int, self>
Fetch all quiz submissions for the quiz
fetchAllPages()  : array<string|int, self>
Fetch all pages of quiz submissions
fetchAllPaginated()  : PaginatedResponse
Fetch paginated quiz submissions
fetchPage()  : PaginationResult
Fetch a single page of quiz submissions
find()  : self
Find a specific quiz submission by ID
getAttempt()  : int|null
Get attempt number
getCurrentUserSubmission()  : self|null
Get current user's submission for the quiz
getEndAt()  : string|null
Get end at timestamp
getExtraAttempts()  : int|null
Get extra attempts
getExtraTime()  : int|null
Get extra time in minutes
getFinishedAt()  : string|null
Get finished at timestamp
getFudgePoints()  : float|null
Get fudge points
getHasSeenResults()  : bool|null
Get has seen results status
getId()  : int|null
Get quiz submission ID
getKeptScore()  : float|null
Get kept score
getManuallyUnlocked()  : bool|null
Get manually unlocked status
getOverdueAndNeedsSubmission()  : bool|null
Get overdue and needs submission status
getQuizData()  : array<string|int, mixed>|null
Get associated quiz data
getQuizId()  : int|null
Get quiz ID
getRemainingTime()  : int|null
Get remaining time in seconds
getScore()  : float|null
Get current score
getScoreBeforeRegrade()  : float|null
Get score before regrade
getStartedAt()  : string|null
Get started at timestamp
getSubmission()  : array<string|int, mixed>|null
Get associated submission data
getSubmissionId()  : int|null
Get submission ID
getTimeSpent()  : int|null
Get time spent in seconds
getUser()  : array<string|int, mixed>|null
Get associated user data
getUserId()  : int|null
Get user ID
getValidationToken()  : string|null
Get validation token
getWorkflowState()  : string|null
Get workflow state
hasTimeLimit()  : bool
Check if quiz has time limit
isComplete()  : bool
Check if submission is complete
isInProgress()  : bool
Check if submission is in progress
isOverdue()  : bool
Check if submission is overdue
save()  : bool
Save the quiz submission (update if exists)
setApiClient()  : void
Set the API client
setAttempt()  : void
Set attempt number
setCourse()  : void
Set the course context for quiz submissions
setEndAt()  : void
Set end at timestamp
setExtraAttempts()  : void
Set extra attempts
setExtraTime()  : void
Set extra time in minutes
setFinishedAt()  : void
Set finished at timestamp
setFudgePoints()  : void
Set fudge points
setHasSeenResults()  : void
Set has seen results status
setId()  : void
Set quiz submission ID
setKeptScore()  : void
Set kept score
setManuallyUnlocked()  : void
Set manually unlocked status
setOverdueAndNeedsSubmission()  : void
Set overdue and needs submission status
setQuiz()  : void
Set the quiz context for quiz submissions
setQuizData()  : void
Set associated quiz data
setQuizId()  : void
Set quiz ID
setScore()  : void
Set current score
setScoreBeforeRegrade()  : void
Set score before regrade
setStartedAt()  : void
Set started at timestamp
setSubmission()  : void
Set associated submission data
setSubmissionId()  : void
Set submission ID
setTimeSpent()  : void
Set time spent in seconds
setUser()  : void
Set associated user data
setUserId()  : void
Set user ID
setValidationToken()  : void
Set validation token
setWorkflowState()  : void
Set workflow state
start()  : self
Start a quiz submission (alias for create)
toArray()  : array<string|int, mixed>
Convert quiz submission to array
toDtoArray()  : array<string|int, mixed>
Convert quiz submission to DTO-compatible array
update()  : self
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
checkContext()  : bool
Check if both course and quiz contexts are set
checkCourse()  : bool
Check if course context is set
checkQuiz()  : bool
Check if quiz context is set
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
fetchAllPagesAsModels()  : array<string|int, static>
Helper method to fetch all pages and convert to model instances
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data

Properties

$attempt

Attempt number (1-based)

public int|null $attempt = null

$endAt

When the submission will end (time limit)

public string|null $endAt = null

$extraAttempts

Extra attempts allowed for this user

public int|null $extraAttempts = null

$extraTime

Extra time allowed for this user (in minutes)

public int|null $extraTime = null

$finishedAt

When the submission was finished

public string|null $finishedAt = null

$fudgePoints

Fudge points added to the score

public float|null $fudgePoints = null

$hasSeenResults

Whether user has seen the results

public bool|null $hasSeenResults = null

$id

Quiz submission unique identifier

public int|null $id = null

$keptScore

Score kept after regrade

public float|null $keptScore = null

$manuallyUnlocked

Whether submission was manually unlocked

public bool|null $manuallyUnlocked = null

$overdueAndNeedsSubmission

Whether submission is overdue and needs submission

public bool|null $overdueAndNeedsSubmission = null

$quizData

Associated quiz data (when included)

public array<string|int, mixed>|null $quizData = null

$quizId

Quiz ID this submission belongs to

public int|null $quizId = null

$score

Current score for the submission

public float|null $score = null

$scoreBeforeRegrade

Score before any regrade

public float|null $scoreBeforeRegrade = null

$startedAt

When the submission was started

public string|null $startedAt = null

$submission

Associated submission data (when included)

public array<string|int, mixed>|null $submission = null

$submissionId

Associated submission ID

public int|null $submissionId = null

$timeSpent

Time spent on the quiz (in seconds)

public int|null $timeSpent = null

$user

Associated user data (when included)

public array<string|int, mixed>|null $user = null

$userId

User ID who made the submission

public int|null $userId = null

$validationToken

Validation token for submission completion

public string|null $validationToken = null

$workflowState

Workflow state (untaken, pending_review, complete, settings_only, preview)

public string|null $workflowState = null

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['fetchAll' => ['all', 'get', 'getAll'], 'find' => ['one', 'getOne'], 'fetchAllPaginated' => ['allPaginated', 'getPaginated'], 'fetchAllPages' => ['allPages', 'getPages'], 'fetchPage' => ['page', 'getPage']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>

__construct()

BaseApi constructor.

public __construct(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

canBeRetaken()

Check if submission can be retaken

public canBeRetaken() : bool
Return values
bool

complete()

Complete a quiz submission

public complete() : bool
Tags
throws
CanvasApiException

If no ID set

Return values
bool

True if completed successfully, false on API error

fetchAll()

Fetch all quiz submissions for the quiz

public static fetchAll([array<string|int, mixed> $params = [] ]) : array<string|int, self>
Parameters
$params : array<string|int, mixed> = []

Optional parameters for filtering

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
array<string|int, self>

Array of quiz submission instances

fetchAllPages()

Fetch all pages of quiz submissions

public static fetchAllPages([array<string|int, mixed> $params = [] ]) : array<string|int, self>
Parameters
$params : array<string|int, mixed> = []

Optional parameters for filtering

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
array<string|int, self>

Array of all quiz submission instances

fetchAllPaginated()

Fetch paginated quiz submissions

public static fetchAllPaginated([array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$params : array<string|int, mixed> = []

Optional parameters for filtering

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
PaginatedResponse

Paginated response instance

fetchPage()

Fetch a single page of quiz submissions

public static fetchPage([array<string|int, mixed> $params = [] ]) : PaginationResult
Parameters
$params : array<string|int, mixed> = []

Optional parameters for filtering

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
PaginationResult

Pagination result with submissions

find()

Find a specific quiz submission by ID

public static find(int $id) : self
Parameters
$id : int

Quiz submission ID

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
self

Quiz submission instance

getAttempt()

Get attempt number

public getAttempt() : int|null
Return values
int|null

getCurrentUserSubmission()

Get current user's submission for the quiz

public static getCurrentUserSubmission() : self|null
Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
self|null

Quiz submission instance or null if no submission

getEndAt()

Get end at timestamp

public getEndAt() : string|null
Return values
string|null

getExtraAttempts()

Get extra attempts

public getExtraAttempts() : int|null
Return values
int|null

getExtraTime()

Get extra time in minutes

public getExtraTime() : int|null
Return values
int|null

getFinishedAt()

Get finished at timestamp

public getFinishedAt() : string|null
Return values
string|null

getFudgePoints()

Get fudge points

public getFudgePoints() : float|null
Return values
float|null

getHasSeenResults()

Get has seen results status

public getHasSeenResults() : bool|null
Return values
bool|null

getId()

Get quiz submission ID

public getId() : int|null
Return values
int|null

getKeptScore()

Get kept score

public getKeptScore() : float|null
Return values
float|null

getManuallyUnlocked()

Get manually unlocked status

public getManuallyUnlocked() : bool|null
Return values
bool|null

getOverdueAndNeedsSubmission()

Get overdue and needs submission status

public getOverdueAndNeedsSubmission() : bool|null
Return values
bool|null

getQuizData()

Get associated quiz data

public getQuizData() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getQuizId()

Get quiz ID

public getQuizId() : int|null
Return values
int|null

getRemainingTime()

Get remaining time in seconds

public getRemainingTime() : int|null
Return values
int|null

getScore()

Get current score

public getScore() : float|null
Return values
float|null

getScoreBeforeRegrade()

Get score before regrade

public getScoreBeforeRegrade() : float|null
Return values
float|null

getStartedAt()

Get started at timestamp

public getStartedAt() : string|null
Return values
string|null

getSubmission()

Get associated submission data

public getSubmission() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getSubmissionId()

Get submission ID

public getSubmissionId() : int|null
Return values
int|null

getTimeSpent()

Get time spent in seconds

public getTimeSpent() : int|null
Return values
int|null

getUser()

Get associated user data

public getUser() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getUserId()

Get user ID

public getUserId() : int|null
Return values
int|null

getValidationToken()

Get validation token

public getValidationToken() : string|null
Return values
string|null

getWorkflowState()

Get workflow state

public getWorkflowState() : string|null
Return values
string|null

hasTimeLimit()

Check if quiz has time limit

public hasTimeLimit() : bool
Return values
bool

isComplete()

Check if submission is complete

public isComplete() : bool
Return values
bool

isInProgress()

Check if submission is in progress

public isInProgress() : bool
Return values
bool

isOverdue()

Check if submission is overdue

public isOverdue() : bool
Return values
bool

save()

Save the quiz submission (update if exists)

public save() : bool
Tags
throws
CanvasApiException

If no ID set or validation fails

Return values
bool

True if saved successfully, false on API error

setAttempt()

Set attempt number

public setAttempt(int|null $attempt) : void
Parameters
$attempt : int|null

setCourse()

Set the course context for quiz submissions

public static setCourse(Course $course) : void
Parameters
$course : Course

The course instance

setEndAt()

Set end at timestamp

public setEndAt(string|null $endAt) : void
Parameters
$endAt : string|null

setExtraAttempts()

Set extra attempts

public setExtraAttempts(int|null $extraAttempts) : void
Parameters
$extraAttempts : int|null

setExtraTime()

Set extra time in minutes

public setExtraTime(int|null $extraTime) : void
Parameters
$extraTime : int|null

setFinishedAt()

Set finished at timestamp

public setFinishedAt(string|null $finishedAt) : void
Parameters
$finishedAt : string|null

setFudgePoints()

Set fudge points

public setFudgePoints(float|null $fudgePoints) : void
Parameters
$fudgePoints : float|null

setHasSeenResults()

Set has seen results status

public setHasSeenResults(bool|null $hasSeenResults) : void
Parameters
$hasSeenResults : bool|null

setId()

Set quiz submission ID

public setId(int|null $id) : void
Parameters
$id : int|null

setKeptScore()

Set kept score

public setKeptScore(float|null $keptScore) : void
Parameters
$keptScore : float|null

setManuallyUnlocked()

Set manually unlocked status

public setManuallyUnlocked(bool|null $manuallyUnlocked) : void
Parameters
$manuallyUnlocked : bool|null

setOverdueAndNeedsSubmission()

Set overdue and needs submission status

public setOverdueAndNeedsSubmission(bool|null $overdueAndNeedsSubmission) : void
Parameters
$overdueAndNeedsSubmission : bool|null

setQuiz()

Set the quiz context for quiz submissions

public static setQuiz(Quiz $quiz) : void
Parameters
$quiz : Quiz

The quiz instance

setQuizData()

Set associated quiz data

public setQuizData(array<string|int, mixed>|null $quizData) : void
Parameters
$quizData : array<string|int, mixed>|null

setQuizId()

Set quiz ID

public setQuizId(int|null $quizId) : void
Parameters
$quizId : int|null

setScore()

Set current score

public setScore(float|null $score) : void
Parameters
$score : float|null

setScoreBeforeRegrade()

Set score before regrade

public setScoreBeforeRegrade(float|null $scoreBeforeRegrade) : void
Parameters
$scoreBeforeRegrade : float|null

setStartedAt()

Set started at timestamp

public setStartedAt(string|null $startedAt) : void
Parameters
$startedAt : string|null

setSubmission()

Set associated submission data

public setSubmission(array<string|int, mixed>|null $submission) : void
Parameters
$submission : array<string|int, mixed>|null

setSubmissionId()

Set submission ID

public setSubmissionId(int|null $submissionId) : void
Parameters
$submissionId : int|null

setTimeSpent()

Set time spent in seconds

public setTimeSpent(int|null $timeSpent) : void
Parameters
$timeSpent : int|null

setUser()

Set associated user data

public setUser(array<string|int, mixed>|null $user) : void
Parameters
$user : array<string|int, mixed>|null

setUserId()

Set user ID

public setUserId(int|null $userId) : void
Parameters
$userId : int|null

setValidationToken()

Set validation token

public setValidationToken(string|null $validationToken) : void
Parameters
$validationToken : string|null

setWorkflowState()

Set workflow state

public setWorkflowState(string|null $workflowState) : void
Parameters
$workflowState : string|null

start()

Start a quiz submission (alias for create)

public static start([array<string|int, mixed> $params = [] ]) : self
Parameters
$params : array<string|int, mixed> = []

Optional parameters like access_code

Tags
throws
CanvasApiException

If course/quiz not set or API error

Return values
self

Created quiz submission instance

toArray()

Convert quiz submission to array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

Quiz submission data

toDtoArray()

Convert quiz submission to DTO-compatible array

public toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

DTO-compatible data

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

checkContext()

Check if both course and quiz contexts are set

protected static checkContext() : bool
Tags
throws
CanvasApiException

If course or quiz is not set

Return values
bool

True if both are set

checkCourse()

Check if course context is set

protected static checkCourse() : bool
Tags
throws
CanvasApiException

If course is not set

Return values
bool

True if course is set

checkQuiz()

Check if quiz context is set

protected static checkQuiz() : bool
Tags
throws
CanvasApiException

If quiz is not set

Return values
bool

True if quiz is set

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

fetchAllPagesAsModels()

Helper method to fetch all pages and convert to model instances

protected static fetchAllPagesAsModels(string $endpoint[, array<string|int, mixed> $params = [] ]) : array<string|int, static>
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
array<string|int, static>

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

        
On this page

Search results