2022-10-02 18:38:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Templates;
|
|
|
|
|
|
|
|
use App\Models\Template;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
2023-09-08 11:00:28 +00:00
|
|
|
class FormTemplateRequest extends FormRequest
|
2022-10-02 18:38:41 +00:00
|
|
|
{
|
2022-12-01 12:13:32 +00:00
|
|
|
const IGNORED_KEYS = [
|
|
|
|
'id',
|
|
|
|
'creator',
|
|
|
|
'cleanings',
|
|
|
|
'closes_at',
|
|
|
|
'deleted_at',
|
|
|
|
'updated_at',
|
|
|
|
'form_pending_submission_key',
|
|
|
|
'is_closed',
|
|
|
|
'is_pro',
|
|
|
|
'is_password_protected',
|
|
|
|
'last_edited_human',
|
|
|
|
'max_number_of_submissions_reached',
|
|
|
|
'notifies',
|
|
|
|
'notification_body',
|
|
|
|
'notification_emails',
|
|
|
|
'notification_sender',
|
|
|
|
'notification_subject',
|
|
|
|
'notifications_include_submission',
|
|
|
|
'notifies_slack',
|
|
|
|
'slack_webhook_url',
|
|
|
|
'removed_properties',
|
|
|
|
'creator_id',
|
|
|
|
'extra',
|
|
|
|
'workspace',
|
|
|
|
'workspace_id',
|
|
|
|
'submissions',
|
|
|
|
'submissions_count',
|
|
|
|
'views',
|
|
|
|
'views_count',
|
|
|
|
'visibility',
|
|
|
|
'webhook_url',
|
|
|
|
];
|
|
|
|
|
2022-10-02 18:38:41 +00:00
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2023-09-08 11:00:28 +00:00
|
|
|
$slugRule = '';
|
|
|
|
if($this->id){
|
|
|
|
$slugRule = ','.$this->id;
|
|
|
|
}
|
2022-10-02 18:38:41 +00:00
|
|
|
return [
|
|
|
|
'form' => 'required|array',
|
2023-09-08 11:00:28 +00:00
|
|
|
'publicly_listed' => 'boolean',
|
2022-10-02 18:38:41 +00:00
|
|
|
'name' => 'required|string|max:60',
|
2023-09-08 11:00:28 +00:00
|
|
|
'slug' => 'required|string|alpha_dash|unique:templates,slug'.$slugRule,
|
|
|
|
'short_description' => 'required|string|max:1000',
|
2023-09-08 13:30:57 +00:00
|
|
|
'description' => 'required|string',
|
2022-10-02 18:38:41 +00:00
|
|
|
'image_url' => 'required|string',
|
2023-09-08 11:00:28 +00:00
|
|
|
'types' => 'nullable|array',
|
|
|
|
'industries' => 'nullable|array',
|
|
|
|
'related_templates' => 'nullable|array',
|
2022-10-02 18:38:41 +00:00
|
|
|
'questions' => 'array',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-12-01 12:13:32 +00:00
|
|
|
public function getTemplate(): Template
|
2022-10-02 18:38:41 +00:00
|
|
|
{
|
|
|
|
$structure = $this->form;
|
2022-12-01 12:13:32 +00:00
|
|
|
foreach ($structure as $key => $val) {
|
|
|
|
if (in_array($key, self::IGNORED_KEYS)) {
|
|
|
|
unset($structure[$key]);
|
2022-10-02 18:38:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-08 13:30:57 +00:00
|
|
|
|
2022-10-02 18:38:41 +00:00
|
|
|
return new Template([
|
2023-10-13 10:11:03 +00:00
|
|
|
'creator_id' => $this->user()?->id ?? null,
|
2023-09-08 11:00:28 +00:00
|
|
|
'publicly_listed' => $this->publicly_listed,
|
2022-10-02 18:38:41 +00:00
|
|
|
'name' => $this->name,
|
|
|
|
'slug' => $this->slug,
|
2023-09-08 11:00:28 +00:00
|
|
|
'short_description' => $this->short_description,
|
2022-10-02 18:38:41 +00:00
|
|
|
'description' => $this->description,
|
|
|
|
'image_url' => $this->image_url,
|
|
|
|
'structure' => $structure,
|
2023-09-08 11:00:28 +00:00
|
|
|
'types' => $this->types ?? [],
|
|
|
|
'industries' => $this->industries ?? [],
|
|
|
|
'related_templates' => $this->related_templates ?? [],
|
2022-10-02 18:38:41 +00:00
|
|
|
'questions' => $this->questions ?? []
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|