51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class RubrikResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$syaratsDb = $this->syarats->pluck('nama');
|
|
$syarats = [];
|
|
foreach ($syaratsDb as $syarat) {
|
|
if (in_array(ucwords($syarat), ['Melalui Proses Review', 'Terdaftar Di Sim Lppm'])) {
|
|
continue;
|
|
}
|
|
|
|
if ($this->id === 660 && ucwords($syarat) === 'Laporan Kegiatan') {
|
|
continue;
|
|
}
|
|
|
|
$key = str_replace(' ', '_', $syarat);
|
|
if (defined("App\Enums\Syarats::$key")) {
|
|
$syarats[] = constant("App\Enums\Syarats::$key");
|
|
} else {
|
|
$syarats[] = ucwords($syarat);
|
|
}
|
|
}
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'periode' => $this->periode_id,
|
|
'kategori' => [
|
|
'id' => $this->kategori->id,
|
|
'nama' => $this->kategori->nama,
|
|
],
|
|
'uraian' => $this->uraian,
|
|
'satuan' => $this->satuan->nama,
|
|
'keterangan' => $this->keterangan ?? '-',
|
|
'pelaksana' => RubrikDetailResource::collection($this->details),
|
|
'syarats' => $syarats,
|
|
];
|
|
}
|
|
}
|