CalendarEvent
extends AbstractBaseApi
in package
CalendarEvent Class
Represents a calendar event in Canvas LMS. Calendar events enable course scheduling, assignment due dates, appointment slots, and general event management. Events can be associated with different contexts (courses, users, groups, accounts) and support recurring patterns, reservations, and time zone handling.
Canvas calendar events are versatile and can represent:
- Regular calendar events (meetings, deadlines, etc.)
- Assignment due dates
- Time slots for appointment groups
- Reservations for appointment slots
- Blackout dates for course pacing
Usage:
// Creating a calendar event directly
$dto = new CreateCalendarEventDTO();
$dto->contextCode = 'course_123';
$dto->title = 'Midterm Exam';
$dto->startAt = new DateTime('2025-03-15 10:00:00');
$dto->endAt = new DateTime('2025-03-15 12:00:00');
$event = CalendarEvent::create($dto);
// Finding a calendar event
$event = CalendarEvent::find(456);
// Listing all calendar events with filters
$events = CalendarEvent::get([
'start_date' => '2025-03-01',
'end_date' => '2025-03-31',
'context_codes' => ['course_123', 'user_456']
]);
// Updating an event
$updateDto = new UpdateCalendarEventDTO();
$updateDto->title = 'Midterm Exam - Room Changed';
$updateDto->locationName = 'Room 301';
$event = CalendarEvent::update(456, $updateDto);
// Working with recurring events
$dto->rrule = 'FREQ=WEEKLY;COUNT=10';
$recurringEvent = CalendarEvent::create($dto);
// Updating a series
$recurringEvent->updateSeries($updateDto, 'following');
// Making a reservation
$reservation = new CreateReservationDTO();
$reservation->participantId = 789;
$reservation->comments = 'Looking forward to the meeting';
$event->reserve($reservation);
Tags
Table of Contents
Properties
- $allContextCodes : string|null
- A comma-separated list of all calendar contexts this event is part of
- $allDay : bool|null
- Boolean indicating whether this is an all-day event (midnight to midnight)
- $allDayDate : string|null
- The date of this event (YYYY-MM-DD format)
- $appointmentGroupId : int|null
- The id of the appointment group
- $appointmentGroupUrl : string|null
- The API URL of the appointment group
- $availableSlots : int|null
- If the event is a time slot with a limit, how many slots are available
- $blackoutDate : bool|null
- Boolean indicating whether this has blackout date
- $childEvents : array<int, array<string, mixed>>|null
- If this is a time slot, this will be a list of any reservations If this is a course-level event, this will be a list of section-level events
- $childEventsCount : int|null
- The number of child_events
- $contextCode : string|null
- The context code of the calendar this event belongs to Format: {type}_{id} (e.g., course_123, user_456, group_789, account_1)
- $contextName : string|null
- The context name of the calendar this event belongs to
- $createdAt : DateTime|null
- When the calendar event was created
- $description : string|null
- The HTML description of the event
- $effectiveContextCode : string|null
- If specified, indicates which calendar this event should be displayed on (e.g., a section-level event would have the course's context code here)
- $endAt : DateTime|null
- The end timestamp of the event
- $group : array<string, mixed>|null
- If the event is a group-level reservation, contains the group participant
- $hidden : bool|null
- Whether this event should be displayed on the calendar Only true for course-level events with section-level child events
- $htmlUrl : string|null
- URL for a user to view this event
- $id : int|null
- The ID of the calendar event
- $importantDates : bool|null
- Boolean indicating whether this has important dates
- $locationAddress : string|null
- The address where the event is taking place
- $locationName : string|null
- The location name of the event
- $ownReservation : bool|null
- If the event is a reservation, whether it is the current user's reservation
- $parentEventId : int|null
- If this is a reservation, the id will indicate the time slot it is for If this is a section-level event, this will be the course-level parent event
- $participantsPerAppointment : int|null
- If the event is a time slot, this is the participant limit
- $participantType : string|null
- The type of participant to sign up for a slot: 'User' or 'Group'
- $reserved : bool|null
- If the event is a time slot, whether the user has already made a reservation
- $reserveUrl : string|null
- If the event is a time slot, the API URL for reserving it
- $rrule : string|null
- An iCalendar RRULE for defining how events in a recurring event series repeat
- $seriesHead : bool|null
- Boolean indicating if this is the first event in the series of recurring events
- $seriesNaturalLanguage : string|null
- A natural language expression of how events occur in the series
- $seriesUuid : string|null
- Identifies the recurring event series this event may belong to
- $startAt : DateTime|null
- The start timestamp of the event
- $title : string|null
- The title of the calendar event
- $updatedAt : DateTime|null
- When the calendar event was last updated
- $url : string|null
- URL for this calendar event (to update, delete, etc.)
- $user : array<string, mixed>|null
- If the event is a user-level reservation, contains the user participant
- $workflowState : string|null
- Current state of the event ('active', 'locked' or 'deleted') 'locked' indicates that start_at/end_at cannot be changed
- $apiClient : HttpClientInterface
- $contextId : int|null
- Context ID extracted from context code
- $contextType : string|null
- Context type extracted from context code
- $methodAliases : array<string|int, mixed>
- Define method aliases
Methods
- __callStatic() : mixed
- Magic method to handle function aliases
- __construct() : mixed
- Constructor
- __set() : void
- Magic setter to handle property casting
- all() : array<int, self>
- Get all calendar events from all pages
- create() : self
- Create a new calendar event
- delete() : self
- Delete a calendar event
- deleteSeries() : self
- Delete a series of recurring events
- fetchByContext() : array<int, self>
- Fetch calendar events by context
- find() : self
- Find a calendar event by ID
- get() : array<int, self>
- List calendar events
- getContextId() : int|null
- Get the context ID
- getContextType() : string|null
- Get the context type
- getNextAvailableAppointment() : self|null
- Get next available appointment
- paginate() : PaginationResult
- Get paginated calendar events
- parseContextCode() : array{type: string, id: int}
- Parse a context code into type and ID
- reserve() : self
- Reserve a time slot
- reserveSlot() : self
- Reserve a time slot (static method)
- save() : self
- Save the calendar event (create or update)
- saveEnabledAccountCalendars() : array<string, mixed>
- Save enabled account calendars
- setApiClient() : void
- Set the API client
- update() : self
- Update a calendar event
- updateSeries() : self
- Update a series of recurring events
- castValue() : mixed
- Cast value to appropriate type based on property
- 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|int, mixed>
- Convert the object to an array
Properties
$allContextCodes
A comma-separated list of all calendar contexts this event is part of
public
string|null
$allContextCodes
= null
$allDay
Boolean indicating whether this is an all-day event (midnight to midnight)
public
bool|null
$allDay
= null
$allDayDate
The date of this event (YYYY-MM-DD format)
public
string|null
$allDayDate
= null
$appointmentGroupId
The id of the appointment group
public
int|null
$appointmentGroupId
= null
$appointmentGroupUrl
The API URL of the appointment group
public
string|null
$appointmentGroupUrl
= null
$availableSlots
If the event is a time slot with a limit, how many slots are available
public
int|null
$availableSlots
= null
$blackoutDate
Boolean indicating whether this has blackout date
public
bool|null
$blackoutDate
= null
$childEvents
If this is a time slot, this will be a list of any reservations If this is a course-level event, this will be a list of section-level events
public
array<int, array<string, mixed>>|null
$childEvents
= null
$childEventsCount
The number of child_events
public
int|null
$childEventsCount
= null
$contextCode
The context code of the calendar this event belongs to Format: {type}_{id} (e.g., course_123, user_456, group_789, account_1)
public
string|null
$contextCode
= null
$contextName
The context name of the calendar this event belongs to
public
string|null
$contextName
= null
$createdAt
When the calendar event was created
public
DateTime|null
$createdAt
= null
$description
The HTML description of the event
public
string|null
$description
= null
$effectiveContextCode
If specified, indicates which calendar this event should be displayed on (e.g., a section-level event would have the course's context code here)
public
string|null
$effectiveContextCode
= null
$endAt
The end timestamp of the event
public
DateTime|null
$endAt
= null
$group
If the event is a group-level reservation, contains the group participant
public
array<string, mixed>|null
$group
= null
$hidden
Whether this event should be displayed on the calendar Only true for course-level events with section-level child events
public
bool|null
$hidden
= null
$htmlUrl
URL for a user to view this event
public
string|null
$htmlUrl
= null
$id
The ID of the calendar event
public
int|null
$id
= null
$importantDates
Boolean indicating whether this has important dates
public
bool|null
$importantDates
= null
$locationAddress
The address where the event is taking place
public
string|null
$locationAddress
= null
$locationName
The location name of the event
public
string|null
$locationName
= null
$ownReservation
If the event is a reservation, whether it is the current user's reservation
public
bool|null
$ownReservation
= null
$parentEventId
If this is a reservation, the id will indicate the time slot it is for If this is a section-level event, this will be the course-level parent event
public
int|null
$parentEventId
= null
$participantsPerAppointment
If the event is a time slot, this is the participant limit
public
int|null
$participantsPerAppointment
= null
$participantType
The type of participant to sign up for a slot: 'User' or 'Group'
public
string|null
$participantType
= null
$reserved
If the event is a time slot, whether the user has already made a reservation
public
bool|null
$reserved
= null
$reserveUrl
If the event is a time slot, the API URL for reserving it
public
string|null
$reserveUrl
= null
$rrule
An iCalendar RRULE for defining how events in a recurring event series repeat
public
string|null
$rrule
= null
$seriesHead
Boolean indicating if this is the first event in the series of recurring events
public
bool|null
$seriesHead
= null
$seriesNaturalLanguage
A natural language expression of how events occur in the series
public
string|null
$seriesNaturalLanguage
= null
$seriesUuid
Identifies the recurring event series this event may belong to
public
string|null
$seriesUuid
= null
$startAt
The start timestamp of the event
public
DateTime|null
$startAt
= null
$title
The title of the calendar event
public
string|null
$title
= null
$updatedAt
When the calendar event was last updated
public
DateTime|null
$updatedAt
= null
$url
URL for this calendar event (to update, delete, etc.)
public
string|null
$url
= null
$user
If the event is a user-level reservation, contains the user participant
public
array<string, mixed>|null
$user
= null
$workflowState
Current state of the event ('active', 'locked' or 'deleted') 'locked' indicates that start_at/end_at cannot be changed
public
string|null
$workflowState
= null
$apiClient
protected
static HttpClientInterface
$apiClient
= null
$contextId
Context ID extracted from context code
protected
int|null
$contextId
= null
$contextType
Context type extracted from context code
protected
string|null
$contextType
= 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()
Constructor
public
__construct([array<string, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string, mixed> = []
__set()
Magic setter to handle property casting
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
-
Property name
- $value : mixed
-
Property value
all()
Get all calendar events from all pages
public
static all([array<string, mixed> $params = [] ]) : array<int, self>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
array<int, self>create()
Create a new calendar event
public
static create(array<string, mixed>|CreateCalendarEventDTO $data) : self
Parameters
- $data : array<string, mixed>|CreateCalendarEventDTO
-
The event data
Tags
Return values
selfdelete()
Delete a calendar event
public
delete([array<string, mixed> $params = [] ]) : self
Parameters
- $params : array<string, mixed> = []
-
Parameters like 'cancel_reason', 'which'
Tags
Return values
selfdeleteSeries()
Delete a series of recurring events
public
deleteSeries([string $which = 'one' ][, string|null $cancelReason = null ]) : self
Parameters
- $which : string = 'one'
-
Which events to delete: 'one', 'all', 'following'
- $cancelReason : string|null = null
-
Optional reason for cancellation
Tags
Return values
selffetchByContext()
Fetch calendar events by context
public
static fetchByContext(string $contextType, int $contextId[, array<string, mixed> $params = [] ]) : array<int, self>
Parameters
- $contextType : string
-
Context type ('account', 'course', 'user', 'group')
- $contextId : int
-
Context ID
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
array<int, self>find()
Find a calendar event by ID
public
static find(int $id[, array<string, mixed> $params = [] ]) : self
Parameters
- $id : int
-
The calendar event ID
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
selfget()
List calendar events
public
static get([array<string, mixed> $params = [] ]) : array<int, self>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
array<int, self>getContextId()
Get the context ID
public
getContextId() : int|null
Return values
int|nullgetContextType()
Get the context type
public
getContextType() : string|null
Return values
string|nullgetNextAvailableAppointment()
Get next available appointment
public
static getNextAvailableAppointment([array<string|int, int> $appointmentGroupIds = [] ]) : self|null
Parameters
- $appointmentGroupIds : array<string|int, int> = []
-
Optional array of appointment group IDs to search
Tags
Return values
self|nullpaginate()
Get paginated calendar events
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
PaginationResultparseContextCode()
Parse a context code into type and ID
public
static parseContextCode(string $contextCode) : array{type: string, id: int}
Parameters
- $contextCode : string
-
Context code (e.g., 'course_123')
Tags
Return values
array{type: string, id: int}reserve()
Reserve a time slot
public
reserve(array<string, mixed>|CreateReservationDTO $data) : self
Parameters
- $data : array<string, mixed>|CreateReservationDTO
-
Reservation data
Tags
Return values
selfreserveSlot()
Reserve a time slot (static method)
public
static reserveSlot(int $eventId, array<string, mixed>|CreateReservationDTO $data[, int|null $participantId = null ]) : self
Parameters
- $eventId : int
-
The calendar event ID
- $data : array<string, mixed>|CreateReservationDTO
-
Reservation data
- $participantId : int|null = null
-
Optional participant ID
Tags
Return values
selfsave()
Save the calendar event (create or update)
public
save() : self
Tags
Return values
selfsaveEnabledAccountCalendars()
Save enabled account calendars
public
static saveEnabledAccountCalendars(array<string|int, int> $accountIds[, bool $markAsSeen = false ]) : array<string, mixed>
Parameters
- $accountIds : array<string|int, int>
-
Array of account IDs
- $markAsSeen : bool = false
-
Whether to mark the feature as seen
Tags
Return values
array<string, mixed>setApiClient()
Set the API client
public
static setApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
update()
Update a calendar event
public
static update(int $id, array<string, mixed>|UpdateCalendarEventDTO $updateData[, array<string, mixed> $params = [] ]) : self
Parameters
- $id : int
-
The calendar event ID
- $updateData : array<string, mixed>|UpdateCalendarEventDTO
-
The update data
- $params : array<string, mixed> = []
-
Additional parameters (e.g., 'which' for series)
Tags
Return values
selfupdateSeries()
Update a series of recurring events
public
updateSeries(array<string, mixed>|UpdateCalendarEventDTO $updateData[, string $which = 'one' ]) : self
Parameters
- $updateData : array<string, mixed>|UpdateCalendarEventDTO
-
Update data
- $which : string = 'one'
-
Which events to update: 'one', 'all', 'following'
Tags
Return values
selfcastValue()
Cast value to appropriate type based on property
protected
castValue(string $key, mixed $value) : mixed
Parameters
- $key : string
-
Property name
- $value : mixed
-
Value to cast
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>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
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 the object to an array
protected
toDtoArray() : array<string|int, mixed>