1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the AL labs package |
6
|
|
|
* |
7
|
|
|
* (c) Arnaud Langlade |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Al\ResourceManagement\Infrastructure\UserInterface\Web; |
14
|
|
|
|
15
|
|
|
use Al\ResourceManagement\Application\Command\FireEmployee; |
16
|
|
|
use Al\ResourceManagement\Application\Command\HireEmployee; |
17
|
|
|
use Al\ResourceManagement\Application\Command\PromoteEmployee; |
18
|
|
|
use Symfony\Component\Form\AbstractType; |
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType; |
20
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
21
|
|
|
use Symfony\Component\Form\FormEvent; |
22
|
|
|
use Symfony\Component\Form\FormEvents; |
23
|
|
|
|
24
|
|
|
final class EmployeeType extends AbstractType |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
30
|
|
|
{ |
31
|
|
|
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
32
|
|
|
$employee = $event->getData(); |
33
|
|
|
|
34
|
|
|
if ($employee instanceof HireEmployee) { |
35
|
|
|
$form = $event->getForm(); |
36
|
|
|
$form->add('name'); |
37
|
|
|
$form->add('position'); |
38
|
|
|
$form->add('salaryScale'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
if ($employee instanceof PromoteEmployee) { |
42
|
|
|
$form = $event->getForm(); |
43
|
|
|
$form->add('position'); |
44
|
|
|
$form->add('salaryScale'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($employee instanceof FireEmployee) { |
48
|
|
|
$form = $event->getForm(); |
49
|
|
|
$form->add('firedAt', DateType::class, [ |
50
|
|
|
'widget' => 'single_text', |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|