Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
servicesynchronization.php
1<?php
2
4
14
19{
23 private $factory;
24
28 public function __construct(FactoryInterface $factory)
29 {
30 $this->factory = $factory;
31 }
32
40 public function createEvent(Event $event, Context $context): Result
41 {
42 $manager = $this->factory->getEventManager();
43 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection());
44 $actionResult = $manager->create($event, $eventContext);
45
46 return $this->handleResult($actionResult);
47 }
48
57 public function updateEvent(Event $event, EventContext $context): Result
58 {
59 $manager = $this->factory->getEventManager();
60 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection(), $event);
61 $actionResult = $manager->update($event, $eventContext);
62
63 return $this->handleResult($actionResult);
64 }
65
66 public function deleteEvent(Event $event, EventContext $context): Result
67 {
68 $manager = $this->factory->getEventManager();
69 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection());
70 $actionResult = $manager->delete($event, $eventContext);
71
72 return $this->handleResult($actionResult);
73 }
74
75 public function createInstance(Event $event, EventContext $context): Result
76 {
77 $manager = $this->factory->getEventManager();
78 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection());
79 $actionResult = $manager->createInstance($event, $eventContext);
80
81 return $this->handleResult($actionResult);
82 }
83
84 public function updateInstance(Event $event, EventContext $context): Result
85 {
86 $manager = $this->factory->getEventManager();
87 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection());
88 $actionResult = $manager->updateInstance($event, $eventContext);
89
90 return $this->handleResult($actionResult);
91 }
92
93 public function deleteInstance(Event $event, EventContext $context): Result
94 {
95 $manager = $this->factory->getEventManager();
96 $eventContext = $this->prepareEventContextFromContext($context, $event->getSection());
97 $actionResult = $manager->deleteInstance($event, $eventContext);
98
99 return $this->handleResult($actionResult);
100 }
101
102 public function createSection(Section $section): Result
103 {
104 $manager = $this->factory->getSectionManager();
105 $manager->create($section);
106
107 return new Result();
108 }
109
110 public function updateSection(Section $section): Result
111 {
112 $manager = $this->factory->getSectionManager();
113 $manager->update($section);
114
115 return new Result();
116 }
117
118 public function deleteSection(Section $section): Result
119 {
120 $manager = $this->factory->getSectionManager();
121 $manager->delete($section);
122
123 return new Result();
124 }
125
132 private function prepareEventContextFromContext(Context $context, Section $eventSection, Event $event = null): EventContext
133 {
134 $eventContext = new EventContext();
136 $sectionConnectionMap = $context->sectionConnections;
137 $sectionConnection = $sectionConnectionMap->getItem($eventSection->getId());
138
139 if ($event)
140 {
141 if (isset($context->eventConnections))
142 {
143 $eventContext->setEventConnection($context->eventConnections->getItem($event->getId()));
144 }
145
146 if ($location = $event->getLocation())
147 {
148 $eventContext->location = Util::getTextLocation((string)$location);
149 }
150 }
151
152 $eventContext->setSectionConnection($sectionConnection);
153
154 return $eventContext;
155 }
156
161 public function handleResult(Result $actionResult): Result
162 {
163 $result = new Result();
164 if ($actionResult->isSuccess())
165 {
166 $result->setData($actionResult->getData());
167 }
168 else
169 {
170 $result->addErrors(
171 $this->factory->handleErrors(
173 $actionResult->getErrorCollection()
174 )
175 );
176 }
177
178 return $result;
179 }
180}
isSuccess($internalCall=false)
Definition result.php:52