coursegroup_item
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
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).
Create a new instance with the provided context ID.
Create a new instance with the provided short name.
Create a new instance with the provided idnumber.
Create a new instance with the provided description.
Create a new instance with the provided description format.
Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
Create a new instance with the provided modification time.
Create a new instance with the provided last modifier.
Get expiration timestamp (int).
Returns a clone with expiration updated.
Returns an array of context IDs (all integers).
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().
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.
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).
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.
in
item at line 113
int|null
get_id()
Get the item database identifier.
in
item at line 121
string
get_type()
Get the logical type identifier.
in
item at line 129
int|null
get_contextid()
Get the Moodle context ID.
in
item at line 141
item
with_contextid(int|null $contextid)
Create a new instance with the provided context ID.
in
item at line 152
int|null
get_courseid()
Get the related course ID.
in
item at line 164
item
with_courseid(int|null $courseid)
Create a new instance with the provided course ID.
in
item at line 175
int|null
get_userid()
Get the author/owner user ID.
in
item at line 187
item
with_userid(int|null $userid)
Create a new instance with the provided user ID.
in
item at line 198
int|null
get_parent()
Get the parent item ID when hierarchical.
in
item at line 210
item
with_parent(int|null $parent)
Create a new instance with the provided parent ID.
in
item at line 221
string|null
get_fullname()
Get the full display name.
in
item at line 233
item
with_fullname(string $fullname)
Create a new instance with the provided full name.
in
item at line 244
string|null
get_shortname()
Get the abbreviated name.
in
item at line 256
item
with_shortname(string|null $shortname)
Create a new instance with the provided short name.
in
item at line 267
string|null
get_idnumber()
Get the external idnumber.
in
item at line 279
item
with_idnumber(string|null $idnumber)
Create a new instance with the provided idnumber.
in
item at line 290
string|null
get_description()
Get the description text.
in
item at line 302
item
with_description(string|null $description)
Create a new instance with the provided description.
in
item at line 313
int
get_descriptionformat()
Get the Moodle format constant for the description.
in
item at line 325
item
with_descriptionformat(int $descriptionformat)
Create a new instance with the provided description format.
in
item at line 336
string
get_status()
Get the current status identifier.
in
item at line 348
item
with_status(string $status)
Create a new instance with the provided status.
in
item at line 359
int
get_visible()
Get the raw visibility flag.
in
item at line 368
bool
is_visible()
Domain logic: Is this item visible? Wraps the raw integer logic into a boolean.
in
item at line 380
item
with_visible(int $visible)
Create a new instance with the provided visibility flag.
in
item at line 391
string|null
get_guid()
Get the GUID reference if present.
in
item at line 401
int
get_sortorder()
Get the ordering value.
in
item at line 413
item
with_sortorder(int $sortorder)
Create a new instance with the provided sort order.
in
item at line 424
string|null
get_version()
Get the semantic version string if tracked.
in
item at line 436
item
with_version(string|null $version)
Create a new instance with the provided version.
in
item at line 447
int
get_timecreated()
Get creation timestamp.
in
item at line 457
int
get_timemodified()
Get last modification timestamp.
in
item at line 469
item
with_timemodified(int $time)
Create a new instance with the provided modification time.
in
item at line 480
int|null
get_usermodified()
Get the user ID of the last modifier.
in
item at line 492
item
with_usermodified(int $userid)
Create a new instance with the provided last modifier.
in
item at line 506
array
to_array()
Convert entity to array.
Useful for DTO conversion or serialization.
at line 55
int|null
get_expiration()
Get expiration timestamp (int).
at line 65
coursegroup_item
with_expiration(int|null $value)
Returns a clone with expiration updated.
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.
at line 101
coursegroup_item
with_context_ids(array $contextids)
Returns a clone with updated context IDs.