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
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
NOTIFY_FALSE
public
mixed
NOTIFY_FALSE
= false
NOTIFY_TRUE
public
mixed
NOTIFY_TRUE
= true
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_TA
public
mixed
TYPE_TA
= 'TaEnrollment'
TYPE_TEACHER
public
mixed
TYPE_TEACHER
= 'TeacherEnrollment'
Properties
$canBeRemoved
public
bool|null
$canBeRemoved
= null
$courseId
public
int|null
$courseId
= null
$createdAt
public
string|null
$createdAt
= null
$currentGrade
public
string|null
$currentGrade
= null
$currentPoints
public
float|null
$currentPoints
= null
$currentScore
public
float|null
$currentScore
= null
$endAt
public
string|null
$endAt
= 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
$id
public
int|null
$id
= null
$lastActivityAt
public
string|null
$lastActivityAt
= null
$limitPrivilegesToCourseSection
public
bool|null
$limitPrivilegesToCourseSection
= null
$locked
public
bool|null
$locked
= null
$observedUsers
public
array<string|int, mixed>|null
$observedUsers
= null
$role
public
string|null
$role
= null
$roleId
public
int|null
$roleId
= null
$rootAccountId
public
int|null
$rootAccountId
= null
$sectionId
public
int|null
$sectionId
= 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
$startAt
public
string|null
$startAt
= null
$totalActivityTime
public
int|null
$totalActivityTime
= null
$type
public
string|null
$type
= 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
$updatedAt
public
string|null
$updatedAt
= null
$user
public
array<string|int, mixed>|null
$user
= null
$userId
public
int|null
$userId
= null
$uuid
public
string|null
$uuid
= null
$apiClient
protected
static HttpClientInterface
$apiClient
$course
protected
static Course
$course
$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
selfcanBeRemoved()
public
canBeRemoved() : bool|null
Return values
bool|nullcheckCourse()
Check if course context is set and valid
public
static checkCourse() : bool
Return values
boolcourse()
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
Return values
Course|null —The course object or null if no courseId is set
create()
public
static create(array<string, mixed>|CreateEnrollmentDTO $data) : self
Parameters
- $data : array<string, mixed>|CreateEnrollmentDTO
Return values
selfdelete()
Delete the current enrollment
public
delete() : bool
Return values
boolfetchAll()
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>fetchAllPaginated()
public
static fetchAllPaginated([array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
- $params : array<string|int, mixed> = []
Return values
PaginatedResponsefetchPage()
public
static fetchPage([array<string|int, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string|int, mixed> = []
Return values
PaginationResultfind()
Find a single record by ID
public
static find(int $id) : self
Parameters
- $id : int
Return values
selfgetCourse()
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
Return values
Course|null —The course object or null if no courseId is set
getCourseId()
public
getCourseId() : int|null
Return values
int|nullgetCreatedAt()
public
getCreatedAt() : string|null
Return values
string|nullgetCurrentGrade()
public
getCurrentGrade() : string|null
Return values
string|nullgetCurrentPoints()
public
getCurrentPoints() : float|null
Return values
float|nullgetCurrentScore()
public
getCurrentScore() : float|null
Return values
float|nullgetEndAt()
public
getEndAt() : string|null
Return values
string|nullgetEnrollmentState()
public
getEnrollmentState() : string|null
Return values
string|nullgetEnrollmentTermId()
public
getEnrollmentTermId() : int|null
Return values
int|nullgetFinalGrade()
public
getFinalGrade() : string|null
Return values
string|nullgetFinalScore()
public
getFinalScore() : float|null
Return values
float|nullgetGrades()
public
getGrades() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetGradingPeriodId()
public
getGradingPeriodId() : int|null
Return values
int|nullgetGroupIds()
public
getGroupIds() : array<string|int, int>|null
Return values
array<string|int, int>|nullgetId()
public
getId() : int|null
Return values
int|nullgetLastActivityAt()
public
getLastActivityAt() : string|null
Return values
string|nullgetObservedUsers()
public
getObservedUsers() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetRole()
public
getRole() : string|null
Return values
string|nullgetRoleId()
public
getRoleId() : int|null
Return values
int|nullgetRootAccountId()
public
getRootAccountId() : int|null
Return values
int|nullgetSectionId()
public
getSectionId() : int|null
Return values
int|nullgetSisAccountId()
public
getSisAccountId() : string|null
Return values
string|nullgetSisCourseId()
public
getSisCourseId() : string|null
Return values
string|nullgetSisSectionId()
public
getSisSectionId() : string|null
Return values
string|nullgetSisUserId()
public
getSisUserId() : string|null
Return values
string|nullgetStartAt()
public
getStartAt() : string|null
Return values
string|nullgetStateName()
Get a human-readable enrollment state name
public
getStateName() : string
Return values
stringgetTotalActivityTime()
public
getTotalActivityTime() : int|null
Return values
int|nullgetType()
public
getType() : string|null
Return values
string|nullgetTypeName()
Get a human-readable enrollment type name
public
getTypeName() : string
Return values
stringgetUnpostedCurrentGrade()
public
getUnpostedCurrentGrade() : string|null
Return values
string|nullgetUnpostedCurrentPoints()
public
getUnpostedCurrentPoints() : float|null
Return values
float|nullgetUnpostedCurrentScore()
public
getUnpostedCurrentScore() : float|null
Return values
float|nullgetUnpostedFinalGrade()
public
getUnpostedFinalGrade() : string|null
Return values
string|nullgetUnpostedFinalScore()
public
getUnpostedFinalScore() : float|null
Return values
float|nullgetUpdatedAt()
public
getUpdatedAt() : string|null
Return values
string|nullgetUser()
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
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>|nullgetUserId()
public
getUserId() : int|null
Return values
int|nullgetUuid()
public
getUuid() : string|null
Return values
string|nullisActive()
Check if this enrollment is active
public
isActive() : bool
Return values
boolisCompleted()
Check if this enrollment is completed
public
isCompleted() : bool
Return values
boolisDesigner()
Check if this enrollment is for a designer
public
isDesigner() : bool
Return values
boolisInactive()
Check if this enrollment is inactive
public
isInactive() : bool
Return values
boolisLimitPrivilegesToCourseSection()
public
isLimitPrivilegesToCourseSection() : bool|null
Return values
bool|nullisLocked()
public
isLocked() : bool|null
Return values
bool|nullisObserver()
Check if this enrollment is for an observer
public
isObserver() : bool
Return values
boolisPending()
Check if this enrollment is pending (invited)
public
isPending() : bool
Return values
boolisStudent()
Check if this enrollment is for a student
public
isStudent() : bool
Return values
boolisTa()
Check if this enrollment is for a TA
public
isTa() : bool
Return values
boolisTeacher()
Check if this enrollment is for a teacher
public
isTeacher() : bool
Return values
boolreactivate()
public
static reactivate(int $enrollmentId) : self
Parameters
- $enrollmentId : int
Return values
selfreject()
public
static reject(int $enrollmentId) : self
Parameters
- $enrollmentId : int
Return values
selfsave()
Save the current enrollment (create or update)
public
save() : bool
Return values
boolsetApiClient()
Set the API client
public
static setApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
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>update()
public
static update(int $id, array<string, mixed>|UpdateEnrollmentDTO $data) : self
Parameters
- $id : int
- $data : array<string, mixed>|UpdateEnrollmentDTO
Return values
selfuser()
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
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
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>createPaginationResult()
Helper method to create PaginationResult from paginated response
protected
static createPaginationResult(PaginatedResponse $paginatedResponse) : PaginationResult
Parameters
- $paginatedResponse : PaginatedResponse
Return values
PaginationResultfetchAllPagesAsModels()
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
PaginatedResponsepopulate()
Populate the object with new data
protected
populate(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Tags
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
boolvalidateEnrollmentType()
Validate enrollment type
private
validateEnrollmentType(string $type) : bool
Parameters
- $type : string