class coursegroup_item extends item

Domain model for Course Group items.

This class maps entity-specific fields (expiration, contextids) to underlying metadata stored in middag_itemmeta.

Traits

Trait has_metadata.

Trait has_relations.

Trait has_status.

Trait has_url.

Constants

TYPE

Logical TYPE this entity represents

FILEMANAGER_OPTIONS

File upload options for image_filemanager

protected METADATA_FIELDS

Metadata keys supported by this entity

private META_EXPIRATION

Metadata keys specific to this Domain

private META_CONTEXTIDS

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

mixed
__get(string $name)

Property-style access: $item->parent.

bool
__isset(string $name)

Check presence of a relation.

void
__set(string $name, mixed $value)

Magic setter.

array
jsonSerialize()

Serializes the object to a value that can be natively serialized by json_encode().

mixed
__call(string $method, array $arguments)

Magic call handler for metadata getters and withers.

mixed
get_meta(string $key, mixed $default = null)

Retrieve a metadata value by key.

bool
has_meta(string $key)

Check if a metadata key exists.

array
get_all_meta()

Get all metadata.

with_meta(string $key, mixed $value)

Return a new instance with the updated metadata (Immutable).

with_all_meta(array $metadata)

Return a new instance replacing all metadata.

void
set_relation(string $name, mixed $value)

Set a relation value.

mixed
get_relation(string $name)

Public accessor for relations using snake_case.

bool
has_relation(string $name)

Returns TRUE if the relation was defined (even if value is null).

array
get_all_relations()

Get all currently loaded relations.

bool
is_status(item_status|string $value)

Check if the current status matches a specific value or Enum case.

bool
is_draft()

Determine if the item is in draft state.

bool
is_published()

Determine if the item is published.

bool
is_archived()

Determine if the item is archived.

bool
is_deleted()

Determine if the item is marked as deleted.

bool
is_active()

Check if the item is active.

bool
is_inactive()

Check if the item is inactive.

bool
is_enabled()

Check if the item is enabled.

bool
is_disabled()

Check if the item is disabled.

bool
is_pending()

Check if the item awaits processing.

bool
is_approved()

Check if the item is approved.

bool
is_rejected()

Check if the item was rejected.

bool
is_not_started()

Check if the item has not started.

bool
is_in_progress()

Check if the item is in progress.

bool
is_completed()

Check if the item is completed.

bool
is_failed()

Check if the item has failed.

bool
is_expired()

Check if the item is expired.

bool
is_canceled()

Check if the item is canceled.

bool
is_paused()

Check if the item is paused.

bool
is_queued()

Check if the item is queued.

bool
is_running()

Check if the item is running.

bool
is_syncing()

Check if the item is syncing.

bool
is_synced()

Check if the item finished syncing.

bool
is_error()

Check if the item is in an error state.

moodle_url
get_url(string $action = 'view', array $params = [])

Get the URL for a specific action on this entity.

from  has_url
moodle_url
get_view_url()

Shortcut for the view URL.

from  has_url
moodle_url
get_edit_url()

Shortcut for the edit URL.

from  has_url
moodle_url
get_webhook_url(string $action, array $params = [])

Generate a webhook URL specific to this entity.

from  has_url
__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).

from  item
static array
metadata_schema()

Define the metadata schema for this item type.

from  item
int|null
get_id()

Get the item database identifier.

from  item
string
get_type()

Get the logical type identifier.

from  item
int|null
get_contextid()

Get the Moodle context ID.

from  item
with_contextid(int|null $contextid)

Create a new instance with the provided context ID.

from  item
int|null
get_courseid()

Get the related course ID.

from  item
with_courseid(int|null $courseid)

Create a new instance with the provided course ID.

from  item
int|null
get_userid()

Get the author/owner user ID.

from  item
with_userid(int|null $userid)

Create a new instance with the provided user ID.

from  item
int|null
get_parent()

Get the parent item ID when hierarchical.

from  item
with_parent(int|null $parent)

Create a new instance with the provided parent ID.

from  item
string|null
get_fullname()

Get the full display name.

from  item
with_fullname(string $fullname)

Create a new instance with the provided full name.

from  item
string|null
get_shortname()

Get the abbreviated name.

from  item
with_shortname(string|null $shortname)

Create a new instance with the provided short name.

from  item
string|null
get_idnumber()

Get the external idnumber.

from  item
with_idnumber(string|null $idnumber)

Create a new instance with the provided idnumber.

from  item
string|null
get_description()

Get the description text.

from  item
with_description(string|null $description)

Create a new instance with the provided description.

from  item
int
get_descriptionformat()

Get the Moodle format constant for the description.

from  item
with_descriptionformat(int $descriptionformat)

Create a new instance with the provided description format.

from  item
string
get_status()

Get the current status identifier.

from  item
with_status(string $status)

Create a new instance with the provided status.

from  item
int
get_visible()

Get the raw visibility flag.

from  item
bool
is_visible()

Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.

from  item
with_visible(int $visible)

Create a new instance with the provided visibility flag.

from  item
string|null
get_guid()

Get the GUID reference if present.

from  item
int
get_sortorder()

Get the ordering value.

from  item
with_sortorder(int $sortorder)

Create a new instance with the provided sort order.

from  item
string|null
get_version()

Get the semantic version string if tracked.

from  item
with_version(string|null $version)

Create a new instance with the provided version.

from  item
int
get_timecreated()

Get creation timestamp.

from  item
int
get_timemodified()

Get last modification timestamp.

from  item
with_timemodified(int $time)

Create a new instance with the provided modification time.

from  item
int|null
get_usermodified()

Get the user ID of the last modifier.

from  item
with_usermodified(int $userid)

Create a new instance with the provided last modifier.

from  item
array
to_array()

Convert entity to array.

from  item
int|null
get_expiration()

Get expiration timestamp (int).

with_expiration(int|null $value)

Returns a clone with expiration updated.

array
get_context_ids()

Returns an array of context IDs (all integers).

with_context_ids(array $contextids)

Returns a clone with updated context IDs.

Details

in has_relations at line 40
mixed __get(string $name)

Property-style access: $item->parent.

Convenience wrapper for get_relation().

Parameters

string $name

Return Value

mixed

in has_relations at line 52
bool __isset(string $name)

Check presence of a relation.

Parameters

string $name

Return Value

bool

in abstract_entity at line 66
void __set(string $name, mixed $value)

Magic setter.

Parameters

string $name

Property name

mixed $value Value

Return Value

void

in abstract_entity at line 80
array jsonSerialize()

Serializes the object to a value that can be natively serialized by json_encode().

Return Value

array

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).

Parameters

string $method
array $arguments

Return Value

mixed

in has_metadata at line 79
mixed get_meta(string $key, mixed $default = null)

Retrieve a metadata value by key.

Parameters

string $key
mixed $default

Return Value

mixed

in has_metadata at line 95
bool has_meta(string $key)

Check if a metadata key exists.

Parameters

string $key

Return Value

bool

in has_metadata at line 109
array get_all_meta()

Get all metadata.

Return Value

array

in has_metadata at line 124
has_metadata with_meta(string $key, mixed $value)

Return a new instance with the updated metadata (Immutable).

Parameters

string $key
mixed $value

Return Value

has_metadata

in has_metadata at line 144
has_metadata with_all_meta(array $metadata)

Return a new instance replacing all metadata.

Parameters

array $metadata

Return Value

has_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.

Parameters

string $name
mixed $value

Return Value

void

in has_relations at line 84
mixed get_relation(string $name)

Public accessor for relations using snake_case.

Parameters

string $name

Return Value

mixed

in has_relations at line 96
bool has_relation(string $name)

Returns TRUE if the relation was defined (even if value is null).

Parameters

string $name

Return Value

bool

in has_relations at line 106
array get_all_relations()

Get all currently loaded relations.

Return Value

array

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.

Parameters

item_status|string $value

Return Value

bool

in has_status at line 61
bool is_draft()

Determine if the item is in draft state.

Return Value

bool

in has_status at line 69
bool is_published()

Determine if the item is published.

Return Value

bool

in has_status at line 77
bool is_archived()

Determine if the item is archived.

Return Value

bool

in has_status at line 85
bool is_deleted()

Determine if the item is marked as deleted.

Return Value

bool

in has_status at line 97
bool is_active()

Check if the item is active.

Return Value

bool

in has_status at line 105
bool is_inactive()

Check if the item is inactive.

Return Value

bool

in has_status at line 113
bool is_enabled()

Check if the item is enabled.

Return Value

bool

in has_status at line 121
bool is_disabled()

Check if the item is disabled.

Return Value

bool

in has_status at line 133
bool is_pending()

Check if the item awaits processing.

Return Value

bool

in has_status at line 141
bool is_approved()

Check if the item is approved.

Return Value

bool

in has_status at line 149
bool is_rejected()

Check if the item was rejected.

Return Value

bool

in has_status at line 161
bool is_not_started()

Check if the item has not started.

Return Value

bool

in has_status at line 169
bool is_in_progress()

Check if the item is in progress.

Return Value

bool

in has_status at line 177
bool is_completed()

Check if the item is completed.

Return Value

bool

in has_status at line 185
bool is_failed()

Check if the item has failed.

Return Value

bool

in has_status at line 193
bool is_expired()

Check if the item is expired.

Return Value

bool

in has_status at line 201
bool is_canceled()

Check if the item is canceled.

Return Value

bool

in has_status at line 209
bool is_paused()

Check if the item is paused.

Return Value

bool

in has_status at line 221
bool is_queued()

Check if the item is queued.

Return Value

bool

in has_status at line 229
bool is_running()

Check if the item is running.

Return Value

bool

in has_status at line 237
bool is_syncing()

Check if the item is syncing.

Return Value

bool

in has_status at line 245
bool is_synced()

Check if the item finished syncing.

Return Value

bool

in has_status at line 257
bool is_error()

Check if the item is in an error state.

Return Value

bool

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])

Parameters

string $action

the action suffix (view, edit, delete) or full route name

array $params

additional parameters

Return Value

moodle_url

in has_url at line 71
moodle_url get_view_url()

Shortcut for the view URL.

Return Value

moodle_url

in has_url at line 79
moodle_url get_edit_url()

Shortcut for the edit URL.

Return Value

moodle_url

in has_url at line 92
moodle_url get_webhook_url(string $action, array $params = [])

Generate a webhook URL specific to this entity.

Parameters

string $action
array $params

Return Value

moodle_url

in item 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).

Parameters

int|null $id
string $type
int|null $contextid
int|null $courseid
int|null $userid
int|null $parent
string|null $fullname
string|null $shortname
string|null $idnumber
string|null $description
int $descriptionformat
string $status
int $visible
string|null $guid
int $sortorder
string|null $version
int $timecreated
int $timemodified
int|null $usermodified
array $metadata

Initial metadata

in item 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.

Return Value

array

Map of key => Type/Rule

in item at line 113
int|null get_id()

Get the item database identifier.

Return Value

int|null

in item at line 121
string get_type()

Get the logical type identifier.

Return Value

string

in item at line 129
int|null get_contextid()

Get the Moodle context ID.

Return Value

int|null

in item at line 141
item with_contextid(int|null $contextid)

Create a new instance with the provided context ID.

Parameters

int|null $contextid

Context identifier

Return Value

item

in item at line 152
int|null get_courseid()

Get the related course ID.

Return Value

int|null

in item at line 164
item with_courseid(int|null $courseid)

Create a new instance with the provided course ID.

Parameters

int|null $courseid

Course identifier

Return Value

item

in item at line 175
int|null get_userid()

Get the author/owner user ID.

Return Value

int|null

in item at line 187
item with_userid(int|null $userid)

Create a new instance with the provided user ID.

Parameters

int|null $userid

User identifier

Return Value

item

in item at line 198
int|null get_parent()

Get the parent item ID when hierarchical.

Return Value

int|null

in item at line 210
item with_parent(int|null $parent)

Create a new instance with the provided parent ID.

Parameters

int|null $parent

Parent item identifier

Return Value

item

in item at line 221
string|null get_fullname()

Get the full display name.

Return Value

string|null

in item at line 233
item with_fullname(string $fullname)

Create a new instance with the provided full name.

Parameters

string $fullname

Full display name

Return Value

item

in item at line 244
string|null get_shortname()

Get the abbreviated name.

Return Value

string|null

in item at line 256
item with_shortname(string|null $shortname)

Create a new instance with the provided short name.

Parameters

string|null $shortname

Short display name

Return Value

item

in item at line 267
string|null get_idnumber()

Get the external idnumber.

Return Value

string|null

in item at line 279
item with_idnumber(string|null $idnumber)

Create a new instance with the provided idnumber.

Parameters

string|null $idnumber

External identifier

Return Value

item

in item at line 290
string|null get_description()

Get the description text.

Return Value

string|null

in item at line 302
item with_description(string|null $description)

Create a new instance with the provided description.

Parameters

string|null $description

Description text

Return Value

item

in item at line 313
int get_descriptionformat()

Get the Moodle format constant for the description.

Return Value

int

in item at line 325
item with_descriptionformat(int $descriptionformat)

Create a new instance with the provided description format.

Parameters

int $descriptionformat

Moodle format constant

Return Value

item

in item at line 336
string get_status()

Get the current status identifier.

Return Value

string

in item at line 348
item with_status(string $status)

Create a new instance with the provided status.

Parameters

string $status

Status identifier

Return Value

item

in item at line 359
int get_visible()

Get the raw visibility flag.

Return Value

int

in item at line 368
bool is_visible()

Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.

Return Value

bool

in item at line 380
item with_visible(int $visible)

Create a new instance with the provided visibility flag.

Parameters

int $visible

Visibility flag (0/1)

Return Value

item

in item at line 391
string|null get_guid()

Get the GUID reference if present.

Return Value

string|null

in item at line 401
int get_sortorder()

Get the ordering value.

Return Value

int

in item at line 413
item with_sortorder(int $sortorder)

Create a new instance with the provided sort order.

Parameters

int $sortorder

Ordering value

Return Value

item

in item at line 424
string|null get_version()

Get the semantic version string if tracked.

Return Value

string|null

in item at line 436
item with_version(string|null $version)

Create a new instance with the provided version.

Parameters

string|null $version

Semantic version string

Return Value

item

in item at line 447
int get_timecreated()

Get creation timestamp.

Return Value

int

in item at line 457
int get_timemodified()

Get last modification timestamp.

Return Value

int

in item at line 469
item with_timemodified(int $time)

Create a new instance with the provided modification time.

Parameters

int $time

Unix timestamp

Return Value

item

in item at line 480
int|null get_usermodified()

Get the user ID of the last modifier.

Return Value

int|null

in item at line 492
item with_usermodified(int $userid)

Create a new instance with the provided last modifier.

Parameters

int $userid

User identifier

Return Value

item

in item at line 506
array to_array()

Convert entity to array.

Useful for DTO conversion or serialization.

Return Value

array

at line 55
int|null get_expiration()

Get expiration timestamp (int).

Return Value

int|null

Returns expiration timestamp (int|null)

at line 65
coursegroup_item with_expiration(int|null $value)

Returns a clone with expiration updated.

Parameters

int|null $value

Return Value

coursegroup_item

at line 78
array get_context_ids()

Returns an array of context IDs (all integers).

Get context IDs as an array.

Always returns an array; empty array if none defined.

Return Value

array

at line 101
coursegroup_item with_context_ids(array $contextids)

Returns a clone with updated context IDs.

Parameters

array $contextids

Return Value

coursegroup_item