CreateModuleItemDTO
extends AbstractBaseDto
in package
implements
DTOInterface
Create Module Item DTO
Data Transfer Object for creating Canvas module items. Handles all Canvas module item types with proper validation.
Canvas Module Item Types and Requirements:
- File: Requires content_id
- Page: Requires page_url
- Discussion: Requires content_id
- Assignment: Requires content_id
- Quiz: Requires content_id
- SubHeader: Text-only divider, no content_id required
- ExternalUrl: Requires external_url
- ExternalTool: Requires external_url, supports iframe config
Usage:
// Create assignment module item
$dto = new CreateModuleItemDTO([
'type' => 'Assignment',
'content_id' => 123,
'title' => 'Assignment 1',
'position' => 1
]);
// Create page module item
$dto = new CreateModuleItemDTO([
'type' => 'Page',
'page_url' => 'course-introduction',
'title' => 'Course Introduction'
]);
// Create external tool with iframe
$dto = new CreateModuleItemDTO([
'type' => 'ExternalTool',
'external_url' => 'https://example.com/tool',
'title' => 'Learning Tool',
'new_tab' => true,
'iframe' => ['width' => 800, 'height' => 600]
]);
Table of Contents
Interfaces
Properties
- $completionRequirement : array<string, mixed>|null
- Completion requirement configuration.
- $contentId : int|null
- ID of associated content object.
- $externalUrl : string|null
- External URL for ExternalUrl/ExternalTool types.
- $iframe : array<string, int>|null
- External tool iframe configuration.
- $indent : int|null
- 0-based hierarchy indent level (0-5 allowed).
- $newTab : bool|null
- Whether external tool opens in new tab.
- $pageUrl : string|null
- Wiki page URL slug.
- $position : int|null
- 1-based position in module (optional).
- $title : string|null
- Item title (optional).
- $type : string
- Content type (File, Page, Discussion, Assignment, Quiz, SubHeader, ExternalUrl, ExternalTool).
- $apiPropertyName : string
- Canvas API property name for module items
Methods
- __construct() : mixed
- BaseDto constructor.
- getCompletionRequirement() : array<string, mixed>|null
- getContentId() : int|null
- getExternalUrl() : string|null
- getIframe() : array<string, int>|null
- getIndent() : int|null
- getNewTab() : bool|null
- getPageUrl() : string|null
- getPosition() : int|null
- getTitle() : string|null
- getType() : string
- setCompletionRequirement() : void
- setContentId() : void
- setExternalUrl() : void
- setIframe() : void
- setIndent() : void
- setNewTab() : void
- setPageUrl() : void
- setPosition() : void
- setTitle() : void
- setType() : void
- toApiArray() : array<string|int, mixed>
- Convert the DTO to an array for API requests Handles nested arrays for iframe and completion_requirement
- toArray() : array<string|int, mixed>
- Convert the DTO to an array
Properties
$completionRequirement
Completion requirement configuration.
public
array<string, mixed>|null
$completionRequirement
= null
Structure: ['type' => 'must_view|must_contribute|must_submit|min_score|must_mark_done', 'min_score' => int]
$contentId
ID of associated content object.
public
int|null
$contentId
= null
Required for: File, Discussion, Assignment, Quiz Not required for: ExternalUrl, Page, SubHeader
$externalUrl
External URL for ExternalUrl/ExternalTool types.
public
string|null
$externalUrl
= null
Required for: ExternalUrl, ExternalTool
$iframe
External tool iframe configuration.
public
array<string, int>|null
$iframe
= null
ExternalTool only. Structure: ['width' => int, 'height' => int]
$indent
0-based hierarchy indent level (0-5 allowed).
public
int|null
$indent
= null
$newTab
Whether external tool opens in new tab.
public
bool|null
$newTab
= null
ExternalTool only.
$pageUrl
Wiki page URL slug.
public
string|null
$pageUrl
= null
Required for: Page type
$position
1-based position in module (optional).
public
int|null
$position
= null
$title
Item title (optional).
public
string|null
$title
= null
$type
Content type (File, Page, Discussion, Assignment, Quiz, SubHeader, ExternalUrl, ExternalTool).
public
string
$type
Required for all module item types.
$apiPropertyName
Canvas API property name for module items
protected
string
$apiPropertyName
= 'module_item'
Methods
__construct()
BaseDto constructor.
public
__construct(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
Tags
getCompletionRequirement()
public
getCompletionRequirement() : array<string, mixed>|null
Return values
array<string, mixed>|nullgetContentId()
public
getContentId() : int|null
Return values
int|nullgetExternalUrl()
public
getExternalUrl() : string|null
Return values
string|nullgetIframe()
public
getIframe() : array<string, int>|null
Return values
array<string, int>|nullgetIndent()
public
getIndent() : int|null
Return values
int|nullgetNewTab()
public
getNewTab() : bool|null
Return values
bool|nullgetPageUrl()
public
getPageUrl() : string|null
Return values
string|nullgetPosition()
public
getPosition() : int|null
Return values
int|nullgetTitle()
public
getTitle() : string|null
Return values
string|nullgetType()
public
getType() : string
Return values
stringsetCompletionRequirement()
public
setCompletionRequirement(array<string, mixed>|null $completionRequirement) : void
Parameters
- $completionRequirement : array<string, mixed>|null
setContentId()
public
setContentId(int|null $contentId) : void
Parameters
- $contentId : int|null
setExternalUrl()
public
setExternalUrl(string|null $externalUrl) : void
Parameters
- $externalUrl : string|null
Tags
setIframe()
public
setIframe(array<string, int>|null $iframe) : void
Parameters
- $iframe : array<string, int>|null
setIndent()
public
setIndent(int|null $indent) : void
Parameters
- $indent : int|null
setNewTab()
public
setNewTab(bool|null $newTab) : void
Parameters
- $newTab : bool|null
setPageUrl()
public
setPageUrl(string|null $pageUrl) : void
Parameters
- $pageUrl : string|null
setPosition()
public
setPosition(int|null $position) : void
Parameters
- $position : int|null
setTitle()
public
setTitle(string|null $title) : void
Parameters
- $title : string|null
setType()
public
setType(string $type) : void
Parameters
- $type : string
Tags
toApiArray()
Convert the DTO to an array for API requests Handles nested arrays for iframe and completion_requirement
public
toApiArray() : array<string|int, mixed>
Return values
array<string|int, mixed>toArray()
Convert the DTO to an array
public
toArray() : array<string|int, mixed>