Documentation

Enrollment extends AbstractBaseApi
in package

Canvas LMS Enrollment API Class

Represents a user's enrollment in a course, providing CRUD operations and relationship access to related User and Course objects.

Relationship Methods

This class provides explicit relationship methods that avoid conflicts with Canvas API data structure:

Tags
example

Basic relationship access

// Set course context for enrollment operations
$course = Course::find(123);
Enrollment::setCourse($course);

// Find and work with an enrollment
$enrollment = Enrollment::find(456);

// Access related objects using explicit methods
$user = $enrollment->user();      // Returns User object
$course = $enrollment->course();  // Returns Course object

echo $user->getName();
echo $course->getName();
example

Working with enrollment collections

// Get enrollments from course perspective
$course = Course::find(123);
$enrollments = $course->enrollments();

// Get enrollments from user perspective
$user = User::find(456);
$enrollments = $user->enrollments();

foreach ($enrollments as $enrollment) {
    echo $enrollment->getTypeName() . ': ' . $enrollment->getStateName();
}

Table of Contents

Constants

NOTIFY_FALSE  = false
NOTIFY_TRUE  = true
STATE_ACTIVE  = 'active'
STATE_COMPLETED  = 'completed'
STATE_CREATION_PENDING  = 'creation_pending'
STATE_DELETED  = 'deleted'
STATE_INACTIVE  = 'inactive'
STATE_INVITED  = 'invited'
STATE_REJECTED  = 'rejected'
TYPE_DESIGNER  = 'DesignerEnrollment'
TYPE_OBSERVER  = 'ObserverEnrollment'
TYPE_STUDENT  = 'StudentEnrollment'
TYPE_TA  = 'TaEnrollment'
TYPE_TEACHER  = 'TeacherEnrollment'

Properties

$canBeRemoved  : bool|null
$courseId  : int|null
$createdAt  : string|null
$currentGrade  : string|null
$currentPoints  : float|null
$currentScore  : float|null
$endAt  : string|null
$enrollmentState  : string|null
$enrollmentTermId  : int|null
$finalGrade  : string|null
$finalScore  : float|null
$grades  : array<string|int, mixed>|null
$gradingPeriodId  : int|null
$groupIds  : array<string|int, int>|null
$id  : int|null
$lastActivityAt  : string|null
$limitPrivilegesToCourseSection  : bool|null
$locked  : bool|null
$observedUsers  : array<string|int, mixed>|null
$role  : string|null
$roleId  : int|null
$rootAccountId  : int|null
$sectionId  : int|null
$sisAccountId  : string|null
$sisCourseId  : string|null
$sisSectionId  : string|null
$sisUserId  : string|null
$startAt  : string|null
$totalActivityTime  : int|null
$type  : string|null
$unpostedCurrentGrade  : string|null
$unpostedCurrentPoints  : float|null
$unpostedCurrentScore  : float|null
$unpostedFinalGrade  : string|null
$unpostedFinalScore  : float|null
$updatedAt  : string|null
$user  : array<string|int, mixed>|null
$userId  : int|null
$uuid  : string|null
$apiClient  : HttpClientInterface
$course  : Course
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
BaseApi constructor.
accept()  : self
canBeRemoved()  : bool|null
checkCourse()  : bool
Check if course context is set and valid
course()  : Course|null
Get the associated Course object (relationship method alias)
create()  : self
delete()  : bool
Delete the current enrollment
fetchAll()  : array<string|int, self>
Fetch all records
fetchAllBySection()  : array<string|int, self>
fetchAllByUser()  : array<string|int, self>
fetchAllPages()  : array<string|int, self>
fetchAllPaginated()  : PaginatedResponse
fetchPage()  : PaginationResult
find()  : self
Find a single record by ID
getCourse()  : Course|null
Get the associated Course object
getCourseId()  : int|null
getCreatedAt()  : string|null
getCurrentGrade()  : string|null
getCurrentPoints()  : float|null
getCurrentScore()  : float|null
getEndAt()  : string|null
getEnrollmentState()  : string|null
getEnrollmentTermId()  : int|null
getFinalGrade()  : string|null
getFinalScore()  : float|null
getGrades()  : array<string|int, mixed>|null
getGradingPeriodId()  : int|null
getGroupIds()  : array<string|int, int>|null
getId()  : int|null
getLastActivityAt()  : string|null
getObservedUsers()  : array<string|int, mixed>|null
getRole()  : string|null
getRoleId()  : int|null
getRootAccountId()  : int|null
getSectionId()  : int|null
getSisAccountId()  : string|null
getSisCourseId()  : string|null
getSisSectionId()  : string|null
getSisUserId()  : string|null
getStartAt()  : string|null
getStateName()  : string
Get a human-readable enrollment state name
getTotalActivityTime()  : int|null
getType()  : string|null
getTypeName()  : string
Get a human-readable enrollment type name
getUnpostedCurrentGrade()  : string|null
getUnpostedCurrentPoints()  : float|null
getUnpostedCurrentScore()  : float|null
getUnpostedFinalGrade()  : string|null
getUnpostedFinalScore()  : float|null
getUpdatedAt()  : string|null
getUser()  : User|null
Get the associated User object
getUserData()  : array<string|int, mixed>|null
Get the user data array (raw Canvas API data)
getUserId()  : int|null
getUuid()  : string|null
isActive()  : bool
Check if this enrollment is active
isCompleted()  : bool
Check if this enrollment is completed
isDesigner()  : bool
Check if this enrollment is for a designer
isInactive()  : bool
Check if this enrollment is inactive
isLimitPrivilegesToCourseSection()  : bool|null
isLocked()  : bool|null
isObserver()  : bool
Check if this enrollment is for an observer
isPending()  : bool
Check if this enrollment is pending (invited)
isStudent()  : bool
Check if this enrollment is for a student
isTa()  : bool
Check if this enrollment is for a TA
isTeacher()  : bool
Check if this enrollment is for a teacher
reactivate()  : self
reject()  : self
save()  : bool
Save the current enrollment (create or update)
setApiClient()  : void
Set the API client
setCourse()  : void
Set the course context for enrollment operations
setEndAt()  : void
setEnrollmentState()  : void
setLimitPrivilegesToCourseSection()  : void
setRoleId()  : void
setSectionId()  : void
setSisUserId()  : void
setStartAt()  : void
setType()  : void
setUserId()  : void
toArray()  : array<string|int, mixed>
update()  : self
user()  : User|null
Get the associated User object (relationship method alias)
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
toDtoArray()  : array<string|int, mixed>
Convert the object to an array
validateEnrollmentState()  : bool
Validate enrollment state
validateEnrollmentType()  : bool
Validate enrollment type

Constants

STATE_ACTIVE

public mixed STATE_ACTIVE = 'active'

STATE_COMPLETED

public mixed STATE_COMPLETED = 'completed'

STATE_CREATION_PENDING

public mixed STATE_CREATION_PENDING = 'creation_pending'

STATE_DELETED

public mixed STATE_DELETED = 'deleted'

STATE_INACTIVE

public mixed STATE_INACTIVE = 'inactive'

STATE_INVITED

public mixed STATE_INVITED = 'invited'

STATE_REJECTED

public mixed STATE_REJECTED = 'rejected'

TYPE_DESIGNER

public mixed TYPE_DESIGNER = 'DesignerEnrollment'

TYPE_OBSERVER

public mixed TYPE_OBSERVER = 'ObserverEnrollment'

TYPE_STUDENT

public mixed TYPE_STUDENT = 'StudentEnrollment'

TYPE_TEACHER

public mixed TYPE_TEACHER = 'TeacherEnrollment'

Properties

$canBeRemoved

public bool|null $canBeRemoved = null

$currentGrade

public string|null $currentGrade = null

$currentPoints

public float|null $currentPoints = null

$currentScore

public float|null $currentScore = null

$enrollmentState

public string|null $enrollmentState = null

$enrollmentTermId

public int|null $enrollmentTermId = null

$finalGrade

public string|null $finalGrade = null

$finalScore

public float|null $finalScore = null

$grades

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

$gradingPeriodId

public int|null $gradingPeriodId = null

$groupIds

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

$lastActivityAt

public string|null $lastActivityAt = null

$limitPrivilegesToCourseSection

public bool|null $limitPrivilegesToCourseSection = null

$observedUsers

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

$rootAccountId

public int|null $rootAccountId = null

$sisAccountId

public string|null $sisAccountId = null

$sisCourseId

public string|null $sisCourseId = null

$sisSectionId

public string|null $sisSectionId = null

$sisUserId

public string|null $sisUserId = null

$totalActivityTime

public int|null $totalActivityTime = null

$unpostedCurrentGrade

public string|null $unpostedCurrentGrade = null

$unpostedCurrentPoints

public float|null $unpostedCurrentPoints = null

$unpostedCurrentScore

public float|null $unpostedCurrentScore = null

$unpostedFinalGrade

public string|null $unpostedFinalGrade = null

$unpostedFinalScore

public float|null $unpostedFinalScore = null

$user

public array<string|int, mixed>|null $user = 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>

accept()

public static accept(int $enrollmentId) : self
Parameters
$enrollmentId : int
Return values
self

canBeRemoved()

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

checkCourse()

Check if course context is set and valid

public static checkCourse() : bool
Return values
bool

course()

Get the associated Course object (relationship method alias)

public course() : Course|null

This method provides a clean, explicit way to access the related course without conflicts with Canvas API data structure.

Tags
example
$enrollment = Enrollment::find(123);
$course = $enrollment->course(); // Returns Course object or null
echo $course->getName();
throws
CanvasApiException

If course cannot be loaded

Return values
Course|null

The course object or null if no courseId is set

delete()

Delete the current enrollment

public delete() : bool
Return values
bool

fetchAll()

Fetch all records

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

fetchAllBySection()

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

fetchAllByUser()

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

fetchAllPages()

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

find()

Find a single record by ID

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

getCourse()

Get the associated Course object

public getCourse() : Course|null

If the static course context is set and matches this enrollment's courseId, returns that course. Otherwise, fetches the course from the API.

Tags
throws
CanvasApiException

If course cannot be loaded

Return values
Course|null

The course object or null if no courseId is set

getCourseId()

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

getCreatedAt()

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

getCurrentGrade()

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

getCurrentPoints()

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

getCurrentScore()

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

getEndAt()

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

getEnrollmentState()

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

getEnrollmentTermId()

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

getFinalGrade()

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

getFinalScore()

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

getGrades()

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

getGradingPeriodId()

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

getGroupIds()

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

getId()

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

getLastActivityAt()

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

getObservedUsers()

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

getRole()

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

getRoleId()

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

getRootAccountId()

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

getSectionId()

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

getSisAccountId()

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

getSisCourseId()

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

getSisSectionId()

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

getSisUserId()

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

getStartAt()

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

getStateName()

Get a human-readable enrollment state name

public getStateName() : string
Return values
string

getTotalActivityTime()

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

getType()

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

getTypeName()

Get a human-readable enrollment type name

public getTypeName() : string
Return values
string

getUnpostedCurrentGrade()

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

getUnpostedCurrentPoints()

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

getUnpostedCurrentScore()

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

getUnpostedFinalGrade()

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

getUnpostedFinalScore()

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

getUpdatedAt()

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

getUser()

Get the associated User object

public getUser() : User|null

If user data is embedded in the enrollment (from Canvas API include), creates a User instance from that data. Otherwise, fetches the user from the API using the userId.

Tags
throws
CanvasApiException

If user cannot be loaded

Return values
User|null

The user object or null if no userId is set

getUserData()

Get the user data array (raw Canvas API data)

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

getUserId()

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

getUuid()

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

isActive()

Check if this enrollment is active

public isActive() : bool
Return values
bool

isCompleted()

Check if this enrollment is completed

public isCompleted() : bool
Return values
bool

isDesigner()

Check if this enrollment is for a designer

public isDesigner() : bool
Return values
bool

isInactive()

Check if this enrollment is inactive

public isInactive() : bool
Return values
bool

isLimitPrivilegesToCourseSection()

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

isLocked()

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

isObserver()

Check if this enrollment is for an observer

public isObserver() : bool
Return values
bool

isPending()

Check if this enrollment is pending (invited)

public isPending() : bool
Return values
bool

isStudent()

Check if this enrollment is for a student

public isStudent() : bool
Return values
bool

isTa()

Check if this enrollment is for a TA

public isTa() : bool
Return values
bool

isTeacher()

Check if this enrollment is for a teacher

public isTeacher() : bool
Return values
bool

reactivate()

public static reactivate(int $enrollmentId) : self
Parameters
$enrollmentId : int
Return values
self

reject()

public static reject(int $enrollmentId) : self
Parameters
$enrollmentId : int
Return values
self

save()

Save the current enrollment (create or update)

public save() : bool
Return values
bool

setCourse()

Set the course context for enrollment operations

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

setEndAt()

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

setEnrollmentState()

public setEnrollmentState(string|null $enrollmentState) : void
Parameters
$enrollmentState : string|null

setLimitPrivilegesToCourseSection()

public setLimitPrivilegesToCourseSection(bool|null $limitPrivilegesToCourseSection) : void
Parameters
$limitPrivilegesToCourseSection : bool|null

setRoleId()

public setRoleId(int|null $roleId) : void
Parameters
$roleId : int|null

setSectionId()

public setSectionId(int|null $sectionId) : void
Parameters
$sectionId : int|null

setSisUserId()

public setSisUserId(string|null $sisUserId) : void
Parameters
$sisUserId : string|null

setStartAt()

public setStartAt(string|null $startAt) : void
Parameters
$startAt : string|null

setType()

public setType(string|null $type) : void
Parameters
$type : string|null

setUserId()

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

toArray()

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

user()

Get the associated User object (relationship method alias)

public user() : User|null

This method provides a clean, explicit way to access the related user without conflicts with Canvas API data structure.

Tags
example
$enrollment = Enrollment::find(123);
$user = $enrollment->user(); // Returns User object or null
echo $user->getName();
throws
CanvasApiException

If user cannot be loaded

Return values
User|null

The user object or null if no userId is set

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

toDtoArray()

Convert the object to an array

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

validateEnrollmentState()

Validate enrollment state

private validateEnrollmentState(string $state) : bool
Parameters
$state : string
Return values
bool

validateEnrollmentType()

Validate enrollment type

private validateEnrollmentType(string $type) : bool
Parameters
$type : string
Return values
bool

        
On this page

Search results