Submission
extends AbstractBaseApi
in package
Canvas LMS Submissions API
Provides functionality to manage assignment submissions in Canvas LMS. This class handles creating, reading, updating submissions for specific assignments. Requires both Course and Assignment context for all operations.
Usage Examples:
// Set dual context (required for all operations)
$course = Course::find(123);
$assignment = Assignment::find(456);
Submission::setCourse($course);
Submission::setAssignment($assignment);
// Submit an assignment
$submissionData = [
'submission_type' => 'online_text_entry',
'body' => 'My essay content...'
];
$submission = Submission::create($submissionData);
// Submit with file upload
$submissionData = [
'submission_type' => 'online_upload',
'file_ids' => [123, 456]
];
$submission = Submission::create($submissionData);
// Submit with URL
$submissionData = [
'submission_type' => 'online_url',
'url' => 'https://example.com/my-project'
];
$submission = Submission::create($submissionData);
// Find a specific submission by user ID
$submission = Submission::find(789);
// List all submissions for the assignment
$submissions = Submission::get();
// Grade a submission
$gradedSubmission = Submission::update(789, [
'posted_grade' => '85',
'comment' => 'Great work!'
]);
// Excuse a submission
$excusedSubmission = Submission::update(789, ['excuse' => true]);
// Mark submission as read/unread
Submission::markAsRead(789);
Submission::markAsUnread(789);
// Bulk grade update
$gradeData = [
'grade_data' => [
['user_id' => 123, 'posted_grade' => '90'],
['user_id' => 456, 'posted_grade' => '85']
]
];
Submission::updateGrades($gradeData);
Table of Contents
Properties
- $anonymousId : string|null
- Anonymous ID for anonymous assignments
- $assignmentId : int|null
- Assignment ID this submission belongs to
- $assignmentVisible : bool|null
- Whether the assignment is visible to the student
- $attachments : array<string|int, mixed>|null
- Array of file attachments
- $attempt : int|null
- Submission attempt number
- $body : string|null
- Text content for online_text_entry submissions
- $excused : bool|null
- Whether the submission is excused
- $extraAttempts : int|null
- Extra attempts granted for this submission
- $grade : string|null
- Grade for the submission (can be letter grade or numeric)
- $gradedAt : string|null
- Date and time when submission was graded
- $gradeMatchesCurrentSubmission : bool|null
- Whether the grade matches the current submission
- $graderId : int|null
- ID of the user who graded this submission
- $htmlUrl : string|null
- Canvas URL for viewing this submission
- $id : int|null
- Submission unique identifier
- $late : bool|null
- Whether the submission was late
- $latePolicyStatus : string|null
- Late policy status
- $missing : bool|null
- Whether the submission is missing
- $pointsDeducted : float|null
- Points deducted for late submission
- $postedAt : string|null
- Date and time when grades were posted
- $previewUrl : string|null
- Preview URL for the submission
- $score : float|null
- Numeric score for the submission
- $secondsLate : int|null
- Seconds late for the submission
- $submissionComments : array<string|int, mixed>|null
- Array of submission comments
- $submissionType : string|null
- Type of submission Valid values: online_text_entry, online_url, online_upload, media_recording, basic_lti_launch, student_annotation
- $submittedAt : string|null
- Date and time when submission was submitted
- $url : string|null
- URL for online_url submissions
- $userId : int|null
- User ID who made the submission
- $workflowState : string|null
- Workflow state of the submission Values: submitted, unsubmitted, graded, pending_review
- $apiClient : HttpClientInterface
- $assignment : Assignment
- Assignment context (required)
- $course : Course
- Course context (required)
- $methodAliases : array<string|int, mixed>
- Define method aliases
Methods
- __callStatic() : mixed
- Magic method to handle function aliases
- __construct() : mixed
- BaseApi constructor.
- all() : array<string|int, Submission>
- Fetch all submissions from all pages
- assignment() : Assignment|null
- Get the assignment this submission belongs to
- checkAssignment() : bool
- Check if assignment context is set
- checkContexts() : bool
- Check if both contexts are set
- checkCourse() : bool
- Check if course context is set
- clearContext() : void
- Clear static contexts to prevent memory leaks in long-running processes
- course() : Course|null
- Get the course this submission belongs to
- create() : self
- Create a new submission
- find() : static
- Find a submission by user ID
- get() : array<string|int, Submission>
- Fetch all submissions for the assignment
- getAnonymousId() : string|null
- getAssignmentId() : int|null
- getAssignmentVisible() : bool|null
- getAttachments() : array<string|int, mixed>|null
- getAttempt() : int|null
- getBody() : string|null
- getExcused() : bool|null
- getExtraAttempts() : int|null
- getGrade() : string|null
- getGradedAt() : string|null
- getGradeMatchesCurrentSubmission() : bool|null
- getGraderId() : int|null
- getHtmlUrl() : string|null
- getId() : int|null
- getLate() : bool|null
- getLatePolicyStatus() : string|null
- getMissing() : bool|null
- getPointsDeducted() : float|null
- getPostedAt() : string|null
- getPreviewUrl() : string|null
- getScore() : float|null
- getSecondsLate() : int|null
- getSubmissionComments() : array<string|int, mixed>|null
- getSubmissionType() : string|null
- getSubmittedAt() : string|null
- getUrl() : string|null
- getUserId() : int|null
- getWorkflowState() : string|null
- grader() : User|null
- Get the user who graded this submission
- markAsRead() : self
- Mark submission as read
- markAsUnread() : self
- Mark submission as unread
- paginate() : PaginationResult
- Get paginated submissions
- save() : self
- Save the submission (update only - submissions are created via static create method)
- setAnonymousId() : void
- setApiClient() : void
- Set the API client
- setAssignment() : void
- Set the assignment context
- setAssignmentId() : void
- setAssignmentVisible() : void
- setAttachments() : void
- setAttempt() : void
- setBody() : void
- setCourse() : void
- Set the course context
- setExcused() : void
- setExtraAttempts() : void
- setGrade() : void
- setGradedAt() : void
- setGradeMatchesCurrentSubmission() : void
- setGraderId() : void
- setHtmlUrl() : void
- setId() : void
- setLate() : void
- setLatePolicyStatus() : void
- setMissing() : void
- setPointsDeducted() : void
- setPostedAt() : void
- setPreviewUrl() : void
- setScore() : void
- setSecondsLate() : void
- setSubmissionComments() : void
- setSubmissionType() : void
- setSubmittedAt() : void
- setUrl() : void
- setUserId() : void
- setWorkflowState() : void
- update() : self
- Update/grade a submission
- updateGrades() : self
- Bulk update grades for multiple submissions
- user() : User|null
- Get the user who made this submission
- 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
- convertPaginatedResponseToModels() : array<string|int, static>
- Helper method to convert paginated response data to model instances
- createConfiguredHttpClient() : HttpClient
- Create an HttpClient with configured middleware
- createPaginationResult() : PaginationResult
- Helper method to create PaginationResult from paginated response
- getEndpoint() : string
- Get the API endpoint for this resource
- getPaginatedResponse() : PaginatedResponse
- Helper method to get paginated response from API endpoint
- populate() : void
- Populate the object with new data
- toDtoArray() : array<string, mixed>
- Convert submission to array for DTO
Properties
$anonymousId
Anonymous ID for anonymous assignments
public
string|null
$anonymousId
= null
$assignmentId
Assignment ID this submission belongs to
public
int|null
$assignmentId
= null
$assignmentVisible
Whether the assignment is visible to the student
public
bool|null
$assignmentVisible
= null
$attachments
Array of file attachments
public
array<string|int, mixed>|null
$attachments
= null
$attempt
Submission attempt number
public
int|null
$attempt
= null
$body
Text content for online_text_entry submissions
public
string|null
$body
= null
$excused
Whether the submission is excused
public
bool|null
$excused
= null
$extraAttempts
Extra attempts granted for this submission
public
int|null
$extraAttempts
= null
$grade
Grade for the submission (can be letter grade or numeric)
public
string|null
$grade
= null
$gradedAt
Date and time when submission was graded
public
string|null
$gradedAt
= null
$gradeMatchesCurrentSubmission
Whether the grade matches the current submission
public
bool|null
$gradeMatchesCurrentSubmission
= null
$graderId
ID of the user who graded this submission
public
int|null
$graderId
= null
$htmlUrl
Canvas URL for viewing this submission
public
string|null
$htmlUrl
= null
$id
Submission unique identifier
public
int|null
$id
= null
$late
Whether the submission was late
public
bool|null
$late
= null
$latePolicyStatus
Late policy status
public
string|null
$latePolicyStatus
= null
$missing
Whether the submission is missing
public
bool|null
$missing
= null
$pointsDeducted
Points deducted for late submission
public
float|null
$pointsDeducted
= null
$postedAt
Date and time when grades were posted
public
string|null
$postedAt
= null
$previewUrl
Preview URL for the submission
public
string|null
$previewUrl
= null
$score
Numeric score for the submission
public
float|null
$score
= null
$secondsLate
Seconds late for the submission
public
int|null
$secondsLate
= null
$submissionComments
Array of submission comments
public
array<string|int, mixed>|null
$submissionComments
= null
$submissionType
Type of submission Valid values: online_text_entry, online_url, online_upload, media_recording, basic_lti_launch, student_annotation
public
string|null
$submissionType
= null
$submittedAt
Date and time when submission was submitted
public
string|null
$submittedAt
= null
$url
URL for online_url submissions
public
string|null
$url
= null
$userId
User ID who made the submission
public
int|null
$userId
= null
$workflowState
Workflow state of the submission Values: submitted, unsubmitted, graded, pending_review
public
string|null
$workflowState
= null
$apiClient
protected
static HttpClientInterface
$apiClient
= null
$assignment
Assignment context (required)
protected
static Assignment
$assignment
= null
$course
Course context (required)
protected
static Course
$course
= null
$methodAliases
Define method aliases
protected
static array<string|int, mixed>
$methodAliases
= ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]
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>
Tags
__construct()
BaseApi constructor.
public
__construct(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
all()
Fetch all submissions from all pages
public
static all([array<string, mixed> $params = [] ]) : array<string|int, Submission>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
array<string|int, Submission>assignment()
Get the assignment this submission belongs to
public
assignment() : Assignment|null
Return values
Assignment|nullcheckAssignment()
Check if assignment context is set
public
static checkAssignment() : bool
Tags
Return values
boolcheckContexts()
Check if both contexts are set
public
static checkContexts() : bool
Tags
Return values
boolcheckCourse()
Check if course context is set
public
static checkCourse() : bool
Tags
Return values
boolclearContext()
Clear static contexts to prevent memory leaks in long-running processes
public
static clearContext() : void
course()
Get the course this submission belongs to
public
course() : Course|null
Return values
Course|nullcreate()
Create a new submission
public
static create(array<string, mixed>|CreateSubmissionDTO $data) : self
Parameters
- $data : array<string, mixed>|CreateSubmissionDTO
Tags
Return values
selffind()
Find a submission by user ID
public
static find(int $id[, array<string, mixed> $params = [] ]) : static
Parameters
- $id : int
-
User ID (submissions are fetched by user ID)
- $params : array<string, mixed> = []
-
Optional query parameters
Tags
Return values
staticget()
Fetch all submissions for the assignment
public
static get([array<string, mixed> $params = [] ]) : array<string|int, Submission>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
array<string|int, Submission>getAnonymousId()
public
getAnonymousId() : string|null
Return values
string|nullgetAssignmentId()
public
getAssignmentId() : int|null
Return values
int|nullgetAssignmentVisible()
public
getAssignmentVisible() : bool|null
Return values
bool|nullgetAttachments()
public
getAttachments() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetAttempt()
public
getAttempt() : int|null
Return values
int|nullgetBody()
public
getBody() : string|null
Return values
string|nullgetExcused()
public
getExcused() : bool|null
Return values
bool|nullgetExtraAttempts()
public
getExtraAttempts() : int|null
Return values
int|nullgetGrade()
public
getGrade() : string|null
Return values
string|nullgetGradedAt()
public
getGradedAt() : string|null
Return values
string|nullgetGradeMatchesCurrentSubmission()
public
getGradeMatchesCurrentSubmission() : bool|null
Return values
bool|nullgetGraderId()
public
getGraderId() : int|null
Return values
int|nullgetHtmlUrl()
public
getHtmlUrl() : string|null
Return values
string|nullgetId()
public
getId() : int|null
Return values
int|nullgetLate()
public
getLate() : bool|null
Return values
bool|nullgetLatePolicyStatus()
public
getLatePolicyStatus() : string|null
Return values
string|nullgetMissing()
public
getMissing() : bool|null
Return values
bool|nullgetPointsDeducted()
public
getPointsDeducted() : float|null
Return values
float|nullgetPostedAt()
public
getPostedAt() : string|null
Return values
string|nullgetPreviewUrl()
public
getPreviewUrl() : string|null
Return values
string|nullgetScore()
public
getScore() : float|null
Return values
float|nullgetSecondsLate()
public
getSecondsLate() : int|null
Return values
int|nullgetSubmissionComments()
public
getSubmissionComments() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetSubmissionType()
public
getSubmissionType() : string|null
Return values
string|nullgetSubmittedAt()
public
getSubmittedAt() : string|null
Return values
string|nullgetUrl()
public
getUrl() : string|null
Return values
string|nullgetUserId()
public
getUserId() : int|null
Return values
int|nullgetWorkflowState()
public
getWorkflowState() : string|null
Return values
string|nullgrader()
Get the user who graded this submission
public
grader() : User|null
Tags
Return values
User|nullmarkAsRead()
Mark submission as read
public
static markAsRead(int $userId) : self
Parameters
- $userId : int
Tags
Return values
selfmarkAsUnread()
Mark submission as unread
public
static markAsUnread(int $userId) : self
Parameters
- $userId : int
Tags
Return values
selfpaginate()
Get paginated submissions
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
PaginationResultsave()
Save the submission (update only - submissions are created via static create method)
public
save() : self
Tags
Return values
selfsetAnonymousId()
public
setAnonymousId(string|null $anonymousId) : void
Parameters
- $anonymousId : string|null
setApiClient()
Set the API client
public
static setApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
setAssignment()
Set the assignment context
public
static setAssignment(Assignment $assignment) : void
Parameters
- $assignment : Assignment
setAssignmentId()
public
setAssignmentId(int|null $assignmentId) : void
Parameters
- $assignmentId : int|null
setAssignmentVisible()
public
setAssignmentVisible(bool|null $assignmentVisible) : void
Parameters
- $assignmentVisible : bool|null
setAttachments()
public
setAttachments(array<string|int, mixed>|null $attachments) : void
Parameters
- $attachments : array<string|int, mixed>|null
setAttempt()
public
setAttempt(int|null $attempt) : void
Parameters
- $attempt : int|null
setBody()
public
setBody(string|null $body) : void
Parameters
- $body : string|null
setCourse()
Set the course context
public
static setCourse(Course $course) : void
Parameters
- $course : Course
setExcused()
public
setExcused(bool|null $excused) : void
Parameters
- $excused : bool|null
setExtraAttempts()
public
setExtraAttempts(int|null $extraAttempts) : void
Parameters
- $extraAttempts : int|null
setGrade()
public
setGrade(string|null $grade) : void
Parameters
- $grade : string|null
setGradedAt()
public
setGradedAt(string|null $gradedAt) : void
Parameters
- $gradedAt : string|null
setGradeMatchesCurrentSubmission()
public
setGradeMatchesCurrentSubmission(bool|null $gradeMatchesCurrentSubmission) : void
Parameters
- $gradeMatchesCurrentSubmission : bool|null
setGraderId()
public
setGraderId(int|null $graderId) : void
Parameters
- $graderId : int|null
setHtmlUrl()
public
setHtmlUrl(string|null $htmlUrl) : void
Parameters
- $htmlUrl : string|null
setId()
public
setId(int|null $id) : void
Parameters
- $id : int|null
setLate()
public
setLate(bool|null $late) : void
Parameters
- $late : bool|null
setLatePolicyStatus()
public
setLatePolicyStatus(string|null $latePolicyStatus) : void
Parameters
- $latePolicyStatus : string|null
setMissing()
public
setMissing(bool|null $missing) : void
Parameters
- $missing : bool|null
setPointsDeducted()
public
setPointsDeducted(float|null $pointsDeducted) : void
Parameters
- $pointsDeducted : float|null
setPostedAt()
public
setPostedAt(string|null $postedAt) : void
Parameters
- $postedAt : string|null
setPreviewUrl()
public
setPreviewUrl(string|null $previewUrl) : void
Parameters
- $previewUrl : string|null
setScore()
public
setScore(float|null $score) : void
Parameters
- $score : float|null
setSecondsLate()
public
setSecondsLate(int|null $secondsLate) : void
Parameters
- $secondsLate : int|null
setSubmissionComments()
public
setSubmissionComments(array<string|int, mixed>|null $submissionComments) : void
Parameters
- $submissionComments : array<string|int, mixed>|null
setSubmissionType()
public
setSubmissionType(string|null $submissionType) : void
Parameters
- $submissionType : string|null
setSubmittedAt()
public
setSubmittedAt(string|null $submittedAt) : void
Parameters
- $submittedAt : string|null
setUrl()
public
setUrl(string|null $url) : void
Parameters
- $url : string|null
setUserId()
public
setUserId(int|null $userId) : void
Parameters
- $userId : int|null
setWorkflowState()
public
setWorkflowState(string|null $workflowState) : void
Parameters
- $workflowState : string|null
update()
Update/grade a submission
public
static update(int $userId, array<string, mixed>|UpdateSubmissionDTO $data) : self
Parameters
- $userId : int
- $data : array<string, mixed>|UpdateSubmissionDTO
Tags
Return values
selfupdateGrades()
Bulk update grades for multiple submissions
public
static updateGrades(array<string, mixed> $gradeData) : self
Parameters
- $gradeData : array<string, mixed>
Tags
Return values
selfuser()
Get the user who made this submission
public
user() : User|null
Tags
Return values
User|nullcastValue()
Cast a value to the correct type
protected
castValue(string $key, mixed $value) : DateTime|mixed
Parameters
- $key : string
- $value : mixed
Tags
Return values
DateTime|mixedcheckApiClient()
Check if the API client is set, if not, instantiate a new one
protected
static checkApiClient() : void
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>createConfiguredHttpClient()
Create an HttpClient with configured middleware
protected
static createConfiguredHttpClient() : HttpClient
Return values
HttpClientcreatePaginationResult()
Helper method to create PaginationResult from paginated response
protected
static createPaginationResult(PaginatedResponse $paginatedResponse) : PaginationResult
Parameters
- $paginatedResponse : PaginatedResponse
Return values
PaginationResultgetEndpoint()
Get the API endpoint for this resource
protected
static getEndpoint() : string
Tags
Return values
stringgetPaginatedResponse()
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
PaginatedResponsepopulate()
Populate the object with new data
protected
populate(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Tags
toDtoArray()
Convert submission to array for DTO
protected
toDtoArray() : array<string, mixed>