2022-09-20 19:59:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
use App\Models\Forms\Form;
|
|
|
|
use App\Models\Workspace;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class FormFactory extends Factory
|
|
|
|
{
|
|
|
|
protected $model = Form::class;
|
|
|
|
|
|
|
|
public function forWorkspace(Workspace $workspace)
|
|
|
|
{
|
|
|
|
return $this->state(function (array $attributes) use ($workspace) {
|
|
|
|
return [
|
|
|
|
'workspace_id' => $workspace->id,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function forDatabase(string $databaseId)
|
|
|
|
{
|
|
|
|
return $this->state(function (array $attributes) use ($databaseId) {
|
|
|
|
return [
|
|
|
|
'database_id' => $databaseId,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withProperties(array $properties)
|
|
|
|
{
|
|
|
|
return $this->state(function (array $attributes) use ($properties) {
|
|
|
|
return [
|
|
|
|
'properties' => $properties,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createdBy(User $user)
|
|
|
|
{
|
|
|
|
return $this->state(function (array $attributes) use ($user) {
|
|
|
|
return [
|
|
|
|
'creator_id' => $user->id,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title' => $this->faker->text(30),
|
2022-09-21 15:23:37 +00:00
|
|
|
'description' => $this->faker->randomHtml(1),
|
2022-10-16 17:27:14 +00:00
|
|
|
'visibility' => 'public',
|
2022-09-20 19:59:52 +00:00
|
|
|
'notifies' => false,
|
|
|
|
'send_submission_confirmation' => false,
|
|
|
|
'webhook_url' => null,
|
|
|
|
'theme' => $this->faker->randomElement(Form::THEMES),
|
|
|
|
'width' => $this->faker->randomElement(Form::WIDTHS),
|
|
|
|
'dark_mode' => $this->faker->randomElement(Form::DARK_MODE_VALUES),
|
|
|
|
'color' => '#3B82F6',
|
|
|
|
'hide_title' => false,
|
|
|
|
'no_branding' => false,
|
|
|
|
'uppercase_labels' => true,
|
|
|
|
'transparent_background' => false,
|
|
|
|
'submit_button_text' => 'Submit',
|
2023-01-10 13:52:14 +00:00
|
|
|
'editable_submissions' => false,
|
2022-09-20 19:59:52 +00:00
|
|
|
're_fillable' => false,
|
|
|
|
're_fill_button_text' => 'Fill Again',
|
|
|
|
'submitted_text' => '<p>Amazing, we saved your answers. Thank you for your time and have a great day!</p>',
|
|
|
|
'notification_sender' => 'OpenForm',
|
|
|
|
'notification_subject' => 'We saved your answers',
|
|
|
|
'notification_body' => 'Hello there 👋 <br>This is a confirmation that your submission was successfully saved.',
|
|
|
|
'notifications_include_submission' => true,
|
|
|
|
'use_captcha' => false,
|
|
|
|
'can_be_indexed' => true,
|
|
|
|
'password' => false,
|
2022-09-21 15:23:37 +00:00
|
|
|
'tags' => [],
|
|
|
|
'slack_webhook_url' => null,
|
2023-04-12 11:17:05 +00:00
|
|
|
'editable_submissions_button_text' => 'Edit submission',
|
2023-08-30 09:43:11 +00:00
|
|
|
'confetti_on_submission' => false,
|
|
|
|
'seo_meta' => [],
|
2022-09-20 19:59:52 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a Notion database list of properties, format them as the front-end does:
|
|
|
|
* - Adds id
|
|
|
|
* - Adds placeholder, prefill, help
|
|
|
|
* - Adds notion_name
|
|
|
|
* @param $properties
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function formatProperties($properties): array
|
|
|
|
{
|
|
|
|
return collect($properties)->map(function ($property) {
|
|
|
|
return array_merge($property, [
|
|
|
|
'id' => Str::uuid(),
|
|
|
|
'placeholder' => $property['name'],
|
|
|
|
'prefill' => null,
|
|
|
|
'help' => 'Please fill this input',
|
|
|
|
'notion_name' => $property['name'],
|
|
|
|
]);
|
|
|
|
})->toArray();
|
|
|
|
}
|
|
|
|
}
|