/
BoardSlotCommandHandler.php
85 lines (69 loc) · 2.65 KB
/
BoardSlotCommandHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Concrete\Core\Board\Command;
use Concrete\Core\Entity\Board\InstanceSlotRule;
use Concrete\Core\Localization\Service\Date;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Logging\LoggerFactory;
use Concrete\Core\User\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Id\UuidGenerator;
abstract class BoardSlotCommandHandler
{
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var UuidGenerator
*/
protected $uuidGenerator;
/**
* @var LoggerFactory
*/
protected $loggerFactory;
abstract protected function getRuleType($command);
public function __construct(UuidGenerator $uuidGenerator, EntityManager $entityManager, LoggerFactory $loggerFactory)
{
$this->uuidGenerator = $uuidGenerator;
$this->entityManager = $entityManager;
$this->loggerFactory = $loggerFactory;
}
public function __invoke(BoardSlotCommand $command)
{
$dateService = new Date();
$timezone = $dateService->getUserTimeZoneID();
$dateCreated = new \DateTime();
$dateCreated->setTimezone(new \DateTimeZone($timezone));
$slot = $command->getSlot();
$rule = new InstanceSlotRule();
$rule->setInstance($command->getInstance());
$rule->setSlot($slot);
$rule->setDateCreated($dateCreated->getTimestamp());
$rule->setTimezone($timezone);
$rule->setBatchIdentifier($this->uuidGenerator->generate($this->entityManager, $rule));
$user = new User();
if ($user) {
$userInfo = $user->getUserInfoObject();
if ($userInfo) {
$rule->setUser($userInfo->getEntityObject());
}
}
$rule->setStartDate($command->getStartDate());
$rule->setEndDate($command->getEndDate());
$rule->setBlockID($command->getBlockID());
$rule->setRuleType($this->getRuleType($command));
$this->entityManager->persist($rule);
$this->entityManager->flush();
$instance = $command->getInstance();
$logger = $this->loggerFactory->createLogger(Channels::CHANNEL_BOARD);
$logger->info(t('Instance rule for slot {slot} in instance {instanceID} successfully created with start date {startDate} and end date {endDate}. Rule Type: {ruleType} Block ID: {bID}'), [
'slot' => $command->getSlot(),
'instanceID' => $instance->getBoardInstanceID(),
'startDate' => $command->getStartDate(),
'endDate' => $command->getEndDate(),
'bID' => $command->getBlockID(),
'ruleType' => $this->getRuleType($command)
]);
return $rule;
}
}