item_dto extends abstract_dto implements item_dto_interface
Data Transfer Object (DTO) for items.
A unified input model for creating and updating items. It is intentionally mutable to support form hydration and stepwise population.
Rules:
- When creating: id = null
- When updating: id != null
- Any field set to null will not override existing entity values (Partial Update)
- Only metadata keys provided here will be merged/updated
Table of Contents
Interfaces
- item_dto_interface
- Public-facing DTO Contract for creating/updating Items.
Properties
- $contextid : int|null
- $courseid : int|null
- $description : string|null
- $descriptionformat : int|null
- $fullname : string|null
- $guid : string|null
- $id : int|null
- $idnumber : string|null
- $metadata : array<string, mixed>
- $parent : int|null
- $shortname : string|null
- $sortorder : int|null
- $status : string|null
- $type : string|null
- $userid : int|null
- $usermodified : int|null
- $version : string|null
- $visible : int|null
Methods
- __construct() : mixed
- DTO constructor.
- from_array() : self
- Create a DTO from an associative array (e.g. form data or JSON).
- to_array() : array<string, mixed>
- Convert DTO to an array, filtering out null values.
Properties
$contextid
public
int|null
$contextid
= null
$courseid
public
int|null
$courseid
= null
$description
public
string|null
$description
= null
$descriptionformat
public
int|null
$descriptionformat
= 0
$fullname
public
string|null
$fullname
= null
$guid
public
string|null
$guid
= null
$id
public
int|null
$id
= null
$idnumber
public
string|null
$idnumber
= null
$metadata
public
array<string, mixed>
$metadata
= []
$parent
public
int|null
$parent
= null
$shortname
public
string|null
$shortname
= null
$sortorder
public
int|null
$sortorder
= 0
$status
public
string|null
$status
= 'draft'
$type
public
string|null
$type
= item::TYPE
$userid
public
int|null
$userid
= null
$usermodified
public
int|null
$usermodified
= null
$version
public
string|null
$version
= null
$visible
public
int|null
$visible
= 1
Methods
__construct()
DTO constructor.
public
__construct([null|int $id = null ][, null|string $type = item_interface::TYPE ][, null|int $contextid = null ][, null|int $courseid = null ][, null|int $userid = null ][, null|int $parent = null ][, null|string $fullname = null ][, null|string $shortname = null ][, null|string $idnumber = null ][, null|string $description = null ][, null|int $descriptionformat = 0 ][, null|string $status = 'draft' ][, null|int $visible = 1 ][, null|string $guid = null ][, null|int $sortorder = 0 ][, null|string $version = null ][, null|int $usermodified = null ][, array<string, mixed> $metadata = [] ]) : mixed
All fields are nullable to support partial updates (PATCH-like behavior).
Parameters
- $id : null|int = null
-
Item ID (null for creation)
- $type : null|string = item_interface::TYPE
-
Logical TYPE identifier
- $contextid : null|int = null
-
Moodle context ID
- $courseid : null|int = null
-
Course ID
- $userid : null|int = null
-
Entity owner (creator)
- $parent : null|int = null
-
Parent item ID
- $fullname : null|string = null
-
Full name/title
- $shortname : null|string = null
-
Short/abbreviated label
- $idnumber : null|string = null
-
External reference
- $description : null|string = null
-
Long description (HTML/text)
- $descriptionformat : null|int = 0
-
Moodle text format
- $status : null|string = 'draft'
-
Logical workflow/status
- $visible : null|int = 1
-
Visibility flag (0/1)
- $guid : null|string = null
-
External unique identifier
- $sortorder : null|int = 0
-
Ordering index
- $version : null|string = null
-
Arbitrary version tag
- $usermodified : null|int = null
-
User performing the operation
- $metadata : array<string, mixed> = []
-
Arbitrary key/value metadata
from_array()
Create a DTO from an associative array (e.g. form data or JSON).
public
static from_array(array<string, mixed> $data) : self
Keys not present in the array will remain null (not updated). Unknown keys are ignored.
Parameters
- $data : array<string, mixed>
Return values
selfto_array()
Convert DTO to an array, filtering out null values.
public
to_array() : array<string, mixed>
Useful for repository methods that should receive only changed fields.