Documentation

Outcome extends AbstractBaseApi
in package

Outcome API class for managing learning outcomes in Canvas LMS.

Outcomes allow instructors to track student mastery of specific learning objectives across assignments and courses. This class follows the Account-as-Default convention for multi-context resources.

Tags
see
https://canvas.instructure.com/doc/api/outcomes.html

Table of Contents

Properties

$alignments  : array<int, mixed>|null
$assessed  : bool|null
$calculationInt  : int|null
$calculationMethod  : string|null
$canEdit  : bool|null
$canUnlink  : bool|null
$contextId  : string|null
$contextType  : string|null
$description  : string|null
$displayName  : string|null
$friendlyDescription  : string|null
$hasUpdateableRubrics  : bool|null
$id  : int|null
$masteryPoints  : float|null
$pointsPossible  : float|null
$ratings  : array<int, mixed>|null
$title  : string|null
$url  : string|null
$vendorGuid  : string|null
$methodAliases  : array<string, array<string|int, string>>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
BaseApi constructor.
all()  : array<string|int, static>
Get all pages of results
canEdit()  : bool
Check if outcome can be edited.
canUnlink()  : bool
Check if outcome can be unlinked.
create()  : self
Create a new outcome (defaults to Account context).
createInContext()  : self
Create or link an outcome in a specific context and group.
deleteFromContext()  : bool
Delete/unlink an outcome from a specific context and group.
fetchByContext()  : array<int, static>
Fetch outcomes by specific context.
fetchByContextPaginated()  : PaginationResult
Fetch paginated outcomes by specific context.
find()  : static
Find a specific outcome by ID.
get()  : array<int, static>
Get first page of outcomes (defaults to Account context).
getAlignments()  : array<int, mixed>
Get alignments for this outcome.
getCalculationMethodDisplayName()  : string
Get the calculation method display name.
importFromVendor()  : self
Import an outcome from external vendor.
isAssessed()  : bool
Check if outcome has been assessed.
overrideApiClient()  : void
Set an API client for this class only, leaving other resources on the shared default.
paginate()  : PaginationResult
Get paginated outcomes (defaults to Account context).
resetApiClients()  : void
Clear the shared default client and all per-class overrides.
save()  : self
Save the current outcome (create or update).
setApiClient()  : void
Set the shared default API client used by ALL resource classes.
stream()  : Generator<int, static>
Stream all items across all pages one at a time.
update()  : self
Update an existing outcome.
validateRatings()  : bool
Validate rating scale.
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
getEndpoint()  : string
Get the 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
toDtoArray()  : array<string|int, mixed>
Convert the object to an array
validateContext()  : void
Validate a context type path segment against an allowlist.

Properties

$alignments

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

$assessed

public bool|null $assessed = null

$calculationInt

public int|null $calculationInt = null

$calculationMethod

public string|null $calculationMethod = null

$canEdit

public bool|null $canEdit = null
public bool|null $canUnlink = null

$contextId

public string|null $contextId = null

$contextType

public string|null $contextType = null

$description

public string|null $description = null

$displayName

public string|null $displayName = null

$friendlyDescription

public string|null $friendlyDescription = null

$hasUpdateableRubrics

public bool|null $hasUpdateableRubrics = null

$masteryPoints

public float|null $masteryPoints = null

$pointsPossible

public float|null $pointsPossible = null

$ratings

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

$title

public string|null $title = null

$vendorGuid

public string|null $vendorGuid = 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
throws
InvalidArgumentException

__construct()

BaseApi constructor.

public __construct(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, 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>

canEdit()

Check if outcome can be edited.

public canEdit() : bool
Return values
bool

Check if outcome can be unlinked.

public canUnlink() : bool
Return values
bool

createInContext()

Create or link an outcome in a specific context and group.

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

Context type (accounts, courses)

$contextId : int

Context ID

$groupId : int|null

Outcome group ID (null for global group)

$data : array<string, mixed>|CreateOutcomeDTO

Outcome data

Tags
throws
CanvasApiException
Return values
self

deleteFromContext()

Delete/unlink an outcome from a specific context and group.

public deleteFromContext(string $contextType, int $contextId[, int|null $groupId = null ]) : bool
Parameters
$contextType : string

Context type (accounts, courses)

$contextId : int

Context ID

$groupId : int|null = null

Outcome group ID (null for global group)

Tags
throws
CanvasApiException
Return values
bool

fetchByContext()

Fetch outcomes by specific context.

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

Context type (accounts, courses)

$contextId : int

Context ID

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
array<int, static>

Array of Outcome objects

fetchByContextPaginated()

Fetch paginated outcomes by specific context.

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

Context type (accounts, courses)

$contextId : int

Context ID

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
PaginationResult

find()

Find a specific outcome by ID.

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

Outcome ID

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
static

get()

Get first page of outcomes (defaults to Account context).

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
array<int, static>

Array of Outcome objects

getAlignments()

Get alignments for this outcome.

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

Context type (accounts, courses)

$contextId : int

Context ID

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

Optional query parameters

Tags
throws
CanvasApiException
Return values
array<int, mixed>

Array of alignments

getCalculationMethodDisplayName()

Get the calculation method display name.

public getCalculationMethodDisplayName() : string
Return values
string

importFromVendor()

Import an outcome from external vendor.

public static importFromVendor(string $contextType, int $contextId, string $vendorGuid[, int|null $groupId = null ]) : self
Parameters
$contextType : string

Context type (accounts, courses)

$contextId : int

Context ID

$vendorGuid : string

Vendor GUID

$groupId : int|null = null

Outcome group ID

Tags
throws
CanvasApiException
Return values
self

isAssessed()

Check if outcome has been assessed.

public isAssessed() : bool
Return values
bool

paginate()

Get paginated outcomes (defaults to Account context).

public static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
$params : array<string, mixed> = []

Optional query parameters

Tags
throws
CanvasApiException
Return values
PaginationResult

Paginated result with metadata

resetApiClients()

Clear the shared default client and all per-class overrides.

public static resetApiClients() : void

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

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
throws
CanvasApiException
Return values
Generator<int, static>

validateRatings()

Validate rating scale.

public validateRatings() : bool
Return values
bool

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>

getAliasMap()

Build a flat alias-to-method lookup from $methodAliases.

protected static getAliasMap() : array<string, string>
Return values
array<string, string>

getEndpoint()

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

hydrate()

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

toDtoArray()

Convert the object to an array

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

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

Tags
throws
CanvasApiException

If the context type is not allowed

On this page

Search results