changes
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateCustomFormAction
|
||||
{
|
||||
public function run(array $data): CustomForm
|
||||
{
|
||||
$data['form_id'] = $data['form_id'] ?? Str::slug($data['title']) . time();
|
||||
$data['status'] = $data['status'] ?? 'published';
|
||||
$data['settings'] = $data['settings'] ?? [];
|
||||
$data['mail_settings'] = $data['mail_settings'] ?? [];
|
||||
$data['columns'] = $data['columns'] ?? [];
|
||||
|
||||
return CustomForm::create($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
|
||||
class DeleteCustomFormAction
|
||||
{
|
||||
public function run(CustomForm $form): bool
|
||||
{
|
||||
return $form->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomFormResponse;
|
||||
|
||||
class DeleteFormResponseAction
|
||||
{
|
||||
public function run(CustomFormResponse $response): bool
|
||||
{
|
||||
return $response->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
|
||||
class ListCustomFormsAction
|
||||
{
|
||||
public function run(array $filters = []): array
|
||||
{
|
||||
$query = CustomForm::query();
|
||||
|
||||
// Поиск по названию
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('title', 'like', '%' . $filters['search'] . '%');
|
||||
}
|
||||
|
||||
// Фильтр по статусу
|
||||
if (!empty($filters['status'])) {
|
||||
$query->where('status', $filters['status']);
|
||||
}
|
||||
|
||||
$forms = $query->orderByDesc('created_at')->paginate(20)->withQueryString();
|
||||
|
||||
return [
|
||||
'forms' => $forms,
|
||||
'filters' => $filters,
|
||||
'statuses' => [
|
||||
['value' => 'published', 'label' => 'Опубликовано'],
|
||||
['value' => 'hidden', 'label' => 'Скрыто'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
|
||||
class ListFormResponsesAction
|
||||
{
|
||||
public function run(CustomForm $form, array $filters = []): array
|
||||
{
|
||||
$query = $form->responses()->with('form');
|
||||
|
||||
// Фильтр по статусу просмотра
|
||||
if (isset($filters['checked']) && $filters['checked'] !== '') {
|
||||
$query->where('checked', (bool) $filters['checked']);
|
||||
}
|
||||
|
||||
// Поиск по ID
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('id', 'like', '%' . $filters['search'] . '%');
|
||||
}
|
||||
|
||||
$responses = $query->orderByDesc('created_at')->paginate(20)->withQueryString();
|
||||
|
||||
// Динамические колонки на основе полей формы
|
||||
$columns = collect($form->columns ?? [])->map(function ($field) {
|
||||
return [
|
||||
'name' => $field['data']['name_field'] ?? '',
|
||||
'title' => $field['data']['title_field'] ?? '',
|
||||
'type' => $field['type'] ?? 'text',
|
||||
'options' => $this->extractOptions($field),
|
||||
];
|
||||
})->filter(fn($col) => !empty($col['name']))->values()->toArray();
|
||||
|
||||
return [
|
||||
'form' => $form,
|
||||
'responses' => $responses,
|
||||
'columns' => $columns,
|
||||
'filters' => $filters,
|
||||
];
|
||||
}
|
||||
|
||||
private function extractOptions(array $field): array
|
||||
{
|
||||
if (!in_array($field['type'], ['single_choice', 'multiple_choice'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($field['data']['columns'] ?? [])
|
||||
->mapWithKeys(fn($opt) => [$opt['name_field'] ?? '' => $opt['title_field'] ?? ''])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\CustomForms;
|
||||
|
||||
use App\Containers\Widget\Models\CustomForm;
|
||||
|
||||
class UpdateCustomFormAction
|
||||
{
|
||||
public function run(CustomForm $form, array $data): CustomForm
|
||||
{
|
||||
$form->update($data);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user