add projet

This commit is contained in:
root
2026-03-05 12:29:37 -05:00
parent 8d1eef8ba8
commit 23b7db1107
9109 changed files with 1106501 additions and 73 deletions
@@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers\Api\Admin;
use App\Models\ClassProgressAttachment;
trait HandlesProgressAttachments
{
protected function resolveAttachmentFile(array $row): ?string
{
$path = trim((string) ($row['attachment_path'] ?? ''));
if ($path === '') {
return null;
}
return $this->resolveAttachmentPath($path);
}
protected function resolveAttachmentPath(string $path): ?string
{
// CI stored paths may look like: writable/uploads/...
$relative = preg_replace('#^writable/uploads/#', '', $path);
// Laravel equivalent target
$absolute = storage_path('app/uploads/' . ltrim((string) $relative, '/'));
return is_file($absolute) ? $absolute : null;
}
/**
* Returns map: [report_id => [ ['id'=>.., 'name'=>..], ... ]]
*/
protected function loadAttachmentsForReports(array $reportIds): array
{
$reportIds = array_values(array_filter(array_map('intval', $reportIds)));
if (empty($reportIds)) {
return [];
}
$rows = ClassProgressAttachment::query()
->whereIn('report_id', $reportIds)
->orderBy('id', 'asc')
->get();
$map = [];
foreach ($rows as $row) {
$reportId = (int) ($row->report_id ?? 0);
if ($reportId === 0) {
continue;
}
$map[$reportId][] = [
'id' => (int) $row->id,
'name' => $row->original_name ?: basename((string) $row->file_path),
];
}
return $map;
}
protected function decodeFlags(?string $json): array
{
if (! $json) {
return [];
}
$flags = json_decode($json, true);
return is_array($flags) ? $flags : [];
}
}