2023-02-14 14:27:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Activity\Resources;
|
|
|
|
|
|
|
|
use App\Activity;
|
2023-02-23 22:43:13 +01:00
|
|
|
use App\Http\Views\ActivityFilterScope;
|
|
|
|
use App\Lib\HasMeta;
|
2023-03-07 01:35:39 +01:00
|
|
|
use App\Resources\SubactivityResource;
|
2023-02-23 22:43:13 +01:00
|
|
|
use App\Subactivity;
|
2023-02-14 14:27:11 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin Activity
|
|
|
|
*/
|
|
|
|
class ActivityResource extends JsonResource
|
|
|
|
{
|
2023-02-23 22:43:13 +01:00
|
|
|
use HasMeta;
|
|
|
|
|
2023-02-14 14:27:11 +01:00
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return array{id: int, name: string}
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => $this->name,
|
|
|
|
'id' => $this->id,
|
2023-02-25 17:19:17 +01:00
|
|
|
'subactivities' => $this->subactivities->pluck('id')->toArray(),
|
2023-03-04 12:09:25 +01:00
|
|
|
'is_filterable' => $this->is_filterable,
|
2023-02-25 17:19:17 +01:00
|
|
|
'links' => [
|
|
|
|
'edit' => route('activity.edit', ['activity' => $this->getModel()]),
|
|
|
|
'update' => route('activity.update', ['activity' => $this->getModel()]),
|
|
|
|
'destroy' => route('activity.destroy', ['activity' => $this->getModel()]),
|
2023-03-04 12:09:25 +01:00
|
|
|
],
|
2023-03-04 15:23:45 +01:00
|
|
|
'subactivity_model' => [
|
|
|
|
'activities' => [$this->id],
|
|
|
|
'is_age_group' => false,
|
|
|
|
'is_filterable' => false,
|
|
|
|
'name' => '',
|
|
|
|
],
|
2023-02-14 14:27:11 +01:00
|
|
|
];
|
|
|
|
}
|
2023-02-23 22:43:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
2023-03-07 01:35:39 +01:00
|
|
|
'subactivities' => SubactivityResource::collectionWithoutMeta(Subactivity::get()),
|
2023-02-23 22:43:13 +01:00
|
|
|
'filter' => ActivityFilterScope::fromRequest(request()->input('filter')),
|
2023-05-02 23:13:00 +02:00
|
|
|
'links' => [
|
|
|
|
'index' => route('activity.index'),
|
|
|
|
'create' => route('activity.create'),
|
2023-12-30 01:19:02 +01:00
|
|
|
'membership_masslist' => route('membership.masslist.index'),
|
2023-05-02 23:13:00 +02:00
|
|
|
],
|
2023-02-23 22:43:13 +01:00
|
|
|
];
|
|
|
|
}
|
2023-02-14 14:27:11 +01:00
|
|
|
}
|