Admin
extends AbstractBaseApi
in package
Admin Class
Represents an admin user in the Canvas LMS. Admins are users with specific permissions to manage accounts and their resources. This class provides methods to create, manage, and remove admin privileges for users at the account level.
Admin operations always require an account context, as admins are assigned permissions within specific accounts in the Canvas hierarchy.
Usage:
// Creating a new admin for an account
$adminData = [
'userId' => 123,
'role' => 'AccountAdmin',
'sendConfirmation' => true
];
$admin = Admin::create($adminData, 1); // Account ID 1
// Finding all admins for an account
$admins = Admin::get(['account_id' => 1]);
// Get all admins from all pages
$allAdmins = Admin::all(['account_id' => 1]);
// Removing admin privileges
$admin = Admin::find(123, ['account_id' => 1]); // User ID 123, Account ID 1
$admin->delete();
// Getting available admin roles
$roles = Admin::getSelfAdminRoles(1);
Table of Contents
Properties
- $accountId : int|null
- The account ID this admin is associated with
- $email : string|null
- The admin's email address
- $id : int|null
- The ID of the User object who is the admin
- $loginId : string|null
- The admin's login ID
- $name : string|null
- The admin's user name
- $role : string|null
- The role of the admin (e.g., 'AccountAdmin', 'SubAccountAdmin')
- $roleId : int|null
- The ID of the role
- $user : array<string, mixed>|null
- Additional user details (optional, based on include parameters)
- $workflowState : string|null
- The workflow state of the admin
- $apiClient : HttpClientInterface
- $methodAliases : array<string|int, mixed>
- Define method aliases
Methods
- __callStatic() : mixed
- Magic method to handle function aliases
- __construct() : mixed
- BaseApi constructor.
- all() : array<int, self>
- Get all admins from all pages
- create() : self
- Create a new admin for an account
- delete() : self
- Remove admin privileges (delete admin)
- find() : self
- Find an admin by user ID in a specific account Note: This implementation differs from the interface as it requires account context
- get() : array<int, self>
- Get first page of admins
- getAccount() : Account|null
- Get the account this admin belongs to
- getAccountId() : int|null
- Get account ID
- getEmail() : string|null
- Get admin email
- getId() : int|null
- Get admin user ID
- getName() : string|null
- Get admin name
- getRole() : string|null
- Get admin role
- getRoleId() : int|null
- Get admin role ID
- getSelfAdminRoles() : array<int, array<string, mixed>>
- Get a list of roles that can be assigned to users in the current account
- paginate() : PaginationResult
- Get paginated admins
- setAccountId() : self
- Set account ID
- setApiClient() : void
- Set the API client
- setEmail() : self
- Set admin email
- setId() : self
- Set admin user ID
- setName() : self
- Set admin name
- setRole() : self
- Set admin role
- setRoleId() : self
- Set admin role 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
- 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
$accountId
The account ID this admin is associated with
public
int|null
$accountId
= null
The admin's email address
public
string|null
$email
= null
$id
The ID of the User object who is the admin
public
int|null
$id
= null
$loginId
The admin's login ID
public
string|null
$loginId
= null
$name
The admin's user name
public
string|null
$name
= null
$role
The role of the admin (e.g., 'AccountAdmin', 'SubAccountAdmin')
public
string|null
$role
= null
$roleId
The ID of the role
public
int|null
$roleId
= null
$user
Additional user details (optional, based on include parameters)
public
array<string, mixed>|null
$user
= null
$workflowState
The workflow state of the admin
public
string|null
$workflowState
= null
$apiClient
protected
static HttpClientInterface
$apiClient
= 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()
BaseApi constructor.
public
__construct(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
all()
Get all admins from all pages
public
static all([array<string, mixed> $params = [] ]) : array<int, self>
Parameters
- $params : array<string, mixed> = []
-
Query parameters (can include 'account_id')
Tags
Return values
array<int, self>create()
Create a new admin for an account
public
static create(array<string, mixed>|CreateAdminDTO $data[, int|null $accountId = null ]) : self
Parameters
- $data : array<string, mixed>|CreateAdminDTO
-
Admin data
- $accountId : int|null = null
-
Account ID (required)
Tags
Return values
selfdelete()
Remove admin privileges (delete admin)
public
delete() : self
Tags
Return values
selffind()
Find an admin by user ID in a specific account Note: This implementation differs from the interface as it requires account context
public
static find(int $userId[, array<string, mixed> $params = [] ]) : self
Parameters
- $userId : int
-
User ID of the admin
- $params : array<string, mixed> = []
-
Optional parameters including account_id
Tags
Return values
selfget()
Get first page of admins
public
static get([array<string, mixed> $params = [] ]) : array<int, self>
Parameters
- $params : array<string, mixed> = []
-
Query parameters (can include 'account_id')
Tags
Return values
array<int, self>getAccount()
Get the account this admin belongs to
public
getAccount() : Account|null
Tags
Return values
Account|nullgetAccountId()
Get account ID
public
getAccountId() : int|null
Return values
int|nullgetEmail()
Get admin email
public
getEmail() : string|null
Return values
string|nullgetId()
Get admin user ID
public
getId() : int|null
Return values
int|nullgetName()
Get admin name
public
getName() : string|null
Return values
string|nullgetRole()
Get admin role
public
getRole() : string|null
Return values
string|nullgetRoleId()
Get admin role ID
public
getRoleId() : int|null
Return values
int|nullgetSelfAdminRoles()
Get a list of roles that can be assigned to users in the current account
public
static getSelfAdminRoles([int|null $accountId = null ]) : array<int, array<string, mixed>>
Parameters
- $accountId : int|null = null
-
Account ID
Tags
Return values
array<int, array<string, mixed>>paginate()
Get paginated admins
public
static paginate([array<string, mixed> $params = [] ]) : PaginationResult
Parameters
- $params : array<string, mixed> = []
-
Query parameters (can include 'account_id')
Tags
Return values
PaginationResultsetAccountId()
Set account ID
public
setAccountId(int $accountId) : self
Parameters
- $accountId : int
Return values
selfsetApiClient()
Set the API client
public
static setApiClient(HttpClientInterface $apiClient) : void
Parameters
- $apiClient : HttpClientInterface
setEmail()
Set admin email
public
setEmail(string $email) : self
Parameters
- $email : string
Return values
selfsetId()
Set admin user ID
public
setId(int $id) : self
Parameters
- $id : int
Return values
selfsetName()
Set admin name
public
setName(string $name) : self
Parameters
- $name : string
Return values
selfsetRole()
Set admin role
public
setRole(string $role) : self
Parameters
- $role : string
Return values
selfsetRoleId()
Set admin role ID
public
setRoleId(int $roleId) : self
Parameters
- $roleId : int
Return values
selfcastValue()
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
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>
Tags
toDtoArray()
Convert the object to an array
protected
toDtoArray() : array<string|int, mixed>