Documentation

Section extends AbstractBaseApi
in package

Canvas LMS Sections API

Provides functionality to manage course sections in Canvas LMS. Sections are ways to divide students in a course into smaller groups.

Usage Examples:

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

// Get all sections for the course
$sections = Section::get();

// Get sections with parameters
$sections = Section::get(['include' => ['students', 'enrollments']]);

// Find a specific section
$section = Section::find(456);

// Create a new section
$sectionData = [
    'name' => 'Lab Section A',
    'sisSectionId' => 'LAB001',
    'startAt' => '2024-01-15T00:00:00Z',
    'endAt' => '2024-05-15T23:59:59Z'
];
$section = Section::create($sectionData);

// Update a section
$updatedSection = Section::update(456, ['name' => 'Updated Lab Section A']);

// Update using instance method
$section = Section::find(456);
$section->setName('New Section Name');
$success = $section->save();

// Delete a section
$section = Section::find(456);
$success = $section->delete();

Table of Contents

Properties

$courseId  : int|null
Course ID this section belongs to
$endAt  : string|null
Section end date
$enrollments  : array<int, array<string, mixed>>|null
Enrollments array (populated when included)
$id  : int|null
Section unique identifier
$integrationId  : string|null
Integration ID
$name  : string|null
Section name
$nonxlistCourseId  : int|null
Nonxlist course ID if cross-listed
$passbackStatus  : string|null
Grade passback status
$permissions  : array<string, bool>|null
Section permissions
$restrictEnrollmentsToSectionDates  : bool|null
Whether this section restricts enrollments to students
$sisCourseId  : string|null
SIS course ID
$sisImportId  : int|null
SIS import ID
$sisSectionId  : string|null
SIS section ID
$startAt  : string|null
Section start date
$students  : array<string|int, mixed>|null
Students array (populated when included)
$totalStudents  : int|null
Total number of students in this section
$apiClient  : HttpClientInterface
$course  : Course|null
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Create a new Section instance
all()  : array<string|int, self>
Get all sections for the current course (paginated)
checkCourse()  : bool
Check if course context is set
course()  : Course
Get the associated course for this section
create()  : self
Create a new section
crossList()  : self
Cross-list a section to another course
deCrossList()  : self
De-cross-list a section (return it to its original course)
delete()  : self
Delete the section
enrollments()  : array<string|int, Enrollment>
Get enrollments for this section
find()  : self
Find a single section by ID
get()  : array<string|int, self>
Get sections for the current course
getCourseId()  : int|null
getEndAt()  : string|null
getId()  : int|null
getIntegrationId()  : string|null
getName()  : string|null
getNonxlistCourseId()  : int|null
getRestrictEnrollmentsToSectionDates()  : bool|null
getSisImportId()  : int|null
getSisSectionId()  : string|null
getStartAt()  : string|null
getTotalStudents()  : int|null
paginate()  : PaginationResult
Get sections with pagination support
save()  : self
Save the current section (create or update)
setApiClient()  : void
Set the API client
setCourse()  : void
Set the course context for section operations
setEndAt()  : void
setIntegrationId()  : void
setName()  : void
setRestrictEnrollmentsToSectionDates()  : void
setSisSectionId()  : void
setStartAt()  : void
students()  : array<string|int, Enrollment>
Get student enrollments for this section
toArray()  : array<string, mixed>
Convert section to array
toDtoArray()  : array<string, mixed>
Convert section to DTO array format
update()  : self
Update a section
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
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

Properties

$courseId

Course ID this section belongs to

public int|null $courseId = null

$endAt

Section end date

public string|null $endAt = null

$enrollments

Enrollments array (populated when included)

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

$id

Section unique identifier

public int|null $id = null

$integrationId

Integration ID

public string|null $integrationId = null

$name

Section name

public string|null $name = null

$nonxlistCourseId

Nonxlist course ID if cross-listed

public int|null $nonxlistCourseId = null

$passbackStatus

Grade passback status

public string|null $passbackStatus = null

$permissions

Section permissions

public array<string, bool>|null $permissions = null

$restrictEnrollmentsToSectionDates

Whether this section restricts enrollments to students

public bool|null $restrictEnrollmentsToSectionDates = null

$sisCourseId

SIS course ID

public string|null $sisCourseId = null

$sisImportId

SIS import ID

public int|null $sisImportId = null

$sisSectionId

SIS section ID

public string|null $sisSectionId = null

$startAt

Section start date

public string|null $startAt = null

$students

Students array (populated when included)

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

$totalStudents

Total number of students in this section

public int|null $totalStudents = 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
throws
InvalidArgumentException

__construct()

Create a new Section instance

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

Section data from Canvas API

all()

Get all sections for the current course (paginated)

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

Query parameters

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

checkCourse()

Check if course context is set

public static checkCourse() : bool
Tags
throws
CanvasApiException

If course is not set

Return values
bool

crossList()

Cross-list a section to another course

public static crossList(int $sectionId, int $newCourseId[, bool $overrideSisStickiness = true ]) : self
Parameters
$sectionId : int

Section ID to cross-list

$newCourseId : int

Target course ID

$overrideSisStickiness : bool = true

Override SIS stickiness

Tags
throws
CanvasApiException
Return values
self

Cross-listed Section object

deCrossList()

De-cross-list a section (return it to its original course)

public static deCrossList(int $sectionId[, bool $overrideSisStickiness = true ]) : self
Parameters
$sectionId : int

Section ID to de-cross-list

$overrideSisStickiness : bool = true

Override SIS stickiness

Tags
throws
CanvasApiException
Return values
self

De-cross-listed Section object

enrollments()

Get enrollments for this section

public enrollments([array<string, mixed> $params = [] ]) : array<string|int, Enrollment>
Parameters
$params : array<string, mixed> = []

Query parameters

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

find()

Find a single section by ID

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

Section ID

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
self

get()

Get sections for the current course

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

Query parameters

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

getCourseId()

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

getEndAt()

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

getId()

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

getIntegrationId()

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

getName()

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

getNonxlistCourseId()

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

getRestrictEnrollmentsToSectionDates()

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

getSisImportId()

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

getSisSectionId()

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

getStartAt()

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

getTotalStudents()

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

setCourse()

Set the course context for section operations

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

The course to operate on

setEndAt()

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

setIntegrationId()

public setIntegrationId(string|null $integrationId) : void
Parameters
$integrationId : string|null

setName()

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

setRestrictEnrollmentsToSectionDates()

public setRestrictEnrollmentsToSectionDates(bool|null $restrictEnrollmentsToSectionDates) : void
Parameters
$restrictEnrollmentsToSectionDates : bool|null

setSisSectionId()

public setSisSectionId(string|null $sisSectionId) : void
Parameters
$sisSectionId : string|null

setStartAt()

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

students()

Get student enrollments for this section

public students([array<string, mixed> $params = [] ]) : array<string|int, Enrollment>
Parameters
$params : array<string, mixed> = []

Query parameters

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

toArray()

Convert section to array

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

toDtoArray()

Convert section to DTO array format

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

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the API endpoint for this resource

protected static getEndpoint() : string
Tags
throws
CanvasApiException
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data

protected populate(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

        
On this page

Search results