Tab
extends AbstractBaseApi
in package
Canvas LMS Tabs API
Provides functionality to manage course tabs in Canvas LMS. This class handles listing and updating tabs for a specific course.
Usage Examples:
// Set course context (required for all operations)
$course = Course::find(123);
Tab::setCourse($course);
// List all tabs for the course
$tabs = Tab::get();
// Get paginated tabs
$paginationResult = Tab::paginate();
// Update a tab
$updatedTab = Tab::update('assignments', ['position' => 3, 'hidden' => false]);
// Update using DTO
$updateDto = new UpdateTabDTO(position: 2, hidden: true);
$updatedTab = Tab::update('home', $updateDto);
// Update using instance method
$tab = Tab::get()[0];
$tab->position = 5;
$tab->hidden = true;
$success = $tab->save();
Table of Contents
Properties
- $hidden : bool|null
- Whether the tab is hidden from students
- $htmlUrl : string|null
- HTML URL of the tab
- $id : string|null
- Unique identifier for the tab
- $label : string|null
- Display label for the tab
- $position : int|null
- Position of the tab in the navigation (1-based)
- $type : string|null
- Type of tab (internal or external)
- $visibility : string|null
- Visibility level of the tab (public, members, admins, none)
- $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 Tab instance
- all() : array<string|int, static>
- Get all pages of results
- checkCourse() : bool
- Check if course context is set
- find() : static
- Find a single tab by ID
- get() : array<string|int, static>
- Get first page of results
- getHidden() : bool|null
- Get hidden status
- getHtmlUrl() : string|null
- Get HTML URL
- getId() : string|null
- Get ID
- getLabel() : string|null
- Get label
- getPosition() : int|null
- Get position
- getType() : string|null
- Get type
- getVisibility() : string|null
- Get visibility
- paginate() : PaginationResult
- Get paginated results with metadata
- save() : self
- Save the current tab (update only)
- setApiClient() : void
- Set the API client
- setCourse() : void
- Set the course context for tab operations
- setHidden() : void
- Set hidden status
- setHtmlUrl() : void
- Set HTML URL
- setId() : void
- Set ID
- setLabel() : void
- Set label
- setPosition() : void
- Set position
- setType() : void
- Set type
- setVisibility() : void
- Set visibility
- toArray() : array<string, mixed>
- Convert tab to array
- toDtoArray() : array<string, mixed>
- Convert tab to DTO array format
- update() : self
- Update a tab
- 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
$hidden
Whether the tab is hidden from students
public
bool|null
$hidden
= null
$htmlUrl
HTML URL of the tab
public
string|null
$htmlUrl
= null
$id
Unique identifier for the tab
public
string|null
$id
= null
$label
Display label for the tab
public
string|null
$label
= null
$position
Position of the tab in the navigation (1-based)
public
int|null
$position
= null
$type
Type of tab (internal or external)
public
string|null
$type
= null
$visibility
Visibility level of the tab (public, members, admins, none)
public
string|null
$visibility
= null
$apiClient
protected
static HttpClientInterface
$apiClient
= null
$course
protected
static Course|null
$course
= 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()
Create a new Tab instance
public
__construct([array<string, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string, mixed> = []
-
Tab data from Canvas API
all()
Get all pages of results
public
static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Return values
array<string|int, static>checkCourse()
Check if course context is set
public
static checkCourse() : bool
Tags
Return values
boolfind()
Find a single tab by ID
public
static find(int $id[, array<string|int, mixed> $params = [] ]) : static
Note: Canvas API doesn't support finding individual tabs by ID. This method throws an exception as it's not supported.
Parameters
- $id : int
-
Tab ID
- $params : array<string|int, mixed> = []
-
Optional query parameters
Tags
Return values
staticget()
Get first page of results
public
static get([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Return values
array<string|int, static>getHidden()
Get hidden status
public
getHidden() : bool|null
Return values
bool|nullgetHtmlUrl()
Get HTML URL
public
getHtmlUrl() : string|null
Return values
string|nullgetId()
Get ID
public
getId() : string|null
Return values
string|nullgetLabel()
Get label
public
getLabel() : string|null
Return values
string|nullgetPosition()
Get position
public
getPosition() : int|null
Return values
int|nullgetType()
Get type
public
getType() : string|null
Return values
string|nullgetVisibility()
Get visibility
public
getVisibility() : string|null
Return values
string|nullpaginate()
Get paginated results with metadata
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters
Return values
PaginationResultsave()
Save the current tab (update only)
public
save() : self
Tags
Return values
selfsetApiClient()
Set the API client
public
static setApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
setCourse()
Set the course context for tab operations
public
static setCourse(Course $course) : void
Parameters
- $course : Course
-
The course to operate on
setHidden()
Set hidden status
public
setHidden(bool|null $hidden) : void
Parameters
- $hidden : bool|null
setHtmlUrl()
Set HTML URL
public
setHtmlUrl(string|null $htmlUrl) : void
Parameters
- $htmlUrl : string|null
setId()
Set ID
public
setId(string|null $id) : void
Parameters
- $id : string|null
setLabel()
Set label
public
setLabel(string|null $label) : void
Parameters
- $label : string|null
setPosition()
Set position
public
setPosition(int|null $position) : void
Parameters
- $position : int|null
setType()
Set type
public
setType(string|null $type) : void
Parameters
- $type : string|null
setVisibility()
Set visibility
public
setVisibility(string|null $visibility) : void
Parameters
- $visibility : string|null
toArray()
Convert tab to array
public
toArray() : array<string, mixed>
Return values
array<string, mixed>toDtoArray()
Convert tab to DTO array format
public
toDtoArray() : array<string, mixed>
Return values
array<string, mixed>update()
Update a tab
public
static update(string $id, array<string, mixed>|UpdateTabDTO $data) : self
Parameters
- $id : string
-
Tab ID
- $data : array<string, mixed>|UpdateTabDTO
-
Tab data
Tags
Return values
self —Updated Tab 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
PaginationResultgetEndpoint()
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
PaginatedResponsepopulate()
Populate the object with new data
protected
populate(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>