mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
Introduce filament
This commit is contained in:
@@ -26,9 +26,9 @@ class ExamResource extends JsonResource
|
||||
'duration' => $this->duration ?: '',
|
||||
'duration_text' => $this->duration_text,
|
||||
'filters' => $this->normalizeFilters($this->resource),
|
||||
'filters_formatted' => $this->formatFilters($this->resource),
|
||||
'filters_formatted' => $this->filterFormatted,
|
||||
'indexes' => $this->indexes,
|
||||
'indexes_formatted' => $this->formatIndexes($this->resource),
|
||||
'indexes_formatted' => $this->indexFormatted,
|
||||
'status' => $this->status,
|
||||
'status_text' => $this->statusText,
|
||||
'is_discovered' => $this->is_discovered,
|
||||
@@ -48,50 +48,4 @@ class ExamResource extends JsonResource
|
||||
return $filters;
|
||||
}
|
||||
|
||||
private function formatFilters(Exam $exam)
|
||||
{
|
||||
$currentFilters = $exam->filters;
|
||||
$arr = [];
|
||||
$filter = Exam::FILTER_USER_CLASS;
|
||||
if (!empty($currentFilters->{$filter})) {
|
||||
$classes = collect(User::$classes)->only($currentFilters->{$filter});
|
||||
$arr[] = sprintf('%s: %s', Exam::$filters[$filter]['name'], $classes->pluck('text')->implode(', '));
|
||||
}
|
||||
|
||||
$filter = Exam::FILTER_USER_REGISTER_TIME_RANGE;
|
||||
if (!empty($currentFilters->{$filter})) {
|
||||
$range = $currentFilters->{$filter};
|
||||
$arr[] = sprintf(
|
||||
"%s: \n%s ~ %s",
|
||||
Exam::$filters[$filter]['name'],
|
||||
$range[0] ? Carbon::parse($range[0])->toDateTimeString() : '-',
|
||||
$range[1] ? Carbon::parse($range[1])->toDateTimeString() : '-'
|
||||
);
|
||||
}
|
||||
|
||||
$filter = Exam::FILTER_USER_DONATE;
|
||||
if (!empty($currentFilters->{$filter})) {
|
||||
$donateStatus = $classes = collect(User::$donateStatus)->only($currentFilters->{$filter});
|
||||
$arr[] = sprintf('%s: %s', Exam::$filters[$filter]['name'], $donateStatus->pluck('text')->implode(', '));
|
||||
}
|
||||
|
||||
return implode("\n", $arr);
|
||||
}
|
||||
|
||||
private function formatIndexes(Exam $exam)
|
||||
{
|
||||
$indexes = $exam->indexes;
|
||||
$arr = [];
|
||||
foreach ($indexes as $index) {
|
||||
if (isset($index['checked']) && $index['checked']) {
|
||||
$arr[] = sprintf(
|
||||
'%s: %s %s',
|
||||
Exam::$indexes[$index['index']]['name'] ?? '',
|
||||
$index['require_value'],
|
||||
Exam::$indexes[$index['index']]['unit'] ?? ''
|
||||
);
|
||||
}
|
||||
}
|
||||
return implode("\n", $arr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user