1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
eventoptionbuilderfromobject.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Builders\EventOption;
4
5use Bitrix\Calendar\Core\Builders\BuilderException;
6use Bitrix\Calendar\Core\EventCategory\EventCategory;
7use Bitrix\Calendar\Core\EventOption\EventOption;
8use Bitrix\Calendar\Core\EventOption\OptionsDto;
9use Bitrix\Calendar\Core\Mappers\Factory;
10use Bitrix\Calendar\OpenEvents\Internals\Entity\OpenEventOption;
11use Bitrix\Main\DI\ServiceLocator;
12
14{
15 public function __construct(private readonly OpenEventOption $eventOption)
16 {
17 }
18
19 public function build(): EventOption
20 {
21 return (new EventOption())
22 ->setId($this->getId())
23 ->setEventId($this->getEventId())
24 ->setCategoryId($this->getCategoryId())
25 ->setCategory($this->getCategory())
26 ->setThreadId($this->getThreadId())
27 ->setOptions($this->getOptions())
28 ->setAttendeesCount($this->getAttendeesCount())
29 ;
30 }
31
32 protected function getId(): ?int
33 {
34 return $this->eventOption->getId();
35 }
36
37 protected function getEventId(): ?int
38 {
39 return $this->eventOption->getEventId();
40 }
41
42 protected function getCategoryId(): ?int
43 {
44 return $this->eventOption->getCategoryId();
45 }
46
47 protected function getCategory(): EventCategory
48 {
49 if ($this->getCategoryId() !== null)
50 {
52 $mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
53 $eventCategoryFactory = $mapperFactory->getEventCategory();
54
55 return $eventCategoryFactory->getById($this->getCategoryId());
56 }
57
58 throw new BuilderException('it is impossible to find the event category');
59 }
60
61 protected function getThreadId(): ?int
62 {
63 return $this->eventOption->getThreadId();
64 }
65
66 protected function getOptions(): ?OptionsDto
67 {
68 $options = $this->eventOption->getOptions();
69 $optionsArray = json_decode($options, true) ?? [];
70
71 return OptionsDto::fromArray($optionsArray);
72 }
73
74 protected function getAttendeesCount(): int
75 {
76 return $this->eventOption->getAttendeesCount() ?? 0;
77 }
78}
__construct(private readonly OpenEventOption $eventOption)
$options
Определения commerceml2.php:49