Documentation

Assignment extends AbstractBaseApi

Canvas LMS Assignments API

Provides functionality to manage assignments in Canvas LMS. This class handles creating, reading, updating, and deleting assignments for a specific course.

Usage Examples:

// Set course context (required for all operations)
$course = Course::find(123);
Assignment::setCourse($course);

// Create a new assignment
$assignmentData = [
    'name' => 'Homework Assignment 1',
    'description' => 'Complete exercises 1-10',
    'points_possible' => 100,
    'due_at' => '2024-12-31T23:59:59Z'
];
$assignment = Assignment::create($assignmentData);

// Find an assignment by ID
$assignment = Assignment::find(456);

// List all assignments for the course
$assignments = Assignment::fetchAll();

// Get paginated assignments
$paginatedAssignments = Assignment::fetchAllPaginated();
$paginationResult = Assignment::fetchPage();

// Update an assignment
$updatedAssignment = Assignment::update(456, ['points_possible' => 150]);

// Update using DTO
$updateDto = new UpdateAssignmentDTO(['name' => 'Updated Assignment Name']);
$updatedAssignment = Assignment::update(456, $updateDto);

// Update using instance method
$assignment = Assignment::find(456);
$assignment->setPointsPossible(125);
$success = $assignment->save();

// Delete an assignment
$assignment = Assignment::find(456);
$success = $assignment->delete();

// Duplicate an assignment
$duplicatedAssignment = Assignment::duplicate(456);

Table of Contents

Properties

$allDates  : array<string, mixed>|null
All date variations for the assignment
$allowedAttempts  : int|null
Maximum number of submission attempts allowed
$allowedExtensions  : array<string|int, string>|null
Allowed file extensions for submissions
$anonymousGrading  : bool|null
Whether grading is anonymous
$assignmentGroupId  : int|null
Assignment group ID
$courseId  : int|null
Course ID this assignment belongs to
$createdAt  : string|null
Assignment creation timestamp
$description  : string|null
Assignment description (HTML)
$dueAt  : string|null
Assignment due date
$gradingType  : string|null
Grading type (points, percent, pass_fail, etc.)
$groupCategoryId  : int|null
Group category ID for group assignments
$hasOverrides  : bool|null
Whether the assignment has date overrides
$htmlUrl  : string|null
HTML URL to the assignment
$id  : int|null
Assignment unique identifier
$lockAt  : string|null
Date when assignment becomes locked
$lockedForUser  : bool|null
Whether assignment is locked for the current user
$moderatedGrading  : bool|null
Whether moderated grading is enabled
$name  : string|null
Assignment name
$onlyVisibleToOverrides  : bool|null
Whether assignment is only visible to users with overrides
$peerReviews  : bool|null
Whether peer reviews are enabled
$pointsPossible  : float|null
Maximum points possible for this assignment
$position  : int|null
Assignment position in the group
$published  : bool|null
Whether the assignment is published
$submissionTypes  : array<string|int, string>|null
Allowed submission types
$unlockAt  : string|null
Date when assignment becomes available
$updatedAt  : string|null
Assignment last update timestamp
$workflowState  : string|null
Assignment workflow state (published, unpublished, etc.)
$apiClient  : HttpClientInterface
$course  : Course
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Create a new Assignment instance
checkCourse()  : bool
Check if course context is set
create()  : self
Create a new assignment
delete()  : bool
Delete the assignment
duplicate()  : self
Duplicate an assignment
fetchAll()  : array<string|int, Assignment>
Fetch all assignments for the course
fetchAllPages()  : array<string|int, Assignment>
Fetch all pages of assignments
fetchAllPaginated()  : PaginatedResponse
Fetch all assignments with pagination support
fetchPage()  : PaginationResult
Fetch a single page of assignments
find()  : self
Find a single assignment by ID
getAllDates()  : array<string, mixed>|null
Get all dates
getAllowedAttempts()  : int|null
Get allowed attempts
getAllowedExtensions()  : array<string|int, string>|null
Get allowed extensions
getAnonymousGrading()  : bool|null
Get anonymous grading status
getAssignmentGroupId()  : int|null
Get assignment group ID
getCourseId()  : int|null
Get course ID
getCreatedAt()  : string|null
Get created at timestamp
getDescription()  : string|null
Get assignment description
getDueAt()  : string|null
Get due date
getGradingType()  : string|null
Get grading type
getGroupCategoryId()  : int|null
Get group category ID
getHasOverrides()  : bool|null
Get has overrides status
getHtmlUrl()  : string|null
Get HTML URL
getId()  : int|null
Get assignment ID
getLockAt()  : string|null
Get lock date
getLockedForUser()  : bool|null
Get locked for user status
getModeratedGrading()  : bool|null
Get moderated grading status
getName()  : string|null
Get assignment name
getOnlyVisibleToOverrides()  : bool|null
Get only visible to overrides status
getPeerReviews()  : bool|null
Get peer reviews status
getPointsPossible()  : float|null
Get points possible
getPosition()  : int|null
Get assignment position
getPublished()  : bool|null
Get published status
getSubmissionTypes()  : array<string|int, string>|null
Get submission types
getUnlockAt()  : string|null
Get unlock date
getUpdatedAt()  : string|null
Get updated at timestamp
getWorkflowState()  : string|null
Get workflow state
save()  : bool
Save the current assignment (create or update)
setAllDates()  : void
Set all dates
setAllowedAttempts()  : void
Set allowed attempts
setAllowedExtensions()  : void
Set allowed extensions
setAnonymousGrading()  : void
Set anonymous grading status
setApiClient()  : void
Set the API client
setAssignmentGroupId()  : void
Set assignment group ID
setCourse()  : void
Set the course context for assignment operations
setCourseId()  : void
Set course ID
setCreatedAt()  : void
Set created at timestamp
setDescription()  : void
Set assignment description
setDueAt()  : void
Set due date
setGradingType()  : void
Set grading type
setGroupCategoryId()  : void
Set group category ID
setHasOverrides()  : void
Set has overrides status
setHtmlUrl()  : void
Set HTML URL
setId()  : void
Set assignment ID
setLockAt()  : void
Set lock date
setLockedForUser()  : void
Set locked for user status
setModeratedGrading()  : void
Set moderated grading status
setName()  : void
Set assignment name
setOnlyVisibleToOverrides()  : void
Set only visible to overrides status
setPeerReviews()  : void
Set peer reviews status
setPointsPossible()  : void
Set points possible
setPosition()  : void
Set assignment position
setPublished()  : void
Set published status
setSubmissionTypes()  : void
Set submission types
setUnlockAt()  : void
Set unlock date
setUpdatedAt()  : void
Set updated at timestamp
setWorkflowState()  : void
Set workflow state
toArray()  : array<string, mixed>
Convert assignment to array
toDtoArray()  : array<string, mixed>
Convert assignment to DTO array format
update()  : self
Update an assignment
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
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

$allDates

All date variations for the assignment

public array<string, mixed>|null $allDates = null

$allowedAttempts

Maximum number of submission attempts allowed

public int|null $allowedAttempts = null

$allowedExtensions

Allowed file extensions for submissions

public array<string|int, string>|null $allowedExtensions = null

$anonymousGrading

Whether grading is anonymous

public bool|null $anonymousGrading = null

$assignmentGroupId

Assignment group ID

public int|null $assignmentGroupId = null

$courseId

Course ID this assignment belongs to

public int|null $courseId = null

$createdAt

Assignment creation timestamp

public string|null $createdAt = null

$description

Assignment description (HTML)

public string|null $description = null

$dueAt

Assignment due date

public string|null $dueAt = null

$gradingType

Grading type (points, percent, pass_fail, etc.)

public string|null $gradingType = null

$groupCategoryId

Group category ID for group assignments

public int|null $groupCategoryId = null

$hasOverrides

Whether the assignment has date overrides

public bool|null $hasOverrides = null

$htmlUrl

HTML URL to the assignment

public string|null $htmlUrl = null

$id

Assignment unique identifier

public int|null $id = null

$lockAt

Date when assignment becomes locked

public string|null $lockAt = null

$lockedForUser

Whether assignment is locked for the current user

public bool|null $lockedForUser = null

$moderatedGrading

Whether moderated grading is enabled

public bool|null $moderatedGrading = null

$name

Assignment name

public string|null $name = null

$onlyVisibleToOverrides

Whether assignment is only visible to users with overrides

public bool|null $onlyVisibleToOverrides = null

$peerReviews

Whether peer reviews are enabled

public bool|null $peerReviews = null

$pointsPossible

Maximum points possible for this assignment

public float|null $pointsPossible = null

$position

Assignment position in the group

public int|null $position = null

$published

Whether the assignment is published

public bool|null $published = null

$submissionTypes

Allowed submission types

public array<string|int, string>|null $submissionTypes = null

$unlockAt

Date when assignment becomes available

public string|null $unlockAt = null

$updatedAt

Assignment last update timestamp

public string|null $updatedAt = null

$workflowState

Assignment workflow state (published, unpublished, etc.)

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()

Create a new Assignment instance

public __construct([array<string, mixed> $data = [] ]) : mixed
Parameters
$data : array<string, mixed> = []

Assignment data from Canvas API

checkCourse()

Check if course context is set

public static checkCourse() : bool
Tags
throws
CanvasApiException

If course is not set

Return values
bool

delete()

Delete the assignment

public delete() : bool
Tags
throws
CanvasApiException
Return values
bool

True if deletion was successful, false otherwise

duplicate()

Duplicate an assignment

public static duplicate(int $id[, array<string, mixed> $options = [] ]) : self
Parameters
$id : int

Assignment ID to duplicate

$options : array<string, mixed> = []

Duplication options

Tags
throws
CanvasApiException
Return values
self

Duplicated Assignment object

fetchAll()

Fetch all assignments for the course

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

Optional parameters

Tags
throws
CanvasApiException
Return values
array<string|int, Assignment>

Array of Assignment objects

fetchAllPages()

Fetch all pages of assignments

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

Optional parameters

Tags
throws
CanvasApiException
Return values
array<string|int, Assignment>

Array of Assignment objects from all pages

find()

Find a single assignment by ID

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

Assignment ID

Tags
throws
CanvasApiException
Return values
self

getAllDates()

Get all dates

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

getAllowedAttempts()

Get allowed attempts

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

getAllowedExtensions()

Get allowed extensions

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

getAnonymousGrading()

Get anonymous grading status

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

getAssignmentGroupId()

Get assignment group ID

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

getCourseId()

Get course ID

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

getCreatedAt()

Get created at timestamp

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

getDescription()

Get assignment description

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

getDueAt()

Get due date

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

getGradingType()

Get grading type

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

getGroupCategoryId()

Get group category ID

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

getHasOverrides()

Get has overrides status

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

getHtmlUrl()

Get HTML URL

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

getId()

Get assignment ID

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

getLockAt()

Get lock date

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

getLockedForUser()

Get locked for user status

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

getModeratedGrading()

Get moderated grading status

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

getName()

Get assignment name

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

getOnlyVisibleToOverrides()

Get only visible to overrides status

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

getPeerReviews()

Get peer reviews status

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

getPointsPossible()

Get points possible

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

getPosition()

Get assignment position

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

getPublished()

Get published status

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

getSubmissionTypes()

Get submission types

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

getUnlockAt()

Get unlock date

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

getUpdatedAt()

Get updated at timestamp

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

getWorkflowState()

Get workflow state

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

save()

Save the current assignment (create or update)

public save() : bool
Tags
throws
CanvasApiException
Return values
bool

True if save was successful, false otherwise

setAllDates()

Set all dates

public setAllDates(array<string, mixed>|null $allDates) : void
Parameters
$allDates : array<string, mixed>|null

setAllowedAttempts()

Set allowed attempts

public setAllowedAttempts(int|null $allowedAttempts) : void
Parameters
$allowedAttempts : int|null

setAllowedExtensions()

Set allowed extensions

public setAllowedExtensions(array<string|int, string>|null $allowedExtensions) : void
Parameters
$allowedExtensions : array<string|int, string>|null

setAnonymousGrading()

Set anonymous grading status

public setAnonymousGrading(bool|null $anonymousGrading) : void
Parameters
$anonymousGrading : bool|null

setAssignmentGroupId()

Set assignment group ID

public setAssignmentGroupId(int|null $assignmentGroupId) : void
Parameters
$assignmentGroupId : int|null

setCourse()

Set the course context for assignment operations

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

The course to operate on

setCourseId()

Set course ID

public setCourseId(int|null $courseId) : void
Parameters
$courseId : int|null

setCreatedAt()

Set created at timestamp

public setCreatedAt(string|null $createdAt) : void
Parameters
$createdAt : string|null

setDescription()

Set assignment description

public setDescription(string|null $description) : void
Parameters
$description : string|null

setDueAt()

Set due date

public setDueAt(string|null $dueAt) : void
Parameters
$dueAt : string|null

setGradingType()

Set grading type

public setGradingType(string|null $gradingType) : void
Parameters
$gradingType : string|null

setGroupCategoryId()

Set group category ID

public setGroupCategoryId(int|null $groupCategoryId) : void
Parameters
$groupCategoryId : int|null

setHasOverrides()

Set has overrides status

public setHasOverrides(bool|null $hasOverrides) : void
Parameters
$hasOverrides : bool|null

setHtmlUrl()

Set HTML URL

public setHtmlUrl(string|null $htmlUrl) : void
Parameters
$htmlUrl : string|null

setId()

Set assignment ID

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

setLockAt()

Set lock date

public setLockAt(string|null $lockAt) : void
Parameters
$lockAt : string|null

setLockedForUser()

Set locked for user status

public setLockedForUser(bool|null $lockedForUser) : void
Parameters
$lockedForUser : bool|null

setModeratedGrading()

Set moderated grading status

public setModeratedGrading(bool|null $moderatedGrading) : void
Parameters
$moderatedGrading : bool|null

setName()

Set assignment name

public setName(string|null $name) : void
Parameters
$name : string|null

setOnlyVisibleToOverrides()

Set only visible to overrides status

public setOnlyVisibleToOverrides(bool|null $onlyVisibleToOverrides) : void
Parameters
$onlyVisibleToOverrides : bool|null

setPeerReviews()

Set peer reviews status

public setPeerReviews(bool|null $peerReviews) : void
Parameters
$peerReviews : bool|null

setPointsPossible()

Set points possible

public setPointsPossible(float|null $pointsPossible) : void
Parameters
$pointsPossible : float|null

setPosition()

Set assignment position

public setPosition(int|null $position) : void
Parameters
$position : int|null

setPublished()

Set published status

public setPublished(bool|null $published) : void
Parameters
$published : bool|null

setSubmissionTypes()

Set submission types

public setSubmissionTypes(array<string|int, string>|null $submissionTypes) : void
Parameters
$submissionTypes : array<string|int, string>|null

setUnlockAt()

Set unlock date

public setUnlockAt(string|null $unlockAt) : void
Parameters
$unlockAt : string|null

setUpdatedAt()

Set updated at timestamp

public setUpdatedAt(string|null $updatedAt) : void
Parameters
$updatedAt : string|null

setWorkflowState()

Set workflow state

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

toArray()

Convert assignment to array

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

toDtoArray()

Convert assignment to DTO array format

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

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

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