Documentation

GroupMembership extends AbstractBaseApi
in package

Canvas LMS Group Memberships API

Group memberships are the objects that tie users and groups together. They handle the relationships between users and groups including invitations, acceptances, and membership states.

Tags
see
https://canvas.instructure.com/doc/api/groups.html#group-memberships

Table of Contents

Properties

$createdAt  : string|null
When the membership was created
$group  : Group|null
The group object (when include[]=group)
$groupId  : int|null
The ID of the group
$id  : int|null
The unique identifier for the membership
$justCreated  : bool|null
Just created membership flag
$moderator  : bool|null
Whether the user is a moderator of the group (observer, admin, etc)
$sisGroupId  : string|null
The SIS ID of the group
$sisImportId  : int|null
The SIS import ID
$updatedAt  : string|null
When the membership was last updated
$user  : User|null
The user object (when include[]=user)
$userId  : int|null
The ID of the user
$workflowState  : string|null
The workflow state of the membership Values: 'accepted', 'invited', 'requested'
$apiClient  : HttpClientInterface
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Constructor override to handle nested objects
accept()  : self
Accept this membership invitation
all()  : array<string|int, GroupMembership>
Get all pages of group memberships
create()  : self
Create a membership
delete()  : self
Delete this membership instance
deleteMembership()  : void
Delete a membership (leave group)
fetchAllForGroup()  : array<string|int, GroupMembership>
List group memberships for a specific group
find()  : self
Get a single group membership
findByUserId()  : self
Get membership by user ID
get()  : array<string|int, GroupMembership>
List group memberships (interface requirement)
getGroup()  : Group|null
getGroupId()  : int|null
getId()  : int|null
getJustCreated()  : bool|null
getModerator()  : bool|null
getUser()  : User|null
Get the user object for this membership
getUserId()  : int|null
getWorkflowState()  : string|null
leave()  : void
Leave a group (for current user)
makeModerator()  : self
Make this member a moderator
paginate()  : PaginationResult
Get paginated results with metadata
reject()  : self
Reject this membership invitation
removeModerator()  : self
Remove moderator status
setApiClient()  : void
Set the API client
setGroup()  : void
setGroupId()  : void
setId()  : void
setJustCreated()  : void
setModerator()  : void
setUser()  : void
setUserId()  : void
setWorkflowState()  : void
update()  : self
Update a membership
updateByUserId()  : self
Update a membership by user ID
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 Note: GroupMembership is a nested resource under Group
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data
toDtoArray()  : array<string|int, mixed>
Convert the object to an array

Properties

$createdAt

When the membership was created

public string|null $createdAt = null

$id

The unique identifier for the membership

public int|null $id = null

$justCreated

Just created membership flag

public bool|null $justCreated = null

$moderator

Whether the user is a moderator of the group (observer, admin, etc)

public bool|null $moderator = null

$sisGroupId

The SIS ID of the group

public string|null $sisGroupId = null

$updatedAt

When the membership was last updated

public string|null $updatedAt = null

$workflowState

The workflow state of the membership Values: 'accepted', 'invited', 'requested'

public string|null $workflowState = 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 override to handle nested objects

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

deleteMembership()

Delete a membership (leave group)

public static deleteMembership(int $groupId, int $membershipId) : void
Parameters
$groupId : int

Group ID

$membershipId : int

Membership ID

Tags
throws
CanvasApiException

fetchAllForGroup()

List group memberships for a specific group

public static fetchAllForGroup(int $groupId[, array<string, mixed> $params = [] ]) : array<string|int, GroupMembership>
Parameters
$groupId : int

Group ID

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

Query parameters

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

find()

Get a single group membership

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

Membership ID

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

Query parameters (must include 'group_id')

Tags
throws
CanvasApiException
Return values
self

findByUserId()

Get membership by user ID

public static findByUserId(int $groupId, int $userId) : self
Parameters
$groupId : int

Group ID

$userId : int

User ID

Tags
throws
CanvasApiException
Return values
self

getJustCreated()

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

getModerator()

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

getUser()

Get the user object for this membership

public getUser() : User|null

This method implements lazy-loading: if the user object is not already loaded but a userId is present, it will make an API call to fetch the user data. To avoid N+1 queries when processing multiple memberships, consider using Canvas API include parameters when fetching memberships.

Return values
User|null

The user object or null if no user is associated

getWorkflowState()

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

setGroupId()

public setGroupId(int|null $groupId) : void
Parameters
$groupId : int|null

setId()

public setId(int|null $id) : void
Parameters
$id : int|null

setJustCreated()

public setJustCreated(bool|null $justCreated) : void
Parameters
$justCreated : bool|null

setModerator()

public setModerator(bool|null $moderator) : void
Parameters
$moderator : bool|null

setUserId()

public setUserId(int|null $userId) : void
Parameters
$userId : int|null

setWorkflowState()

public setWorkflowState(string|null $workflowState) : void
Parameters
$workflowState : string|null

update()

Update a membership

public static update(int $groupId, int $membershipId, array<string, mixed> $data) : self
Parameters
$groupId : int

Group ID

$membershipId : int

Membership ID

$data : array<string, mixed>

Update data

Tags
throws
CanvasApiException
Return values
self

updateByUserId()

Update a membership by user ID

public static updateByUserId(int $groupId, int $userId, array<string, mixed> $data) : self
Parameters
$groupId : int

Group ID

$userId : int

User ID

$data : array<string, mixed>

Update data

Tags
throws
CanvasApiException
Return values
self

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 Note: GroupMembership is a nested resource under Group

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

toDtoArray()

Convert the object to an array

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

        
On this page

Search results