1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ConferenceTools\Checkin\Domain\Projection; |
4
|
|
|
|
5
|
|
|
use Carnage\Cqrs\MessageHandler\AbstractMethodNameMessageHandler; |
6
|
|
|
use Carnage\Cqrs\Persistence\ReadModel\RepositoryInterface; |
7
|
|
|
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateCheckedIn; |
8
|
|
|
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateInformationUpdated; |
9
|
|
|
use ConferenceTools\Checkin\Domain\Event\Delegate\DelegateRegistered; |
10
|
|
|
use ConferenceTools\Checkin\Domain\ReadModel\Delegate as DelegateModel; |
11
|
|
|
use Doctrine\Common\Collections\Criteria; |
12
|
|
|
|
13
|
|
|
class Delegate extends AbstractMethodNameMessageHandler |
14
|
|
|
{ |
15
|
|
|
private $repository; |
16
|
|
|
|
17
|
3 |
|
public function __construct(RepositoryInterface $repository) |
18
|
|
|
{ |
19
|
3 |
|
$this->repository = $repository; |
20
|
3 |
|
} |
21
|
|
|
|
22
|
1 |
|
protected function handleDelegateRegistered(DelegateRegistered $event) |
23
|
|
|
{ |
24
|
1 |
|
$entity = new DelegateModel( |
25
|
1 |
|
$event->getDelegateId(), |
26
|
1 |
|
$event->getDelegateInfo(), |
27
|
1 |
|
$event->getTicket(), |
28
|
1 |
|
$event->getPurchaserEmail() |
29
|
|
|
); |
30
|
1 |
|
$this->repository->add($entity); |
31
|
1 |
|
$this->repository->commit(); |
32
|
1 |
|
} |
33
|
|
|
|
34
|
1 |
|
protected function handleDelegateInformationUpdated(DelegateInformationUpdated $event) |
35
|
|
|
{ |
36
|
1 |
|
$model = $this->loadDelegate($event->getId()); |
37
|
1 |
|
$model->updateDelegateInfo($event->getDelegateInfo()); |
38
|
1 |
|
$this->repository->commit(); |
39
|
1 |
|
} |
40
|
|
|
|
41
|
1 |
|
protected function handleDelegateCheckedIn(DelegateCheckedIn $event) |
42
|
|
|
{ |
43
|
1 |
|
$model = $this->loadDelegate($event->getId()); |
44
|
1 |
|
$model->checkIn(); |
45
|
1 |
|
$this->repository->commit(); |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $delegateId |
50
|
|
|
* @return DelegateModel |
51
|
|
|
*/ |
52
|
2 |
|
private function loadDelegate(string $delegateId): DelegateModel |
53
|
|
|
{ |
54
|
2 |
|
$criteria = Criteria::create(); |
55
|
2 |
|
$criteria->where(Criteria::expr()->eq('delegateId', $delegateId)); |
56
|
|
|
/** @var DelegateModel $model */ |
57
|
2 |
|
$model = $this->repository->matching($criteria)->current(); |
58
|
2 |
|
return $model; |
59
|
|
|
} |
60
|
|
|
} |