/
ScheduleCustomElementCommandHandler.php
94 lines (80 loc) · 3.24 KB
/
ScheduleCustomElementCommandHandler.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
86
87
88
89
90
91
92
93
94
<?php
namespace Concrete\Core\Board\Designer\Command;
use Concrete\Core\Application\Application;
use Concrete\Core\Entity\Board\InstanceSlotRule;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Logging\LoggerFactory;
use Concrete\Core\User\User;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Id\UuidGenerator;
class ScheduleCustomElementCommandHandler
{
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var Application
*/
protected $app;
/**
* @var User
*/
protected $user;
/**
* @var UuidGenerator
*/
protected $uuidGenerator;
/**
* @var LoggerFactory
*/
protected $loggerFactory;
public function __construct(UuidGenerator $uuidGenerator, LoggerFactory $loggerFactory, User $user, Application $app, EntityManager $entityManager)
{
$this->uuidGenerator = $uuidGenerator;
$this->app = $app;
$this->user = $user;
$this->entityManager = $entityManager;
$this->loggerFactory = $loggerFactory;
}
public function __invoke(ScheduleCustomElementCommand $command)
{
$element = $command->getElement();
$batchIdentifier = $this->uuidGenerator->generate($this->entityManager, $element);
foreach($command->getInstances() as $instance) {
$startDate = new \DateTime($command->getStartDateTime(), new \DateTimeZone($command->getTimezone()));
if ($command->getEndDateTime()) {
$endDate = new \DateTime($command->getEndDateTime(), new \DateTimeZone($command->getTimezone()));
}
$block = $element->createBlock();
$boardCommand = new AddDesignerSlotToBoardCommand();
$boardCommand->setTimezone($command->getTimezone());
$boardCommand->setRuleType(InstanceSlotRule::RULE_TYPE_DESIGNER_CUSTOM_CONTENT);
if ($command->getLockType() == 'L') {
$boardCommand->setIsLocked(true);
}
if ($this->user->isRegistered()) {
$boardCommand->setUser($this->user->getUserInfoObject()->getEntityObject());
}
$boardCommand->setBatchIdentifier($batchIdentifier);
$boardCommand->setNotes($element->getElementName());
$boardCommand->setSlot($command->getSlot());
$boardCommand->setInstance($instance);
$boardCommand->setBlockID($block->getBlockID());
$boardCommand->setStartDate($startDate->getTimestamp());
if (isset($endDate)) {
$boardCommand->setEndDate($endDate->getTimestamp());
}
$this->app->executeCommand($boardCommand);
$logger = $this->loggerFactory->createLogger(Channels::CHANNEL_BOARD);
$logger->info(t('Element {elementName} scheduled for {slot} in instance {instanceID} successfully with start date {startDate} and lock type {lockType}'), [
'slot' => $command->getSlot(),
'instanceID' => $instance->getBoardInstanceID(),
'startDate' => $command->getStartDateTime(),
'elementName' => $element->getElementName(),
'lockType' => $command->getLockType()
]);
}
$this->entityManager->flush();
}
}