MIDDAG for Moodle

item_repository_interface extends repository_interface

Marker interface for Repositories.

Table of Contents

Methods

create()  : T
Create a new item from a DTO.
delete()  : void
Delete an item and all related metadata.
find_by_id()  : null|T
Find an item by ID.
find_by_metadata()  : array<string|int, T>
Search items by metadata key/value pair.
find_by_type()  : array<string|int, T>
Find all items of a given TYPE.
get_metadata()  : array<string, mixed>
Get all metadata associated with an item.
save_metadata()  : void
Save (insert/update) metadata entries.
update()  : T
Update an existing item from a DTO.

Methods

delete()

Delete an item and all related metadata.

public delete(int $id) : void
Parameters
$id : int
Tags
throws
dml_exception|dml_transaction_exception

find_by_id()

Find an item by ID.

public find_by_id(int $id) : null|T
Parameters
$id : int
Tags
throws
coding_exception|dml_exception
Return values
null|T

find_by_metadata()

Search items by metadata key/value pair.

public find_by_metadata(string $key, string $value) : array<string|int, T>
Parameters
$key : string
$value : string
Tags
throws
coding_exception|dml_exception
Return values
array<string|int, T>

find_by_type()

Find all items of a given TYPE.

public find_by_type(string $type) : array<string|int, T>

Must use efficient metadata loading to avoid N+1.

Parameters
$type : string
Tags
throws
coding_exception|dml_exception
Return values
array<string|int, T>

get_metadata()

Get all metadata associated with an item.

public get_metadata(int $itemid) : array<string, mixed>
Parameters
$itemid : int
Tags
throws
dml_exception
Return values
array<string, mixed>

save_metadata()

Save (insert/update) metadata entries.

public save_metadata(int $itemid, array<string, mixed> $metadata) : void

Keys not provided must remain untouched.

Parameters
$itemid : int
$metadata : array<string, mixed>
Tags
throws
dml_exception|JsonException

update()

Update an existing item from a DTO.

public update(item_dto_interface $dto) : T

Must be atomic: Item + Metadata in a single transaction.

Parameters
$dto : item_dto_interface
Tags
throws
coding_exception|dml_exception|dml_transaction_exception|JsonException|moodle_exception
Return values
T

        
On this page

Search results