Files
nexusphp/app/Http/Resources/ExamResource.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2021-04-19 20:13:21 +08:00
<?php
namespace App\Http\Resources;
2021-04-23 20:05:39 +08:00
use App\Models\Exam;
use App\Models\User;
use Carbon\Carbon;
2021-04-19 20:13:21 +08:00
use Illuminate\Http\Resources\Json\JsonResource;
class ExamResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'begin' => $this->begin,
'end' => $this->end,
2021-05-08 16:25:55 +08:00
'duration' => $this->duration ?: '',
2021-05-06 01:49:05 +08:00
'duration_text' => $this->duration_text,
2021-06-12 23:21:40 +08:00
'filters' => $this->normalizeFilters($this->resource),
2022-06-27 01:39:01 +08:00
'filters_formatted' => $this->filterFormatted,
2021-04-23 20:05:39 +08:00
'indexes' => $this->indexes,
2022-06-27 01:39:01 +08:00
'indexes_formatted' => $this->indexFormatted,
2021-04-19 20:13:21 +08:00
'status' => $this->status,
2021-04-23 20:05:39 +08:00
'status_text' => $this->statusText,
2021-05-02 17:24:05 +08:00
'is_discovered' => $this->is_discovered,
'is_discovered_text' => $this->is_discovered_text,
'priority' => $this->priority,
2021-04-19 20:13:21 +08:00
];
}
2021-04-23 20:05:39 +08:00
2021-06-12 23:21:40 +08:00
private function normalizeFilters(Exam $exam)
{
$filters = $exam->filters;
foreach (Exam::$filters as $key => $value) {
if (!isset($filters->$key)) {
$filters->$key = [];
}
}
return $filters;
}
2021-04-19 20:13:21 +08:00
}