Files
lucent-laravel/src/Core/File/RecordFileModule.php
T

64 lines
2.1 KiB
PHP
Raw Normal View History

2026-01-13 17:51:19 +02:00
<?php namespace Lucent\Core\File;
use Lucent\Core\Data\RecordFile;
2026-01-13 18:20:01 +02:00
use Lucent\Core\Data\RecordFilePreview;
2026-01-13 17:51:19 +02:00
use Lucent\Core\Data\RecordMode;
2026-01-13 18:20:01 +02:00
use Lucent\Core\Data\File;
2026-01-13 17:51:19 +02:00
use stdClass;
class RecordFileModule
{
public static function toDb(RecordFile $file): array
{
return [
"id" => $file->id,
"record_id" => $file->recordId,
"file_id" => $file->fileId,
"field_id" => $file->fieldId,
"mode" => $file->mode,
"locale" => $file->locale,
"rank" => $file->rank,
];
}
public static function fromDb(stdClass $data): RecordFile
{
return new RecordFile(
id: data_get($data, "id"),
2026-01-13 18:20:01 +02:00
recordId: data_get($data, "record_id"),
2026-01-13 17:51:19 +02:00
fileId: data_get($data, "file_id"),
fieldId: data_get($data, "field_id"),
mode: RecordMode::from(data_get($data, "mode")),
locale: data_get($data, "locale"),
rank: data_get($data, "rank"),
);
}
2026-01-13 18:20:01 +02:00
public static function recordFilePreviewFromDb(
stdClass $data,
): RecordFilePreview {
return new RecordFilePreview(
new RecordFile(
id: data_get($data, "record_file_id"),
recordId: data_get($data, "record_id"),
fileId: data_get($data, "file_id"),
fieldId: data_get($data, "field_id"),
mode: RecordMode::from(data_get($data, "mode")),
locale: data_get($data, "locale"),
rank: data_get($data, "rank"),
),
new File(
id: data_get($data, "file_id"),
name: data_get($data, "name"),
size: data_get($data, "size"),
width: data_get($data, "width"),
height: data_get($data, "height"),
mime: data_get($data, "mime"),
checksum: data_get($data, "checksum"),
recordId: data_get($data, "recordId"),
isShared: data_get($data, "is_shared"),
),
);
}
2026-01-13 17:51:19 +02:00
}