item
class item extends abstract_entity implements item_interface
Domain entity: Item.
Represents an item stored in middag_items.
This is an immutable entity designed for DDD. Changes must be done via with_* methods
which return a new instance of the entity.
Traits
Trait has_metadata.
Trait has_relations.
Trait has_status.
Trait has_url.
Constants
| TYPE |
Default type for generic items (extensions override this). |
Properties
| array<string,mixed> | $metadata | Expected property on the consuming class. |
from has_metadata |
| string | $status | Expected property on the using class. |
from has_status |
Methods
Serializes the object to a value that can be natively serialized by json_encode().
Magic call handler for metadata getters and withers.
Retrieve a metadata value by key.
Return a new instance with the updated metadata (Immutable).
Return a new instance replacing all metadata.
Returns TRUE if the relation was defined (even if value is null).
Check if the current status matches a specific value or Enum case.
Get the URL for a specific action on this entity.
Generate a webhook URL specific to this entity.
Item constructor (immutable).
Define the metadata schema for this item type.
Get the item database identifier.
Get the logical type identifier.
Get the Moodle context ID.
Create a new instance with the provided context ID.
Get the related course ID.
Create a new instance with the provided course ID.
Get the author/owner user ID.
Create a new instance with the provided user ID.
Get the parent item ID when hierarchical.
Create a new instance with the provided parent ID.
Get the full display name.
Create a new instance with the provided full name.
Get the abbreviated name.
Create a new instance with the provided short name.
Get the external idnumber.
Create a new instance with the provided idnumber.
Get the description text.
Create a new instance with the provided description.
Get the Moodle format constant for the description.
Create a new instance with the provided description format.
Get the current status identifier.
Create a new instance with the provided status.
Get the raw visibility flag.
Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
Create a new instance with the provided visibility flag.
Get the GUID reference if present.
Get the ordering value.
Create a new instance with the provided sort order.
Get the semantic version string if tracked.
Create a new instance with the provided version.
Get creation timestamp.
Get last modification timestamp.
Create a new instance with the provided modification time.
Get the user ID of the last modifier.
Create a new instance with the provided last modifier.
Convert entity to array.
Details
in
has_relations at line 40
mixed
__get(string $name)
Property-style access: $item->parent.
Convenience wrapper for get_relation().
in
has_relations at line 52
bool
__isset(string $name)
Check presence of a relation.
in
abstract_entity at line 66
void
__set(string $name, mixed $value)
Magic setter.
in
abstract_entity at line 80
array
jsonSerialize()
Serializes the object to a value that can be natively serialized by json_encode().
in
has_metadata at line 46
mixed
__call(string $method, array $arguments)
Magic call handler for metadata getters and withers.
Allows accessing metadata like $item->get_price() or $item->with_price(10).
in
has_metadata at line 79
mixed
get_meta(string $key, mixed $default = null)
Retrieve a metadata value by key.
in
has_metadata at line 95
bool
has_meta(string $key)
Check if a metadata key exists.
in
has_metadata at line 109
array
get_all_meta()
Get all metadata.
in
has_metadata at line 124
has_metadata
with_meta(string $key, mixed $value)
Return a new instance with the updated metadata (Immutable).
in
has_metadata at line 144
has_metadata
with_all_meta(array $metadata)
Return a new instance replacing all metadata.
in
has_relations at line 72
void
set_relation(string $name, mixed $value)
| internal |
Set a relation value.
INTERNAL API used by loader and the query engine. Use Repository/Loader to set these during hydration.
Architecture Note: This mutates the internal state of the entity. In a strict immutable context, this might return a clone, but for hydration performance (lazy loading relations), direct mutation is acceptable here.
in
has_relations at line 84
mixed
get_relation(string $name)
Public accessor for relations using snake_case.
in
has_relations at line 96
bool
has_relation(string $name)
Returns TRUE if the relation was defined (even if value is null).
in
has_relations at line 106
array
get_all_relations()
Get all currently loaded relations.
in
has_status at line 39
bool
is_status(item_status|string $value)
Check if the current status matches a specific value or Enum case.
in
has_status at line 61
bool
is_draft()
Determine if the item is in draft state.
in
has_status at line 69
bool
is_published()
Determine if the item is published.
in
has_status at line 77
bool
is_archived()
Determine if the item is archived.
in
has_status at line 85
bool
is_deleted()
Determine if the item is marked as deleted.
in
has_status at line 97
bool
is_active()
Check if the item is active.
in
has_status at line 105
bool
is_inactive()
Check if the item is inactive.
in
has_status at line 113
bool
is_enabled()
Check if the item is enabled.
in
has_status at line 121
bool
is_disabled()
Check if the item is disabled.
in
has_status at line 133
bool
is_pending()
Check if the item awaits processing.
in
has_status at line 141
bool
is_approved()
Check if the item is approved.
in
has_status at line 149
bool
is_rejected()
Check if the item was rejected.
in
has_status at line 161
bool
is_not_started()
Check if the item has not started.
in
has_status at line 169
bool
is_in_progress()
Check if the item is in progress.
in
has_status at line 177
bool
is_completed()
Check if the item is completed.
in
has_status at line 185
bool
is_failed()
Check if the item has failed.
in
has_status at line 193
bool
is_expired()
Check if the item is expired.
in
has_status at line 201
bool
is_canceled()
Check if the item is canceled.
in
has_status at line 209
bool
is_paused()
Check if the item is paused.
in
has_status at line 221
bool
is_queued()
Check if the item is queued.
in
has_status at line 229
bool
is_running()
Check if the item is running.
in
has_status at line 237
bool
is_syncing()
Check if the item is syncing.
in
has_status at line 245
bool
is_synced()
Check if the item finished syncing.
in
has_status at line 257
bool
is_error()
Check if the item is in an error state.
in
has_url at line 46
moodle_url
get_url(string $action = 'view', array $params = [])
Get the URL for a specific action on this entity.
Convention: Route name is "middag.{type}.{action}" Example: $item->get_url('edit') -> route('middag.generic.edit', ['id' => 123])
in
has_url at line 71
moodle_url
get_view_url()
Shortcut for the view URL.
in
has_url at line 79
moodle_url
get_edit_url()
Shortcut for the edit URL.
in
has_url at line 92
moodle_url
get_webhook_url(string $action, array $params = [])
Generate a webhook URL specific to this entity.
at line 70
__construct(int|null $id = null, string $type = self::TYPE, int|null $contextid = null, int|null $courseid = null, int|null $userid = null, int|null $parent = null, string|null $fullname = null, string|null $shortname = null, string|null $idnumber = null, string|null $description = null, int $descriptionformat = 0, string $status = 'draft', int $visible = 1, string|null $guid = null, int $sortorder = 0, string|null $version = null, int $timecreated = 0, int $timemodified = 0, int|null $usermodified = null, array $metadata = [])
Item constructor (immutable).
at line 103
static array
metadata_schema()
Define the metadata schema for this item type.
Override this in subclasses to define typed metadata fields or validation rules.
at line 113
int|null
get_id()
Get the item database identifier.
at line 121
string
get_type()
Get the logical type identifier.
at line 129
int|null
get_contextid()
Get the Moodle context ID.
at line 141
item
with_contextid(int|null $contextid)
Create a new instance with the provided context ID.
at line 152
int|null
get_courseid()
Get the related course ID.
at line 164
item
with_courseid(int|null $courseid)
Create a new instance with the provided course ID.
at line 175
int|null
get_userid()
Get the author/owner user ID.
at line 187
item
with_userid(int|null $userid)
Create a new instance with the provided user ID.
at line 198
int|null
get_parent()
Get the parent item ID when hierarchical.
at line 210
item
with_parent(int|null $parent)
Create a new instance with the provided parent ID.
at line 221
string|null
get_fullname()
Get the full display name.
at line 233
item
with_fullname(string $fullname)
Create a new instance with the provided full name.
at line 244
string|null
get_shortname()
Get the abbreviated name.
at line 256
item
with_shortname(string|null $shortname)
Create a new instance with the provided short name.
at line 267
string|null
get_idnumber()
Get the external idnumber.
at line 279
item
with_idnumber(string|null $idnumber)
Create a new instance with the provided idnumber.
at line 290
string|null
get_description()
Get the description text.
at line 302
item
with_description(string|null $description)
Create a new instance with the provided description.
at line 313
int
get_descriptionformat()
Get the Moodle format constant for the description.
at line 325
item
with_descriptionformat(int $descriptionformat)
Create a new instance with the provided description format.
at line 336
string
get_status()
Get the current status identifier.
at line 348
item
with_status(string $status)
Create a new instance with the provided status.
at line 359
int
get_visible()
Get the raw visibility flag.
at line 368
bool
is_visible()
Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
at line 380
item
with_visible(int $visible)
Create a new instance with the provided visibility flag.
at line 391
string|null
get_guid()
Get the GUID reference if present.
at line 401
int
get_sortorder()
Get the ordering value.
at line 413
item
with_sortorder(int $sortorder)
Create a new instance with the provided sort order.
at line 424
string|null
get_version()
Get the semantic version string if tracked.
at line 436
item
with_version(string|null $version)
Create a new instance with the provided version.
at line 447
int
get_timecreated()
Get creation timestamp.
at line 457
int
get_timemodified()
Get last modification timestamp.
at line 469
item
with_timemodified(int $time)
Create a new instance with the provided modification time.
at line 480
int|null
get_usermodified()
Get the user ID of the last modifier.
at line 492
item
with_usermodified(int $userid)
Create a new instance with the provided last modifier.
at line 506
array
to_array()
Convert entity to array.
Useful for DTO conversion or serialization.