2023-12-31 22:35:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Resources;
|
|
|
|
|
2024-06-29 18:02:23 +02:00
|
|
|
use App\Form\Data\ExportData;
|
2024-02-16 14:18:16 +01:00
|
|
|
use App\Form\Enums\NamiType;
|
2024-03-15 00:39:17 +01:00
|
|
|
use App\Form\Enums\SpecialType;
|
2024-01-01 18:29:33 +01:00
|
|
|
use App\Form\Fields\Field;
|
2024-05-27 19:47:28 +02:00
|
|
|
use App\Form\FormSettings;
|
2024-03-08 02:19:07 +01:00
|
|
|
use App\Form\Scopes\FormFilterScope;
|
2023-12-31 22:35:13 +01:00
|
|
|
use App\Form\Models\Form;
|
2024-01-01 16:53:32 +01:00
|
|
|
use App\Form\Models\Formtemplate;
|
2024-01-01 18:29:33 +01:00
|
|
|
use App\Group;
|
2024-01-01 16:53:32 +01:00
|
|
|
use App\Lib\HasMeta;
|
2023-12-31 22:35:13 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin Form
|
|
|
|
*/
|
|
|
|
class FormResource extends JsonResource
|
|
|
|
{
|
2024-01-01 16:53:32 +01:00
|
|
|
|
|
|
|
use HasMeta;
|
|
|
|
|
2023-12-31 22:35:13 +01:00
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
2024-01-01 18:29:33 +01:00
|
|
|
'id' => $this->id,
|
2023-12-31 22:35:13 +01:00
|
|
|
'name' => $this->name,
|
2024-01-10 21:31:34 +01:00
|
|
|
'from_human' => $this->from->format('d.m.Y'),
|
|
|
|
'to_human' => $this->to->format('d.m.Y'),
|
|
|
|
'from' => $this->from->format('Y-m-d'),
|
|
|
|
'to' => $this->to->format('Y-m-d'),
|
2023-12-31 22:35:13 +01:00
|
|
|
'excerpt' => $this->excerpt,
|
|
|
|
'description' => $this->description,
|
|
|
|
'mail_top' => $this->mail_top,
|
|
|
|
'mail_bottom' => $this->mail_bottom,
|
|
|
|
'registration_from' => $this->registration_from?->format('Y-m-d H:i:s'),
|
|
|
|
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
|
2024-01-01 16:43:40 +01:00
|
|
|
'config' => $this->config,
|
2024-02-08 20:29:46 +01:00
|
|
|
'participants_count' => $this->participants_count,
|
2024-05-27 18:30:05 +02:00
|
|
|
'is_active' => $this->is_active,
|
2024-05-27 18:49:11 +02:00
|
|
|
'is_private' => $this->is_private,
|
2024-06-20 23:29:23 +02:00
|
|
|
'has_nami_field' => $this->getFields()->hasNamiField(),
|
2024-06-29 18:02:23 +02:00
|
|
|
'export' => $this->export,
|
2024-01-01 18:29:33 +01:00
|
|
|
'links' => [
|
2024-06-20 23:29:23 +02:00
|
|
|
'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]),
|
|
|
|
'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]),
|
2024-01-01 18:29:33 +01:00
|
|
|
'update' => route('form.update', ['form' => $this->getModel()]),
|
|
|
|
'destroy' => route('form.destroy', ['form' => $this->getModel()]),
|
2024-04-18 22:15:28 +02:00
|
|
|
'is_dirty' => route('form.is-dirty', ['form' => $this->getModel()]),
|
2024-05-27 21:08:09 +02:00
|
|
|
'frontend' => str(app(FormSettings::class)->registerUrl)->replace('{slug}', $this->slug),
|
|
|
|
'export' => route('form.export', ['form' => $this->getModel()]),
|
2024-01-01 18:29:33 +01:00
|
|
|
]
|
2023-12-31 22:35:13 +01:00
|
|
|
];
|
|
|
|
}
|
2024-01-01 16:53:32 +01:00
|
|
|
|
2024-01-10 21:31:34 +01:00
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
2024-01-01 16:53:32 +01:00
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-01-01 18:29:33 +01:00
|
|
|
'base_url' => url(''),
|
|
|
|
'groups' => Group::forSelect(),
|
|
|
|
'fields' => Field::asMeta(),
|
2024-03-08 02:19:07 +01:00
|
|
|
'filter' => FormFilterScope::fromRequest(request()->input('filter', '')),
|
2024-01-01 16:53:32 +01:00
|
|
|
'links' => [
|
|
|
|
'store' => route('form.store'),
|
2024-01-01 18:29:33 +01:00
|
|
|
'formtemplate_index' => route('formtemplate.index'),
|
2024-01-01 16:53:32 +01:00
|
|
|
],
|
|
|
|
'templates' => FormtemplateResource::collection(Formtemplate::get()),
|
2024-02-21 22:10:26 +01:00
|
|
|
'namiTypes' => NamiType::forSelect(),
|
2024-03-15 00:39:17 +01:00
|
|
|
'specialTypes' => SpecialType::forSelect(),
|
2024-01-01 18:29:33 +01:00
|
|
|
'default' => [
|
2024-02-02 01:05:45 +01:00
|
|
|
'description' => [],
|
2024-05-27 18:30:05 +02:00
|
|
|
'is_active' => true,
|
2024-05-27 18:49:11 +02:00
|
|
|
'is_private' => false,
|
2024-01-01 18:29:33 +01:00
|
|
|
'name' => '',
|
|
|
|
'excerpt' => '',
|
|
|
|
'from' => null,
|
|
|
|
'to' => null,
|
|
|
|
'registration_from' => null,
|
|
|
|
'registration_until' => null,
|
2024-04-19 17:42:59 +02:00
|
|
|
'mail_top' => [],
|
|
|
|
'mail_bottom' => [],
|
2024-01-01 18:29:33 +01:00
|
|
|
'config' => null,
|
2024-01-13 21:53:39 +01:00
|
|
|
'header_image' => null,
|
2024-04-14 00:26:17 +02:00
|
|
|
'mailattachments' => [],
|
2024-01-13 21:53:39 +01:00
|
|
|
'id' => null,
|
2024-06-29 18:02:23 +02:00
|
|
|
'export' => ExportData::from([]),
|
2024-01-01 18:29:33 +01:00
|
|
|
],
|
|
|
|
'section_default' => [
|
|
|
|
'name' => '',
|
|
|
|
'intro' => '',
|
|
|
|
'fields' => [],
|
|
|
|
]
|
2024-01-01 16:53:32 +01:00
|
|
|
];
|
|
|
|
}
|
2023-12-31 22:35:13 +01:00
|
|
|
}
|