item extends item
Public SDK Item Entity.
Use this class to type items returned by framework services or to extend the central Item behavior with your extension-specific rules.
Tags
Table of Contents
Constants
- TYPE = 'generic'
- Default type for generic items (extensions override this).
Properties
- $metadata : array<string, mixed>
- $__relations : array<string, mixed>
Methods
- __call() : mixed
- Magic call handler for metadata getters and withers.
- __construct() : mixed
- Item constructor (immutable).
- __get() : mixed
- Property-style access: $item->parent.
- __isset() : bool
- Check presence of a relation.
- __set() : void
- Magic setter.
- get_all_meta() : array<string, mixed>
- Get all metadata.
- get_all_relations() : array<string, mixed>
- Get all currently loaded relations.
- get_contextid() : int|null
- Get the Moodle context ID.
- get_courseid() : int|null
- Get the related course ID.
- get_description() : string|null
- Get the description text.
- get_descriptionformat() : int
- Get the Moodle format constant for the description.
- get_edit_url() : moodle_url
- Shortcut for the edit URL.
- get_fullname() : string|null
- Get the full display name.
- get_guid() : string|null
- Get the GUID reference if present.
- get_id() : null|int
- Get the item database identifier.
- get_idnumber() : string|null
- Get the external idnumber.
- get_meta() : mixed
- Retrieve a metadata value by key.
- get_parent() : int|null
- Get the parent item ID when hierarchical.
- get_relation() : mixed
- Public accessor for relations using snake_case.
- get_shortname() : string|null
- Get the abbreviated name.
- get_sortorder() : int
- Get the ordering value.
- get_status() : string
- Get the current status identifier.
- get_timecreated() : int
- Get creation timestamp.
- get_timemodified() : int
- Get last modification timestamp.
- get_type() : string
- Get the logical type identifier.
- get_url() : moodle_url
- Get the URL for a specific action on this entity.
- get_userid() : int|null
- Get the author/owner user ID.
- get_usermodified() : int|null
- Get the user ID of the last modifier.
- get_version() : string|null
- Get the semantic version string if tracked.
- get_view_url() : moodle_url
- Shortcut for the view URL.
- get_visible() : int
- Get the raw visibility flag.
- get_webhook_url() : moodle_url
- Generate a webhook URL specific to this entity.
- has_meta() : bool
- Check if a metadata key exists.
- has_relation() : bool
- Returns TRUE if the relation was defined (even if value is null).
- is_active() : bool
- Check if the item is active.
- is_approved() : bool
- Check if the item is approved.
- is_archived() : bool
- Determine if the item is archived.
- is_canceled() : bool
- Check if the item is canceled.
- is_completed() : bool
- Check if the item is completed.
- is_deleted() : bool
- Determine if the item is marked as deleted.
- is_disabled() : bool
- Check if the item is disabled.
- is_draft() : bool
- Determine if the item is in draft state.
- is_enabled() : bool
- Check if the item is enabled.
- is_error() : bool
- Check if the item is in an error state.
- is_expired() : bool
- Check if the item is expired.
- is_failed() : bool
- Check if the item has failed.
- is_in_progress() : bool
- Check if the item is in progress.
- is_inactive() : bool
- Check if the item is inactive.
- is_not_started() : bool
- Check if the item has not started.
- is_paused() : bool
- Check if the item is paused.
- is_pending() : bool
- Check if the item awaits processing.
- is_published() : bool
- Determine if the item is published.
- is_queued() : bool
- Check if the item is queued.
- is_rejected() : bool
- Check if the item was rejected.
- is_running() : bool
- Check if the item is running.
- is_status() : bool
- Check if the current status matches a specific value or Enum case.
- is_synced() : bool
- Check if the item finished syncing.
- is_syncing() : bool
- Check if the item is syncing.
- is_visible() : bool
- Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
- jsonSerialize() : array<string, mixed>
- Serializes the object to a value that can be natively serialized by json_encode().
- metadata_schema() : array<string, string>
- Define the metadata schema for this item type.
- to_array() : array<string, mixed>
- Convert entity to array.
- with_all_meta() : static
- Return a new instance replacing all metadata.
- with_contextid() : self
- Create a new instance with the provided context ID.
- with_courseid() : self
- Create a new instance with the provided course ID.
- with_description() : self
- Create a new instance with the provided description.
- with_descriptionformat() : self
- Create a new instance with the provided description format.
- with_fullname() : self
- Create a new instance with the provided full name.
- with_idnumber() : self
- Create a new instance with the provided idnumber.
- with_meta() : static
- Return a new instance with the updated metadata (Immutable).
- with_parent() : self
- Create a new instance with the provided parent ID.
- with_shortname() : self
- Create a new instance with the provided short name.
- with_sortorder() : self
- Create a new instance with the provided sort order.
- with_status() : self
- Create a new instance with the provided status.
- with_timemodified() : self
- Create a new instance with the provided modification time.
- with_userid() : self
- Create a new instance with the provided user ID.
- with_usermodified() : self
- Create a new instance with the provided last modifier.
- with_version() : self
- Create a new instance with the provided version.
- with_visible() : self
- Create a new instance with the provided visibility flag.
Constants
TYPE
Default type for generic items (extensions override this).
public
mixed
TYPE
= 'generic'
Properties
$metadata
protected
array<string, mixed>
$metadata
= []
key/value
$__relations
private
array<string, mixed>
$__relations
= []
Internal storage for loaded relations
Methods
__call()
Magic call handler for metadata getters and withers.
public
__call(string $method, array<int, mixed> $arguments) : mixed
Allows accessing metadata like $item->get_price() or $item->with_price(10).
Parameters
- $method : string
- $arguments : array<int, mixed>
__construct()
Item constructor (immutable).
public
__construct([null|int $id = null ][, string $type = self::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 ][, int $descriptionformat = 0 ][, string $status = 'draft' ][, int $visible = 1 ][, null|string $guid = null ][, int $sortorder = 0 ][, null|string $version = null ][, int $timecreated = 0 ][, int $timemodified = 0 ][, null|int $usermodified = null ][, array<string, mixed> $metadata = [] ]) : mixed
Parameters
- $id : null|int = null
- $type : string = self::TYPE
- $contextid : null|int = null
- $courseid : null|int = null
- $userid : null|int = null
- $parent : null|int = null
- $fullname : null|string = null
- $shortname : null|string = null
- $idnumber : null|string = null
- $description : null|string = null
- $descriptionformat : int = 0
- $status : string = 'draft'
- $visible : int = 1
- $guid : null|string = null
- $sortorder : int = 0
- $version : null|string = null
- $timecreated : int = 0
- $timemodified : int = 0
- $usermodified : null|int = null
- $metadata : array<string, mixed> = []
-
Initial metadata
__get()
Property-style access: $item->parent.
public
__get(string $name) : mixed
Convenience wrapper for get_relation().
Parameters
- $name : string
__isset()
Check presence of a relation.
public
__isset(string $name) : bool
Parameters
- $name : string
Return values
bool__set()
Magic setter.
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
-
Property name
- $value : mixed
-
Value
get_all_meta()
Get all metadata.
public
get_all_meta() : array<string, mixed>
Return values
array<string, mixed>get_all_relations()
Get all currently loaded relations.
public
get_all_relations() : array<string, mixed>
Return values
array<string, mixed>get_contextid()
Get the Moodle context ID.
public
get_contextid() : int|null
Return values
int|nullget_courseid()
Get the related course ID.
public
get_courseid() : int|null
Return values
int|nullget_description()
Get the description text.
public
get_description() : string|null
Return values
string|nullget_descriptionformat()
Get the Moodle format constant for the description.
public
get_descriptionformat() : int
Return values
intget_edit_url()
Shortcut for the edit URL.
public
get_edit_url() : moodle_url
Return values
moodle_urlget_fullname()
Get the full display name.
public
get_fullname() : string|null
Return values
string|nullget_guid()
Get the GUID reference if present.
public
get_guid() : string|null
Return values
string|nullget_id()
Get the item database identifier.
public
get_id() : null|int
Return values
null|intget_idnumber()
Get the external idnumber.
public
get_idnumber() : string|null
Return values
string|nullget_meta()
Retrieve a metadata value by key.
public
get_meta(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
- $default : mixed = null
get_parent()
Get the parent item ID when hierarchical.
public
get_parent() : int|null
Return values
int|nullget_relation()
Public accessor for relations using snake_case.
public
get_relation(string $name) : mixed
Parameters
- $name : string
get_shortname()
Get the abbreviated name.
public
get_shortname() : string|null
Return values
string|nullget_sortorder()
Get the ordering value.
public
get_sortorder() : int
Return values
intget_status()
Get the current status identifier.
public
get_status() : string
Return values
stringget_timecreated()
Get creation timestamp.
public
get_timecreated() : int
Return values
intget_timemodified()
Get last modification timestamp.
public
get_timemodified() : int
Return values
intget_type()
Get the logical type identifier.
public
get_type() : string
Return values
stringget_url()
Get the URL for a specific action on this entity.
public
get_url([string $action = 'view' ][, array<string, mixed> $params = [] ]) : moodle_url
Convention: Route name is "middag.{type}.{action}" Example: $item->get_url('edit') -> route('middag.generic.edit', ['id' => 123])
Parameters
- $action : string = 'view'
-
the action suffix (view, edit, delete) or full route name
- $params : array<string, mixed> = []
-
additional parameters
Return values
moodle_urlget_userid()
Get the author/owner user ID.
public
get_userid() : int|null
Return values
int|nullget_usermodified()
Get the user ID of the last modifier.
public
get_usermodified() : int|null
Return values
int|nullget_version()
Get the semantic version string if tracked.
public
get_version() : string|null
Return values
string|nullget_view_url()
Shortcut for the view URL.
public
get_view_url() : moodle_url
Return values
moodle_urlget_visible()
Get the raw visibility flag.
public
get_visible() : int
Return values
intget_webhook_url()
Generate a webhook URL specific to this entity.
public
get_webhook_url(string $action[, array<string, mixed> $params = [] ]) : moodle_url
Parameters
- $action : string
- $params : array<string, mixed> = []
Return values
moodle_urlhas_meta()
Check if a metadata key exists.
public
has_meta(string $key) : bool
Parameters
- $key : string
Return values
boolhas_relation()
Returns TRUE if the relation was defined (even if value is null).
public
has_relation(string $name) : bool
Parameters
- $name : string
Return values
boolis_active()
Check if the item is active.
public
is_active() : bool
Return values
boolis_approved()
Check if the item is approved.
public
is_approved() : bool
Return values
boolis_archived()
Determine if the item is archived.
public
is_archived() : bool
Return values
boolis_canceled()
Check if the item is canceled.
public
is_canceled() : bool
Return values
boolis_completed()
Check if the item is completed.
public
is_completed() : bool
Return values
boolis_deleted()
Determine if the item is marked as deleted.
public
is_deleted() : bool
Return values
boolis_disabled()
Check if the item is disabled.
public
is_disabled() : bool
Return values
boolis_draft()
Determine if the item is in draft state.
public
is_draft() : bool
Return values
boolis_enabled()
Check if the item is enabled.
public
is_enabled() : bool
Return values
boolis_error()
Check if the item is in an error state.
public
is_error() : bool
Return values
boolis_expired()
Check if the item is expired.
public
is_expired() : bool
Return values
boolis_failed()
Check if the item has failed.
public
is_failed() : bool
Return values
boolis_in_progress()
Check if the item is in progress.
public
is_in_progress() : bool
Return values
boolis_inactive()
Check if the item is inactive.
public
is_inactive() : bool
Return values
boolis_not_started()
Check if the item has not started.
public
is_not_started() : bool
Return values
boolis_paused()
Check if the item is paused.
public
is_paused() : bool
Return values
boolis_pending()
Check if the item awaits processing.
public
is_pending() : bool
Return values
boolis_published()
Determine if the item is published.
public
is_published() : bool
Return values
boolis_queued()
Check if the item is queued.
public
is_queued() : bool
Return values
boolis_rejected()
Check if the item was rejected.
public
is_rejected() : bool
Return values
boolis_running()
Check if the item is running.
public
is_running() : bool
Return values
boolis_status()
Check if the current status matches a specific value or Enum case.
public
is_status(item_status|string $value) : bool
Parameters
- $value : item_status|string
Return values
boolis_synced()
Check if the item finished syncing.
public
is_synced() : bool
Return values
boolis_syncing()
Check if the item is syncing.
public
is_syncing() : bool
Return values
boolis_visible()
Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
public
is_visible() : bool
Return values
booljsonSerialize()
Serializes the object to a value that can be natively serialized by json_encode().
public
jsonSerialize() : array<string, mixed>
Tags
Return values
array<string, mixed>metadata_schema()
Define the metadata schema for this item type.
public
static metadata_schema() : array<string, string>
Override this in subclasses to define typed metadata fields or validation rules.
Return values
array<string, string> —Map of key => Type/Rule
to_array()
Convert entity to array.
public
to_array() : array<string, mixed>
Useful for DTO conversion or serialization.
Return values
array<string, mixed>with_all_meta()
Return a new instance replacing all metadata.
public
with_all_meta(array<string, mixed> $metadata) : static
Parameters
- $metadata : array<string, mixed>
Return values
staticwith_contextid()
Create a new instance with the provided context ID.
public
with_contextid(null|int $contextid) : self
Parameters
- $contextid : null|int
-
Context identifier
Return values
selfwith_courseid()
Create a new instance with the provided course ID.
public
with_courseid(null|int $courseid) : self
Parameters
- $courseid : null|int
-
Course identifier
Return values
selfwith_description()
Create a new instance with the provided description.
public
with_description(null|string $description) : self
Parameters
- $description : null|string
-
Description text
Return values
selfwith_descriptionformat()
Create a new instance with the provided description format.
public
with_descriptionformat(int $descriptionformat) : self
Parameters
- $descriptionformat : int
-
Moodle format constant
Return values
selfwith_fullname()
Create a new instance with the provided full name.
public
with_fullname(string $fullname) : self
Parameters
- $fullname : string
-
Full display name
Return values
selfwith_idnumber()
Create a new instance with the provided idnumber.
public
with_idnumber(null|string $idnumber) : self
Parameters
- $idnumber : null|string
-
External identifier
Return values
selfwith_meta()
Return a new instance with the updated metadata (Immutable).
public
with_meta(string $key, mixed $value) : static
Parameters
- $key : string
- $value : mixed
Return values
staticwith_parent()
Create a new instance with the provided parent ID.
public
with_parent(null|int $parent) : self
Parameters
- $parent : null|int
-
Parent item identifier
Return values
selfwith_shortname()
Create a new instance with the provided short name.
public
with_shortname(null|string $shortname) : self
Parameters
- $shortname : null|string
-
Short display name
Return values
selfwith_sortorder()
Create a new instance with the provided sort order.
public
with_sortorder(int $sortorder) : self
Parameters
- $sortorder : int
-
Ordering value
Return values
selfwith_status()
Create a new instance with the provided status.
public
with_status(string $status) : self
Parameters
- $status : string
-
Status identifier
Return values
selfwith_timemodified()
Create a new instance with the provided modification time.
public
with_timemodified(int $time) : self
Parameters
- $time : int
-
Unix timestamp
Return values
selfwith_userid()
Create a new instance with the provided user ID.
public
with_userid(null|int $userid) : self
Parameters
- $userid : null|int
-
User identifier
Return values
selfwith_usermodified()
Create a new instance with the provided last modifier.
public
with_usermodified(int $userid) : self
Parameters
- $userid : int
-
User identifier
Return values
selfwith_version()
Create a new instance with the provided version.
public
with_version(null|string $version) : self
Parameters
- $version : null|string
-
Semantic version string
Return values
selfwith_visible()
Create a new instance with the provided visibility flag.
public
with_visible(int $visible) : self
Parameters
- $visible : int
-
Visibility flag (0/1)