Documentation

Rubric extends AbstractBaseApi
in package

Rubric Class

Represents a rubric in Canvas LMS. Rubrics are assessment tools that define standardized grading criteria. They can exist at both the course and account levels and can be associated with assignments, discussions, and other assessable items.

Rubrics contain criteria with ratings that define performance levels and point values. They provide consistent grading standards and clear expectations for students.

Usage:

// Account context (default)
$rubrics = Rubric::get();
$rubric = Rubric::create([
    'title' => 'Account Rubric',
    'criteria' => [...]
]);

// Course context via Course instance
$course = Course::find(123);
$rubrics = $course->rubrics();

// Direct context access
$rubrics = Rubric::fetchByContext('course', 123);
$rubric = Rubric::createInContext('course', 123, [
    'title' => 'Course Rubric',
    'criteria' => [...]
]);

// Finding and updating rubrics
$rubric = Rubric::find(456); // Searches in account context
$rubric = Rubric::findByContext('course', 123, 456); // Course-specific

$rubric = Rubric::update(456, [
    'title' => 'Updated Rubric'
]);

// Using DTOs
$dto = new CreateRubricDTO();
$dto->title = "Essay Rubric";
$dto->criteria = [...];
$rubric = Rubric::create($dto);

Table of Contents

Properties

$assessments  : array<int, mixed>|null
Array of rubric assessments (when included)
$association  : RubricAssociation|null
Associated RubricAssociation from create/update responses
$associations  : array<int, mixed>|null
Array of rubric associations (when included)
$contextId  : int|null
The context owning the rubric (course_id)
$contextType  : string|null
The context type owning the rubric
$data  : array<int, RubricCriterion>|null
Array of rubric criteria
$freeFormCriterionComments  : bool|null
Whether free-form comments are used
$hideScoreTotal  : bool|null
Whether to hide the score total
$id  : int|null
The ID of the rubric
$pointsPossible  : float|null
Total points possible for the rubric
$readOnly  : bool|null
Whether the rubric is read-only
$reusable  : bool|null
Whether the rubric is reusable
$title  : string|null
Title of the rubric
$apiClient  : HttpClientInterface
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Constructor
all()  : array<string|int, static>
Get all pages of results
create()  : self
Create a new rubric in the default account context
createInContext()  : self
Create a new rubric in a specific context
delete()  : self
Delete a rubric
fetchByContext()  : array<string|int, self>
List rubrics for a specific context
fetchByContextPaginated()  : PaginatedResponse
Get paginated rubrics for a specific context
find()  : self
Find a rubric by ID in the default account context
findByContext()  : self
Find a rubric by ID in a specific context
get()  : array<string|int, static>
Get first page of results
getUploadStatus()  : array<string, mixed>
Get the status of a rubric import in account context
getUploadStatusInContext()  : array<string, mixed>
Get the status of a rubric import in a specific context
getUploadTemplate()  : string
Get CSV template for rubric import
getUsedLocations()  : array<string, mixed>
Get the courses and assignments where this rubric is used
paginate()  : PaginationResult
Get paginated results with metadata
save()  : self
Save the rubric (create or update)
setApiClient()  : void
Set the API client
update()  : self
Update a rubric in the default account context
updateInContext()  : self
Update a rubric in a specific context
uploadCsv()  : array<string, mixed>
Upload a rubric via CSV file to account context
uploadCsvToContext()  : array<string, mixed>
Upload a rubric via CSV file to a specific context
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
getResourceIdentifier()  : string
Get the resource identifier for API endpoints
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array

Properties

$assessments

Array of rubric assessments (when included)

public array<int, mixed>|null $assessments = null

$association

Associated RubricAssociation from create/update responses

public RubricAssociation|null $association = null

$associations

Array of rubric associations (when included)

public array<int, mixed>|null $associations = null

$contextId

The context owning the rubric (course_id)

public int|null $contextId = null

$contextType

The context type owning the rubric

public string|null $contextType = null

$freeFormCriterionComments

Whether free-form comments are used

public bool|null $freeFormCriterionComments = null

$hideScoreTotal

Whether to hide the score total

public bool|null $hideScoreTotal = null

$id

The ID of the rubric

public int|null $id = null

$pointsPossible

Total points possible for the rubric

public float|null $pointsPossible = null

$readOnly

Whether the rubric is read-only

public bool|null $readOnly = null

$reusable

Whether the rubric is reusable

public bool|null $reusable = null

$title

Title of the rubric

public string|null $title = 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()

Constructor

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

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>

createInContext()

Create a new rubric in a specific context

public static createInContext(string $contextType, int $contextId, array<string, mixed>|CreateRubricDTO $data) : self
Parameters
$contextType : string

Context type (accounts, courses)

$contextId : int

Context ID

$data : array<string, mixed>|CreateRubricDTO

The rubric data

Tags
throws
CanvasApiException
Return values
self

fetchByContext()

List rubrics for a specific context

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

'accounts' or 'courses'

$contextId : int

Account or Course ID

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

Query parameters

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

fetchByContextPaginated()

Get paginated rubrics for a specific context

public static fetchByContextPaginated(string $contextType, int $contextId[, array<string, mixed> $params = [] ]) : PaginatedResponse
Parameters
$contextType : string

'accounts' or 'courses'

$contextId : int

Account or Course ID

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

Query parameters

Tags
throws
CanvasApiException
Return values
PaginatedResponse

find()

Find a rubric by ID in the default account context

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

The rubric ID

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

Query parameters

Tags
throws
CanvasApiException
Return values
self

findByContext()

Find a rubric by ID in a specific context

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

Context type (accounts, courses)

$contextId : int

Context ID

$id : int

The rubric ID

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

Query parameters

Tags
throws
CanvasApiException
Return values
self

get()

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>

getUploadStatus()

Get the status of a rubric import in account context

public static getUploadStatus([int|null $importId = null ]) : array<string, mixed>
Parameters
$importId : int|null = null

The import ID (optional, returns latest if not provided)

Tags
throws
CanvasApiException
Return values
array<string, mixed>

getUploadStatusInContext()

Get the status of a rubric import in a specific context

public static getUploadStatusInContext(string $contextType, int $contextId[, int|null $importId = null ]) : array<string, mixed>
Parameters
$contextType : string

'accounts' or 'courses'

$contextId : int

Context ID

$importId : int|null = null

The import ID (optional, returns latest if not provided)

Tags
throws
CanvasApiException
Return values
array<string, mixed>

getUploadTemplate()

Get CSV template for rubric import

public static getUploadTemplate() : string
Tags
throws
CanvasApiException
Return values
string

CSV content

getUsedLocations()

Get the courses and assignments where this rubric is used

public getUsedLocations() : array<string, mixed>
Tags
throws
CanvasApiException
Return values
array<string, mixed>

update()

Update a rubric in the default account context

public static update(int $id, array<string, mixed>|UpdateRubricDTO $data) : self
Parameters
$id : int

The rubric ID

$data : array<string, mixed>|UpdateRubricDTO

The update data

Tags
throws
CanvasApiException
Return values
self

updateInContext()

Update a rubric in a specific context

public static updateInContext(string $contextType, int $contextId, int $id, array<string, mixed>|UpdateRubricDTO $data) : self
Parameters
$contextType : string

Context type (accounts, courses)

$contextId : int

Context ID

$id : int

The rubric ID

$data : array<string, mixed>|UpdateRubricDTO

The update data

Tags
throws
CanvasApiException
Return values
self

uploadCsv()

Upload a rubric via CSV file to account context

public static uploadCsv(string $filePath) : array<string, mixed>
Parameters
$filePath : string

Path to the CSV file

Tags
throws
CanvasApiException
Return values
array<string, mixed>

Import status information

uploadCsvToContext()

Upload a rubric via CSV file to a specific context

public static uploadCsvToContext(string $contextType, int $contextId, string $filePath) : array<string, mixed>
Parameters
$contextType : string

'accounts' or 'courses'

$contextId : int

Context ID

$filePath : string

Path to the CSV file

Tags
throws
CanvasApiException
Return values
array<string, mixed>

Import status information

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
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

getResourceIdentifier()

Get the resource identifier for API endpoints

protected static getResourceIdentifier() : string
Return values
string

populate()

Populate the object with new data

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

toDtoArray()

Convert the object to an array

protected toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results