| @@ 16-40 (lines=25) @@ | ||
| 13 | use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
| 14 | use Doctrine\Common\Collections\Collection; |
|
| 15 | ||
| 16 | class ByDate implements FilterInterface |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @var Configuration |
|
| 20 | */ |
|
| 21 | private $configuration; |
|
| 22 | ||
| 23 | public function __construct(Configuration $configuration) |
|
| 24 | { |
|
| 25 | $this->configuration = $configuration; |
|
| 26 | } |
|
| 27 | ||
| 28 | public function filter(Collection $tickets): Collection |
|
| 29 | { |
|
| 30 | $configuration = $this->configuration; |
|
| 31 | $today = new \DateTime(); |
|
| 32 | ||
| 33 | $p = function (TicketCounter $ticket) use ($configuration, $today) { |
|
| 34 | $metadata = $configuration->getTicketMetadata($ticket->getTicketType()->getIdentifier()); |
|
| 35 | return $metadata->isAvailableOn($today); |
|
| 36 | }; |
|
| 37 | ||
| 38 | return $tickets->filter($p); |
|
| 39 | } |
|
| 40 | } |
|
| @@ 19-43 (lines=25) @@ | ||
| 16 | /** |
|
| 17 | * @TODO refactor this to use a single filter |
|
| 18 | */ |
|
| 19 | class DiscountByDate implements FilterInterface |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var Configuration |
|
| 23 | */ |
|
| 24 | private $configuration; |
|
| 25 | ||
| 26 | public function __construct(Configuration $configuration) |
|
| 27 | { |
|
| 28 | $this->configuration = $configuration; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function filter(Collection $tickets): Collection |
|
| 32 | { |
|
| 33 | $configuration = $this->configuration; |
|
| 34 | $today = new \DateTime(); |
|
| 35 | ||
| 36 | $p = function (DiscountCode $discountCode) use ($configuration, $today) { |
|
| 37 | $metadata = $configuration->getDiscountCodeMetadata($discountCode->getCode()); |
|
| 38 | return $metadata->isAvailableOn($today); |
|
| 39 | }; |
|
| 40 | ||
| 41 | return $tickets->filter($p); |
|
| 42 | } |
|
| 43 | } |
|
| @@ 16-37 (lines=22) @@ | ||
| 13 | use ConferenceTools\Tickets\Domain\Service\Configuration; |
|
| 14 | use Doctrine\Common\Collections\Collection; |
|
| 15 | ||
| 16 | class IsPrivate implements FilterInterface |
|
| 17 | { |
|
| 18 | /** |
|
| 19 | * @var Configuration |
|
| 20 | */ |
|
| 21 | private $configuration; |
|
| 22 | ||
| 23 | public function __construct(Configuration $configuration) |
|
| 24 | { |
|
| 25 | $this->configuration = $configuration; |
|
| 26 | } |
|
| 27 | ||
| 28 | public function filter(Collection $tickets): Collection |
|
| 29 | { |
|
| 30 | $configuration = $this->configuration; |
|
| 31 | $p = function (TicketCounter $ticket) use ($configuration) { |
|
| 32 | $metadata = $configuration->getTicketMetadata($ticket->getTicketType()->getIdentifier()); |
|
| 33 | return !$metadata->isPrivateTicket(); |
|
| 34 | }; |
|
| 35 | return $tickets->filter($p); |
|
| 36 | } |
|
| 37 | } |
|