Add mail for registration
This commit is contained in:
parent
c3a2417cac
commit
9144ae1028
|
@ -40,17 +40,23 @@ class FieldCollection extends Collection
|
||||||
*/
|
*/
|
||||||
public function getMailRecipient(): ?stdClass
|
public function getMailRecipient(): ?stdClass
|
||||||
{
|
{
|
||||||
$firstname = $this->findBySpecialType(SpecialType::FIRSTNAME)?->value;
|
|
||||||
$lastname = $this->findBySpecialType(SpecialType::LASTNAME)?->value;
|
|
||||||
$email = $this->findBySpecialType(SpecialType::EMAIL)?->value;
|
$email = $this->findBySpecialType(SpecialType::EMAIL)?->value;
|
||||||
|
|
||||||
return $firstname && $lastname && $email
|
return $this->getFullname() && $email
|
||||||
? (object) [
|
? (object) [
|
||||||
'name' => "$firstname $lastname",
|
'name' => $this->getFullname(),
|
||||||
"email" => $email,
|
"email" => $email,
|
||||||
] : null;
|
] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFullname(): ?string
|
||||||
|
{
|
||||||
|
$firstname = $this->findBySpecialType(SpecialType::FIRSTNAME)?->value;
|
||||||
|
$lastname = $this->findBySpecialType(SpecialType::LASTNAME)?->value;
|
||||||
|
|
||||||
|
return $firstname && $lastname ? "$firstname $lastname" : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $input
|
* @param array<string, mixed> $input
|
||||||
*/
|
*/
|
||||||
|
@ -59,6 +65,11 @@ class FieldCollection extends Collection
|
||||||
return $form->getFields()->each(fn ($field) => $field->value = array_key_exists($field->key, $input) ? $input[$field->key] : $field->default());
|
return $form->getFields()->each(fn ($field) => $field->value = array_key_exists($field->key, $input) ? $input[$field->key] : $field->default());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function find(Field $givenField): ?Field
|
||||||
|
{
|
||||||
|
return $this->first(fn ($field) => $field->key === $givenField->key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, mixed>
|
* @return array<string, mixed>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -93,10 +93,18 @@ abstract class Field extends Data
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
$this->key => $this->value,
|
$this->key => $this->value,
|
||||||
$this->getDisplayAttribute() => $this->getPresenter()->present($this->value),
|
$this->getDisplayAttribute() => $this->presentRaw(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function presentRaw()
|
||||||
|
{
|
||||||
|
return $this->getPresenter()->present($this->value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, string>
|
* @return array<string, string>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Form\Mails;
|
namespace App\Form\Mails;
|
||||||
|
|
||||||
|
use App\Form\Data\FormConfigData;
|
||||||
|
use App\Form\Models\Participant;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
|
@ -13,6 +15,9 @@ class ConfirmRegistrationMail extends Mailable
|
||||||
{
|
{
|
||||||
use Queueable, SerializesModels;
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public string $fullname;
|
||||||
|
public FormConfigData $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new message instance.
|
* Create a new message instance.
|
||||||
*
|
*
|
||||||
|
@ -20,7 +25,8 @@ class ConfirmRegistrationMail extends Mailable
|
||||||
*/
|
*/
|
||||||
public function __construct(public Participant $participant)
|
public function __construct(public Participant $participant)
|
||||||
{
|
{
|
||||||
//
|
$this->fullname = $participant->getFields()->getFullname();
|
||||||
|
$this->config = $participant->getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +49,7 @@ class ConfirmRegistrationMail extends Mailable
|
||||||
public function content()
|
public function content()
|
||||||
{
|
{
|
||||||
return new Content(
|
return new Content(
|
||||||
view: 'view.name',
|
markdown: 'mail.form.confirm-registration',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Form\Models;
|
namespace App\Form\Models;
|
||||||
|
|
||||||
use App\Form\Data\FieldCollection;
|
use App\Form\Data\FieldCollection;
|
||||||
|
use App\Form\Data\FormConfigData;
|
||||||
use App\Form\Mails\ConfirmRegistrationMail;
|
use App\Form\Mails\ConfirmRegistrationMail;
|
||||||
use App\Form\Scopes\ParticipantFilterScope;
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
@ -52,6 +53,17 @@ class Participant extends Model
|
||||||
return FieldCollection::fromRequest($this->form, $this->data);
|
return FieldCollection::fromRequest($this->form, $this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getConfig(): FormConfigData
|
||||||
|
{
|
||||||
|
return tap($this->form->config, function ($config) {
|
||||||
|
$config->sections->each(function ($section) {
|
||||||
|
$section->fields->each(function ($field) {
|
||||||
|
$field->value = $this->getFields()->find($field)->value;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function sendConfirmationMail(): void
|
public function sendConfirmationMail(): void
|
||||||
{
|
{
|
||||||
if (!$this->getFields()->getMailRecipient()) {
|
if (!$this->getFields()->getMailRecipient()) {
|
||||||
|
|
|
@ -30,14 +30,6 @@ class ParticipantFactory extends Factory
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, FormtemplateSectionRequest> $sections
|
|
||||||
*/
|
|
||||||
public function sections(array $sections): self
|
|
||||||
{
|
|
||||||
return $this->state(['config' => ['sections' => array_map(fn ($section) => $section->create(), $sections)]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, mixed> $data
|
* @param array<string, mixed> $data
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
@component('mail::message')
|
||||||
|
# Hallo {{$fullname}},
|
||||||
|
|
||||||
|
{{ $participant->form->mail_top }}
|
||||||
|
{{ $participant->form->mail_bottom }}
|
||||||
|
|
||||||
|
@foreach($config->sections as $section)
|
||||||
|
## {{$section->name}}
|
||||||
|
@foreach ($section->fields as $field)
|
||||||
|
* {{$field->name}}: {{$field->presentRaw()}}
|
||||||
|
@endforeach
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
Im Anhang findet ihr die aktuelle Rechnung des Stammes Silva für das laufende Jahr. Bitte begleicht diese bis zum angegebenen Datum.
|
||||||
|
|
||||||
|
@component('mail::subcopy')
|
||||||
|
|
||||||
|
Herzliche Grüße und gut Pfad
|
||||||
|
|
||||||
|
Der Stammesvorstand
|
||||||
|
@endcomponent
|
||||||
|
|
||||||
|
@endcomponent
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
|
use App\Form\Enums\SpecialType;
|
||||||
|
use App\Form\Mails\ConfirmRegistrationMail;
|
||||||
|
use App\Form\Models\Form;
|
||||||
|
use App\Form\Models\Participant;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class FormRegisterMailTest extends FormTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItShowsFormContent(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$participant = Participant::factory()
|
||||||
|
->for(Form::factory()->mailTop('mail top')->mailBottom('mail bottom'))->create();
|
||||||
|
|
||||||
|
$mail = new ConfirmRegistrationMail($participant);
|
||||||
|
$mail->assertSeeInText('mail top');
|
||||||
|
$mail->assertSeeInText('mail bottom');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShowsParticipantGreeting(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$participant = Participant::factory()->for(Form::factory()->sections([
|
||||||
|
FormtemplateSectionRequest::new()->name('Persönliches')->fields([
|
||||||
|
$this->textField('vorname')->name('Vorname')->specialType(SpecialType::FIRSTNAME),
|
||||||
|
$this->textField('nachname')->specialType(SpecialType::LASTNAME),
|
||||||
|
])
|
||||||
|
]))
|
||||||
|
->data(['vorname' => 'Max', 'nachname' => 'Muster'])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$mail = new ConfirmRegistrationMail($participant);
|
||||||
|
$mail->assertSeeInText('# Hallo Max Muster');
|
||||||
|
$mail->assertSeeInText('## Persönliches');
|
||||||
|
$mail->assertSeeInText('* Vorname: Max');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue