Announcement
extends DiscussionTopic
in package
Canvas LMS Announcements API
Provides functionality to manage announcements in Canvas LMS. Announcements are special discussion topics that serve as one-way broadcasts from instructors to students. This class extends DiscussionTopic and automatically applies announcement-specific filters and defaults.
Usage Examples:
// Set course context (required for all operations)
$course = Course::find(123);
Announcement::setCourse($course);
// Create a new announcement
$announcementData = [
'title' => 'Important: Exam Schedule Update',
'message' => 'The midterm exam has been rescheduled to next Friday',
'published' => true,
'delayed_post_at' => '2024-03-01T09:00:00Z' // Schedule for future
];
$announcement = Announcement::create($announcementData);
// Find an announcement by ID
$announcement = Announcement::find(456);
// List all announcements for the course
$announcements = Announcement::get();
// Get only active announcements
$activeAnnouncements = Announcement::get(['active_only' => true]);
// Get paginated announcements
$paginatedAnnouncements = Announcement::paginate();
// Update an announcement
$updatedAnnouncement = Announcement::update(456, ['title' => 'Updated: Exam Schedule']);
// Lock/unlock an announcement to prevent/allow modifications
$announcement->lock();
$announcement->unlock();
// Delete an announcement
$announcement = Announcement::find(456);
$announcement->delete();
// Get global announcements across multiple courses
$contextCodes = ['course_123', 'course_456'];
$globalAnnouncements = Announcement::fetchGlobalAnnouncements($contextCodes);
Table of Contents
Properties
- $allowRating : bool|null
- Whether the discussion allows rating
- $assignmentId : int|null
- Assignment ID for graded discussions
- $attachments : array<string|int, mixed>|null
- Array of file attachments
- $author : array<string, mixed>|null
- Discussion topic author information
- $contextCode : string|null
- Context code for global announcements (populated when using fetchGlobalAnnouncements)
- $courseId : int|null
- Course ID this discussion topic belongs to
- $createdAt : DateTime|null
- Discussion topic creation timestamp
- $delayedPostAt : DateTime|null
- When the topic will be automatically published
- $discussionSubentryCount : int|null
- Number of replies in the topic
- $discussionType : string|null
- Discussion type (threaded, side_comment, etc.)
- $expand : bool|null
- Whether threaded replies should be expanded by default
- $expandLocked : bool|null
- Whether users can choose their preferred thread expansion setting
- $gradingType : string|null
- Grading type for graded discussions
- $groupCategoryId : int|null
- Group category ID for group discussions
- $groupTopic : bool|null
- Whether the discussion is for a group
- $groupTopicChildren : array<string|int, mixed>|null
- Group-specific child topics
- $htmlUrl : string|null
- HTML URL to the discussion topic
- $id : int|null
- Discussion topic unique identifier
- $isAnnouncement : bool|null
- Whether this is an announcement
- $lastReplyAt : DateTime|null
- When the last reply was posted
- $locked : bool|null
- Whether the discussion is locked
- $lockedForUser : bool|null
- Whether the topic is locked for the current user
- $lockExplanation : string|null
- Explanation of why the topic is locked
- $lockInfo : array<string, mixed>|null
- Information about why the topic is locked
- $message : string|null
- Discussion topic message/description (HTML)
- $onlyGradersCanRate : bool|null
- Whether rating is only for graders
- $permissions : array<string, mixed>|null
- User permissions for the topic
- $pinned : bool|null
- Whether the discussion is pinned
- $podcastUrl : string|null
- URL for podcast feed
- $pointsPossible : float|null
- Points possible for graded discussions
- $postedAt : DateTime|null
- When the discussion topic was posted
- $published : bool|null
- Whether the discussion topic is published
- $readOnly : bool|null
- Whether the discussion is read only
- $readState : string|null
- Read state for the current user (read, unread, partially_read)
- $requireInitialPost : bool|null
- Whether users must post before seeing replies
- $rootTopicId : int|null
- ID of the root topic (for group discussions)
- $sortByRating : bool|null
- Whether to sort entries by rating
- $sortOrder : string|null
- Default sort order of the discussion (asc or desc)
- $sortOrderLocked : bool|null
- Whether users can choose their preferred sort order
- $subscribed : bool|null
- Whether the current user is subscribed to notifications
- $subscriptionHold : string|null
- Subscription hold status
- $title : string|null
- Discussion topic title
- $topicChildren : array<string|int, mixed>|null
- Child topics (for threaded discussions)
- $unreadCount : int|null
- Number of unread entries for the current user
- $updatedAt : DateTime|null
- Discussion topic last update timestamp
- $userCanSeePosts : bool|null
- Whether users can see posts (based on require_initial_post)
- $userId : int|null
- User ID of the discussion author
- $userName : string|null
- Name of the topic author
- $workflowState : string|null
- Discussion workflow state
- $course : Course|null
- $methodAliases : array<string, array<string|int, string>>
- Define method aliases
Methods
- __callStatic() : mixed
- Magic method to handle function aliases
- __construct() : mixed
- Create a new DiscussionTopic instance
- all() : array<int, self>
- Get all announcements from all pages
- assignment() : Assignment|null
- Get the assignment associated with this discussion (if graded)
- author() : User|null
- Get the author of this discussion topic
- checkCourse() : bool
- Check if course context is set
- course() : Course|null
- Get the course this discussion topic belongs to
- create() : self
- Create a new announcement Overrides parent to ensure announcement flag is set
- delete() : self
- Delete the discussion topic
- fetchGlobalAnnouncements() : array<string|int, Announcement>
- Fetch global announcements across multiple courses Uses the /api/v1/announcements endpoint for cross-course announcements
- find() : static
- Find a single discussion topic by ID
- get() : array<string|int, Announcement>
- Fetch all announcements for the course Overrides parent to automatically filter for announcements only
- getAllowRating() : bool|null
- Get allow rating status
- getAssignmentId() : int|null
- Get assignment ID
- getAttachments() : array<string|int, mixed>|null
- Get attachments
- getAuthor() : array<string, mixed>|null
- Get author information
- getContextCode() : string|null
- Get context code (for global announcements)
- getCourseId() : int|null
- Get course ID
- getCreatedAt() : DateTime|null
- Get created at timestamp
- getDelayedPostAt() : DateTime|null
- Get delayed post at timestamp
- getDiscussionSubentryCount() : int|null
- Get discussion subentry count
- getDiscussionType() : string|null
- Get discussion type
- getExpand() : bool|null
- Get expand status
- getExpandLocked() : bool|null
- Get expand locked status
- getGradingType() : string|null
- Get grading type
- getGroupCategoryId() : int|null
- Get group category ID
- getGroupTopic() : bool|null
- Get group topic status
- getGroupTopicChildren() : array<string|int, mixed>|null
- Get group topic children
- getHtmlUrl() : string|null
- Get HTML URL
- getId() : int|null
- Get discussion topic ID
- getIsAnnouncement() : bool|null
- Get is announcement status
- getLastReplyAt() : DateTime|null
- Get last reply at timestamp
- getLocked() : bool|null
- Get locked status
- getLockedForUser() : bool|null
- Get locked for user status
- getLockExplanation() : string|null
- Get lock explanation
- getLockInfo() : array<string, mixed>|null
- Get lock info
- getMessage() : string|null
- Get discussion topic message
- getOnlyGradersCanRate() : bool|null
- Get only graders can rate status
- getPermissions() : array<string, mixed>|null
- Get permissions
- getPinned() : bool|null
- Get pinned status
- getPodcastUrl() : string|null
- Get podcast URL
- getPointsPossible() : float|null
- Get points possible
- getPostedAt() : DateTime|null
- Get posted at timestamp
- getPublished() : bool|null
- Get published status
- getReadOnly() : bool|null
- Get read only status
- getReadState() : string|null
- Get read state
- getRequireInitialPost() : bool|null
- Get require initial post status
- getRootTopicId() : int|null
- Get root topic ID
- getSortByRating() : bool|null
- Get sort by rating status
- getSortOrder() : string|null
- Get sort order
- getSortOrderLocked() : bool|null
- Get sort order locked status
- getSubscribed() : bool|null
- Get subscribed status
- getSubscriptionHold() : string|null
- Get subscription hold status
- getTitle() : string|null
- Get discussion topic title
- getTopicChildren() : array<string|int, mixed>|null
- Get topic children
- getUnreadCount() : int|null
- Get unread count
- getUpdatedAt() : DateTime|null
- Get updated at timestamp
- getUserCanSeePosts() : bool|null
- Get user can see posts status
- getUserId() : int|null
- Get user ID
- getUserName() : string|null
- Get user name
- getWorkflowState() : string|null
- Get workflow state
- lock() : bool
- Lock the discussion topic
- markAllAsRead() : bool
- Mark all discussion topics in course as read
- markAllAsUnread() : bool
- Mark all discussion topics in course as unread
- markAsRead() : bool
- Mark discussion topic as read
- markAsUnread() : bool
- Mark discussion topic as unread
- overrideApiClient() : void
- Set an API client for this class only, leaving other resources on the shared default.
- paginate() : PaginationResult
- Get paginated announcements
- pin() : bool
- Pin the discussion topic
- postImmediately() : self
- Post an announcement immediately (remove delayed posting)
- resetApiClients() : void
- Clear the shared default client and all per-class overrides.
- save() : static
- Save the current announcement (create or update) Overrides parent to ensure announcement-specific validation
- scheduleFor() : self
- Schedule an announcement to be posted at a future date
- setAllowRating() : void
- Set allow rating status
- setApiClient() : void
- Set the shared default API client used by ALL resource classes.
- setAssignmentId() : void
- Set assignment ID
- setAttachments() : void
- Set attachments
- setAuthor() : void
- Set author information
- setContextCode() : void
- Set context code (for global announcements)
- setCourse() : void
- Set the course context for discussion topic operations
- setCourseId() : void
- Set course ID
- setCreatedAt() : void
- Set created at timestamp
- setDelayedPostAt() : void
- Set delayed post at timestamp
- setDiscussionSubentryCount() : void
- Set discussion subentry count
- setDiscussionType() : void
- Set discussion type
- setExpand() : void
- Set expand status
- setExpandLocked() : void
- Set expand locked status
- setGradingType() : void
- Set grading type
- setGroupCategoryId() : void
- Set group category ID
- setGroupTopic() : void
- Set group topic status
- setGroupTopicChildren() : void
- Set group topic children
- setHtmlUrl() : void
- Set HTML URL
- setId() : void
- Set discussion topic ID
- setIsAnnouncement() : void
- Set is announcement status
- setLastReplyAt() : void
- Set last reply at timestamp
- setLocked() : void
- Set locked status
- setLockedForUser() : void
- Set locked for user status
- setLockExplanation() : void
- Set lock explanation
- setLockInfo() : void
- Set lock info
- setMessage() : void
- Set discussion topic message
- setOnlyGradersCanRate() : void
- Set only graders can rate status
- setPermissions() : void
- Set permissions
- setPinned() : void
- Set pinned status
- setPodcastUrl() : void
- Set podcast URL
- setPointsPossible() : void
- Set points possible
- setPostedAt() : void
- Set posted at timestamp
- setPublished() : void
- Set published status
- setReadOnly() : void
- Set read only status
- setReadState() : void
- Set read state
- setRequireInitialPost() : void
- Set require initial post status
- setRootTopicId() : void
- Set root topic ID
- setSortByRating() : void
- Set sort by rating status
- setSortOrder() : void
- Set sort order
- setSortOrderLocked() : void
- Set sort order locked status
- setSubscribed() : void
- Set subscribed status
- setSubscriptionHold() : void
- Set subscription hold status
- setTitle() : void
- Set discussion topic title
- setTopicChildren() : void
- Set topic children
- setUnreadCount() : void
- Set unread count
- setUpdatedAt() : void
- Set updated at timestamp
- setUserCanSeePosts() : void
- Set user can see posts status
- setUserId() : void
- Set user ID
- setUserName() : void
- Set user name
- setWorkflowState() : void
- Set workflow state
- stream() : Generator<int, static>
- Stream all items across all pages one at a time.
- subscribe() : bool
- Subscribe to discussion topic notifications
- toArray() : array<string, mixed>
- Convert discussion topic to array
- toDtoArray() : array<string, mixed>
- Convert discussion topic to DTO array format
- unlock() : bool
- Unlock the discussion topic
- unpin() : bool
- Unpin the discussion topic
- unsubscribe() : bool
- Unsubscribe from discussion topic notifications
- update() : self
- Update an announcement Overrides parent to use announcement-specific DTO
- 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
- getAliasMap() : array<string, string>
- Build a flat alias-to-method lookup from $methodAliases.
- getApiClient() : HttpClientInterface
- Get the API client, initializing if necessary
- getContextCourseId() : int
- Get the Course ID from context, ensuring course is set
- getCourse() : Course
- Get the Course instance, ensuring it is set
- getEndpoint() : string
- Get the API endpoint for this resource
- getPaginatedResponse() : PaginatedResponse
- Helper method to get paginated response from API endpoint
- hydrate() : void
- Assign API response data to properties with type coercion.
- parseJsonResponse() : array<string|int, mixed>
- Parse JSON response from API safely handling StreamInterface
- populate() : void
- Populate the object with new data
- validateContext() : void
- Validate a context type path segment against an allowlist.
Properties
$allowRating
Whether the discussion allows rating
public
bool|null
$allowRating
= null
$assignmentId
Assignment ID for graded discussions
public
int|null
$assignmentId
= null
$attachments
Array of file attachments
public
array<string|int, mixed>|null
$attachments
= null
$author
Discussion topic author information
public
array<string, mixed>|null
$author
= null
$contextCode
Context code for global announcements (populated when using fetchGlobalAnnouncements)
public
string|null
$contextCode
= null
$courseId
Course ID this discussion topic belongs to
public
int|null
$courseId
= null
$createdAt
Discussion topic creation timestamp
public
DateTime|null
$createdAt
= null
$delayedPostAt
When the topic will be automatically published
public
DateTime|null
$delayedPostAt
= null
$discussionSubentryCount
Number of replies in the topic
public
int|null
$discussionSubentryCount
= null
$discussionType
Discussion type (threaded, side_comment, etc.)
public
string|null
$discussionType
= null
$expand
Whether threaded replies should be expanded by default
public
bool|null
$expand
= null
$expandLocked
Whether users can choose their preferred thread expansion setting
public
bool|null
$expandLocked
= null
$gradingType
Grading type for graded discussions
public
string|null
$gradingType
= null
$groupCategoryId
Group category ID for group discussions
public
int|null
$groupCategoryId
= null
$groupTopic
Whether the discussion is for a group
public
bool|null
$groupTopic
= null
$groupTopicChildren
Group-specific child topics
public
array<string|int, mixed>|null
$groupTopicChildren
= null
$htmlUrl
HTML URL to the discussion topic
public
string|null
$htmlUrl
= null
$id
Discussion topic unique identifier
public
int|null
$id
= null
$isAnnouncement
Whether this is an announcement
public
bool|null
$isAnnouncement
= null
$lastReplyAt
When the last reply was posted
public
DateTime|null
$lastReplyAt
= null
$locked
Whether the discussion is locked
public
bool|null
$locked
= null
$lockedForUser
Whether the topic is locked for the current user
public
bool|null
$lockedForUser
= null
$lockExplanation
Explanation of why the topic is locked
public
string|null
$lockExplanation
= null
$lockInfo
Information about why the topic is locked
public
array<string, mixed>|null
$lockInfo
= null
$message
Discussion topic message/description (HTML)
public
string|null
$message
= null
$onlyGradersCanRate
Whether rating is only for graders
public
bool|null
$onlyGradersCanRate
= null
$permissions
User permissions for the topic
public
array<string, mixed>|null
$permissions
= null
$pinned
Whether the discussion is pinned
public
bool|null
$pinned
= null
$podcastUrl
URL for podcast feed
public
string|null
$podcastUrl
= null
$pointsPossible
Points possible for graded discussions
public
float|null
$pointsPossible
= null
$postedAt
When the discussion topic was posted
public
DateTime|null
$postedAt
= null
$published
Whether the discussion topic is published
public
bool|null
$published
= null
$readOnly
Whether the discussion is read only
public
bool|null
$readOnly
= null
$readState
Read state for the current user (read, unread, partially_read)
public
string|null
$readState
= null
$requireInitialPost
Whether users must post before seeing replies
public
bool|null
$requireInitialPost
= null
$rootTopicId
ID of the root topic (for group discussions)
public
int|null
$rootTopicId
= null
$sortByRating
Whether to sort entries by rating
public
bool|null
$sortByRating
= null
$sortOrder
Default sort order of the discussion (asc or desc)
public
string|null
$sortOrder
= null
$sortOrderLocked
Whether users can choose their preferred sort order
public
bool|null
$sortOrderLocked
= null
$subscribed
Whether the current user is subscribed to notifications
public
bool|null
$subscribed
= null
$subscriptionHold
Subscription hold status
public
string|null
$subscriptionHold
= null
$title
Discussion topic title
public
string|null
$title
= null
$topicChildren
Child topics (for threaded discussions)
public
array<string|int, mixed>|null
$topicChildren
= null
$unreadCount
Number of unread entries for the current user
public
int|null
$unreadCount
= null
$updatedAt
Discussion topic last update timestamp
public
DateTime|null
$updatedAt
= null
$userCanSeePosts
Whether users can see posts (based on require_initial_post)
public
bool|null
$userCanSeePosts
= null
$userId
User ID of the discussion author
public
int|null
$userId
= null
$userName
Name of the topic author
public
string|null
$userName
= null
$workflowState
Discussion workflow state
public
string|null
$workflowState
= null
$course
protected
static Course|null
$course
= null
$methodAliases
Define method aliases
protected
static array<string, array<string|int, string>>
$methodAliases
= ['get' => ['fetch', 'list'], 'all' => ['fetchAllPages', 'getAll', 'fetchAll'], 'paginate' => ['getPaginated', 'withPagination'], '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()
Create a new DiscussionTopic instance
public
__construct([array<string, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string, mixed> = []
-
Discussion topic data from Canvas API
all()
Get all announcements 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>assignment()
Get the assignment associated with this discussion (if graded)
public
assignment() : Assignment|null
Tags
Return values
Assignment|nullauthor()
Get the author of this discussion topic
public
author() : User|null
Tags
Return values
User|nullcheckCourse()
Check if course context is set
public
static checkCourse() : bool
Tags
Return values
boolcourse()
Get the course this discussion topic belongs to
public
course() : Course|null
Return values
Course|nullcreate()
Create a new announcement Overrides parent to ensure announcement flag is set
public
static create(array<string, mixed>|CreateAnnouncementDTO|CreateDiscussionTopicDTO $data) : self
Parameters
- $data : array<string, mixed>|CreateAnnouncementDTO|CreateDiscussionTopicDTO
-
Announcement data
Tags
Return values
self —Created Announcement object
delete()
Delete the discussion topic
public
delete() : self
Tags
Return values
selffetchGlobalAnnouncements()
Fetch global announcements across multiple courses Uses the /api/v1/announcements endpoint for cross-course announcements
public
static fetchGlobalAnnouncements(array<string|int, string> $contextCodes[, array<string, mixed> $params = [] ]) : array<string|int, Announcement>
Parameters
- $contextCodes : array<string|int, string>
-
Array of context codes (e.g., ['course_123', 'course_456'])
- $params : array<string, mixed> = []
-
Optional parameters (start_date, end_date, active_only, latest_only, include)
Tags
Return values
array<string|int, Announcement> —Array of Announcement objects with context_code added
find()
Find a single discussion topic by ID
public
static find(int $id[, array<string, mixed> $params = [] ]) : static
Parameters
- $id : int
-
Discussion topic ID
- $params : array<string, mixed> = []
-
Optional query parameters
Tags
Return values
staticget()
Fetch all announcements for the course Overrides parent to automatically filter for announcements only
public
static get([array<string, mixed> $params = [] ]) : array<string|int, Announcement>
Parameters
- $params : array<string, mixed> = []
-
Optional parameters
Tags
Return values
array<string|int, Announcement> —Array of Announcement objects
getAllowRating()
Get allow rating status
public
getAllowRating() : bool|null
Return values
bool|nullgetAssignmentId()
Get assignment ID
public
getAssignmentId() : int|null
Return values
int|nullgetAttachments()
Get attachments
public
getAttachments() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetAuthor()
Get author information
public
getAuthor() : array<string, mixed>|null
Return values
array<string, mixed>|nullgetContextCode()
Get context code (for global announcements)
public
getContextCode() : string|null
Return values
string|nullgetCourseId()
Get course ID
public
getCourseId() : int|null
Return values
int|nullgetCreatedAt()
Get created at timestamp
public
getCreatedAt() : DateTime|null
Return values
DateTime|nullgetDelayedPostAt()
Get delayed post at timestamp
public
getDelayedPostAt() : DateTime|null
Return values
DateTime|nullgetDiscussionSubentryCount()
Get discussion subentry count
public
getDiscussionSubentryCount() : int|null
Return values
int|nullgetDiscussionType()
Get discussion type
public
getDiscussionType() : string|null
Return values
string|nullgetExpand()
Get expand status
public
getExpand() : bool|null
Return values
bool|nullgetExpandLocked()
Get expand locked status
public
getExpandLocked() : bool|null
Return values
bool|nullgetGradingType()
Get grading type
public
getGradingType() : string|null
Return values
string|nullgetGroupCategoryId()
Get group category ID
public
getGroupCategoryId() : int|null
Return values
int|nullgetGroupTopic()
Get group topic status
public
getGroupTopic() : bool|null
Return values
bool|nullgetGroupTopicChildren()
Get group topic children
public
getGroupTopicChildren() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetHtmlUrl()
Get HTML URL
public
getHtmlUrl() : string|null
Return values
string|nullgetId()
Get discussion topic ID
public
getId() : int|null
Return values
int|nullgetIsAnnouncement()
Get is announcement status
public
getIsAnnouncement() : bool|null
Return values
bool|nullgetLastReplyAt()
Get last reply at timestamp
public
getLastReplyAt() : DateTime|null
Return values
DateTime|nullgetLocked()
Get locked status
public
getLocked() : bool|null
Return values
bool|nullgetLockedForUser()
Get locked for user status
public
getLockedForUser() : bool|null
Return values
bool|nullgetLockExplanation()
Get lock explanation
public
getLockExplanation() : string|null
Return values
string|nullgetLockInfo()
Get lock info
public
getLockInfo() : array<string, mixed>|null
Return values
array<string, mixed>|nullgetMessage()
Get discussion topic message
public
getMessage() : string|null
Return values
string|nullgetOnlyGradersCanRate()
Get only graders can rate status
public
getOnlyGradersCanRate() : bool|null
Return values
bool|nullgetPermissions()
Get permissions
public
getPermissions() : array<string, mixed>|null
Return values
array<string, mixed>|nullgetPinned()
Get pinned status
public
getPinned() : bool|null
Return values
bool|nullgetPodcastUrl()
Get podcast URL
public
getPodcastUrl() : string|null
Return values
string|nullgetPointsPossible()
Get points possible
public
getPointsPossible() : float|null
Return values
float|nullgetPostedAt()
Get posted at timestamp
public
getPostedAt() : DateTime|null
Return values
DateTime|nullgetPublished()
Get published status
public
getPublished() : bool|null
Return values
bool|nullgetReadOnly()
Get read only status
public
getReadOnly() : bool|null
Return values
bool|nullgetReadState()
Get read state
public
getReadState() : string|null
Return values
string|nullgetRequireInitialPost()
Get require initial post status
public
getRequireInitialPost() : bool|null
Return values
bool|nullgetRootTopicId()
Get root topic ID
public
getRootTopicId() : int|null
Return values
int|nullgetSortByRating()
Get sort by rating status
public
getSortByRating() : bool|null
Return values
bool|nullgetSortOrder()
Get sort order
public
getSortOrder() : string|null
Return values
string|nullgetSortOrderLocked()
Get sort order locked status
public
getSortOrderLocked() : bool|null
Return values
bool|nullgetSubscribed()
Get subscribed status
public
getSubscribed() : bool|null
Return values
bool|nullgetSubscriptionHold()
Get subscription hold status
public
getSubscriptionHold() : string|null
Return values
string|nullgetTitle()
Get discussion topic title
public
getTitle() : string|null
Return values
string|nullgetTopicChildren()
Get topic children
public
getTopicChildren() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|nullgetUnreadCount()
Get unread count
public
getUnreadCount() : int|null
Return values
int|nullgetUpdatedAt()
Get updated at timestamp
public
getUpdatedAt() : DateTime|null
Return values
DateTime|nullgetUserCanSeePosts()
Get user can see posts status
public
getUserCanSeePosts() : bool|null
Return values
bool|nullgetUserId()
Get user ID
public
getUserId() : int|null
Return values
int|nullgetUserName()
Get user name
public
getUserName() : string|null
Return values
string|nullgetWorkflowState()
Get workflow state
public
getWorkflowState() : string|null
Return values
string|nulllock()
Lock the discussion topic
public
lock() : bool
Tags
Return values
bool —True if locking was successful, false otherwise
markAllAsRead()
Mark all discussion topics in course as read
public
static markAllAsRead() : bool
Tags
Return values
bool —True if marking all as read was successful, false otherwise
markAllAsUnread()
Mark all discussion topics in course as unread
public
static markAllAsUnread() : bool
Tags
Return values
bool —True if marking all as unread was successful, false otherwise
markAsRead()
Mark discussion topic as read
public
markAsRead() : bool
Tags
Return values
bool —True if marking as read was successful, false otherwise
markAsUnread()
Mark discussion topic as unread
public
markAsUnread() : bool
Tags
Return values
bool —True if marking as unread was successful, false otherwise
overrideApiClient()
Set an API client for this class only, leaving other resources on the shared default.
public
static overrideApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
paginate()
Get paginated announcements
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Tags
Return values
PaginationResultpin()
Pin the discussion topic
public
pin() : bool
Tags
Return values
bool —True if pinning was successful, false otherwise
postImmediately()
Post an announcement immediately (remove delayed posting)
public
postImmediately() : self
Tags
Return values
selfresetApiClients()
Clear the shared default client and all per-class overrides.
public
static resetApiClients() : void
save()
Save the current announcement (create or update) Overrides parent to ensure announcement-specific validation
public
save() : static
Tags
Return values
staticscheduleFor()
Schedule an announcement to be posted at a future date
public
scheduleFor(string $datetime) : self
Parameters
- $datetime : string
-
ISO 8601 formatted datetime (e.g., '2024-03-15T10:00:00Z')
Tags
Return values
selfsetAllowRating()
Set allow rating status
public
setAllowRating(bool|null $allowRating) : void
Parameters
- $allowRating : bool|null
setApiClient()
Set the shared default API client used by ALL resource classes.
public
static setApiClient(HttpClientInterface $apiClient) : void
Calling this on any resource (e.g. Course::setApiClient()) replaces the client for every resource, because relationship methods cross class boundaries ($course->enrollments() calls Enrollment internally). Use overrideApiClient() to scope a client to a single class, and resetApiClients() in test teardown to avoid state leaking.
Parameters
- $apiClient : HttpClientInterface
setAssignmentId()
Set assignment ID
public
setAssignmentId(int|null $assignmentId) : void
Parameters
- $assignmentId : int|null
setAttachments()
Set attachments
public
setAttachments(array<string|int, mixed>|null $attachments) : void
Parameters
- $attachments : array<string|int, mixed>|null
setAuthor()
Set author information
public
setAuthor(array<string, mixed>|null $author) : void
Parameters
- $author : array<string, mixed>|null
setContextCode()
Set context code (for global announcements)
public
setContextCode(string|null $contextCode) : void
Parameters
- $contextCode : string|null
setCourse()
Set the course context for discussion topic 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(DateTime|null $createdAt) : void
Parameters
- $createdAt : DateTime|null
setDelayedPostAt()
Set delayed post at timestamp
public
setDelayedPostAt(DateTime|null $delayedPostAt) : void
Parameters
- $delayedPostAt : DateTime|null
setDiscussionSubentryCount()
Set discussion subentry count
public
setDiscussionSubentryCount(int|null $discussionSubentryCount) : void
Parameters
- $discussionSubentryCount : int|null
setDiscussionType()
Set discussion type
public
setDiscussionType(string|null $discussionType) : void
Parameters
- $discussionType : string|null
setExpand()
Set expand status
public
setExpand(bool|null $expand) : void
Parameters
- $expand : bool|null
setExpandLocked()
Set expand locked status
public
setExpandLocked(bool|null $expandLocked) : void
Parameters
- $expandLocked : bool|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
setGroupTopic()
Set group topic status
public
setGroupTopic(bool|null $groupTopic) : void
Parameters
- $groupTopic : bool|null
setGroupTopicChildren()
Set group topic children
public
setGroupTopicChildren(array<string|int, mixed>|null $groupTopicChildren) : void
Parameters
- $groupTopicChildren : array<string|int, mixed>|null
setHtmlUrl()
Set HTML URL
public
setHtmlUrl(string|null $htmlUrl) : void
Parameters
- $htmlUrl : string|null
setId()
Set discussion topic ID
public
setId(int|null $id) : void
Parameters
- $id : int|null
setIsAnnouncement()
Set is announcement status
public
setIsAnnouncement(bool|null $isAnnouncement) : void
Parameters
- $isAnnouncement : bool|null
setLastReplyAt()
Set last reply at timestamp
public
setLastReplyAt(DateTime|null $lastReplyAt) : void
Parameters
- $lastReplyAt : DateTime|null
setLocked()
Set locked status
public
setLocked(bool|null $locked) : void
Parameters
- $locked : bool|null
setLockedForUser()
Set locked for user status
public
setLockedForUser(bool|null $lockedForUser) : void
Parameters
- $lockedForUser : bool|null
setLockExplanation()
Set lock explanation
public
setLockExplanation(string|null $lockExplanation) : void
Parameters
- $lockExplanation : string|null
setLockInfo()
Set lock info
public
setLockInfo(array<string, mixed>|null $lockInfo) : void
Parameters
- $lockInfo : array<string, mixed>|null
setMessage()
Set discussion topic message
public
setMessage(string|null $message) : void
Parameters
- $message : string|null
setOnlyGradersCanRate()
Set only graders can rate status
public
setOnlyGradersCanRate(bool|null $onlyGradersCanRate) : void
Parameters
- $onlyGradersCanRate : bool|null
setPermissions()
Set permissions
public
setPermissions(array<string, mixed>|null $permissions) : void
Parameters
- $permissions : array<string, mixed>|null
setPinned()
Set pinned status
public
setPinned(bool|null $pinned) : void
Parameters
- $pinned : bool|null
setPodcastUrl()
Set podcast URL
public
setPodcastUrl(string|null $podcastUrl) : void
Parameters
- $podcastUrl : string|null
setPointsPossible()
Set points possible
public
setPointsPossible(float|null $pointsPossible) : void
Parameters
- $pointsPossible : float|null
setPostedAt()
Set posted at timestamp
public
setPostedAt(DateTime|null $postedAt) : void
Parameters
- $postedAt : DateTime|null
setPublished()
Set published status
public
setPublished(bool|null $published) : void
Parameters
- $published : bool|null
setReadOnly()
Set read only status
public
setReadOnly(bool|null $readOnly) : void
Parameters
- $readOnly : bool|null
setReadState()
Set read state
public
setReadState(string|null $readState) : void
Parameters
- $readState : string|null
setRequireInitialPost()
Set require initial post status
public
setRequireInitialPost(bool|null $requireInitialPost) : void
Parameters
- $requireInitialPost : bool|null
setRootTopicId()
Set root topic ID
public
setRootTopicId(int|null $rootTopicId) : void
Parameters
- $rootTopicId : int|null
setSortByRating()
Set sort by rating status
public
setSortByRating(bool|null $sortByRating) : void
Parameters
- $sortByRating : bool|null
setSortOrder()
Set sort order
public
setSortOrder(string|null $sortOrder) : void
Parameters
- $sortOrder : string|null
setSortOrderLocked()
Set sort order locked status
public
setSortOrderLocked(bool|null $sortOrderLocked) : void
Parameters
- $sortOrderLocked : bool|null
setSubscribed()
Set subscribed status
public
setSubscribed(bool|null $subscribed) : void
Parameters
- $subscribed : bool|null
setSubscriptionHold()
Set subscription hold status
public
setSubscriptionHold(string|null $subscriptionHold) : void
Parameters
- $subscriptionHold : string|null
setTitle()
Set discussion topic title
public
setTitle(string|null $title) : void
Parameters
- $title : string|null
setTopicChildren()
Set topic children
public
setTopicChildren(array<string|int, mixed>|null $topicChildren) : void
Parameters
- $topicChildren : array<string|int, mixed>|null
setUnreadCount()
Set unread count
public
setUnreadCount(int|null $unreadCount) : void
Parameters
- $unreadCount : int|null
setUpdatedAt()
Set updated at timestamp
public
setUpdatedAt(DateTime|null $updatedAt) : void
Parameters
- $updatedAt : DateTime|null
setUserCanSeePosts()
Set user can see posts status
public
setUserCanSeePosts(bool|null $userCanSeePosts) : void
Parameters
- $userCanSeePosts : bool|null
setUserId()
Set user ID
public
setUserId(int|null $userId) : void
Parameters
- $userId : int|null
setUserName()
Set user name
public
setUserName(string|null $userName) : void
Parameters
- $userName : string|null
setWorkflowState()
Set workflow state
public
setWorkflowState(string|null $workflowState) : void
Parameters
- $workflowState : string|null
stream()
Stream all items across all pages one at a time.
public
static stream([array<string|int, mixed> $params = [] ]) : Generator<int, static>
Unlike all(), only one page of raw data is held in memory at a time, making this safe for very large datasets (e.g. tens of thousands of enrollments):
foreach (User::stream(['per_page' => 100]) as $user) {
processUser($user);
}
Parameters
- $params : array<string|int, mixed> = []
-
Query parameters for the request
Tags
Return values
Generator<int, static>subscribe()
Subscribe to discussion topic notifications
public
subscribe() : bool
Tags
Return values
bool —True if subscription was successful, false otherwise
toArray()
Convert discussion topic to array
public
toArray() : array<string, mixed>
Return values
array<string, mixed>toDtoArray()
Convert discussion topic to DTO array format
public
toDtoArray() : array<string, mixed>
Return values
array<string, mixed>unlock()
Unlock the discussion topic
public
unlock() : bool
Tags
Return values
bool —True if unlocking was successful, false otherwise
unpin()
Unpin the discussion topic
public
unpin() : bool
Tags
Return values
bool —True if unpinning was successful, false otherwise
unsubscribe()
Unsubscribe from discussion topic notifications
public
unsubscribe() : bool
Tags
Return values
bool —True if unsubscription was successful, false otherwise
update()
Update an announcement Overrides parent to use announcement-specific DTO
public
static update(int $id, array<string, mixed>|UpdateAnnouncementDTO|UpdateDiscussionTopicDTO $data) : self
Parameters
- $id : int
-
Announcement ID
- $data : array<string, mixed>|UpdateAnnouncementDTO|UpdateDiscussionTopicDTO
-
Announcement data
Tags
Return values
self —Updated Announcement object
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>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
PaginationResultgetAliasMap()
Build a flat alias-to-method lookup from $methodAliases.
protected
static getAliasMap() : array<string, string>
Return values
array<string, string>getApiClient()
Get the API client, initializing if necessary
protected
static getApiClient() : HttpClientInterface
Return values
HttpClientInterfacegetContextCourseId()
Get the Course ID from context, ensuring course is set
protected
static getContextCourseId() : int
Tags
Return values
intgetCourse()
Get the Course instance, ensuring it is set
protected
static getCourse() : Course
Tags
Return values
CoursegetEndpoint()
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
PaginatedResponsehydrate()
Assign API response data to properties with type coercion.
protected
hydrate(array<string|int, mixed> $data) : void
Shared by the constructor and populate() so objects keep the same type guarantees after save()/update() round-trips as on creation.
Parameters
- $data : array<string|int, mixed>
parseJsonResponse()
Parse JSON response from API safely handling StreamInterface
protected
static parseJsonResponse(ResponseInterface $response) : array<string|int, mixed>
Parameters
- $response : ResponseInterface
Return values
array<string|int, mixed>populate()
Populate the object with new data
protected
populate(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Tags
validateContext()
Validate a context type path segment against an allowlist.
protected
static validateContext(string|null $contextType, array<int, string> $allowed) : void
Context types are interpolated into URL paths; validating against the contexts Canvas actually supports prevents crafted values from injecting extra path segments or query parameters.
Parameters
- $contextType : string|null
-
The context type (plural, e.g. 'courses'); null is ignored
- $allowed : array<int, string>
-
Allowed context types