1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Event.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\OpenEvents\Controller;
4
5use Bitrix\Calendar\OpenEvents\Exception\EventBusyException;
6use Bitrix\Calendar\OpenEvents\Exception\MaxAttendeesReachedException;
7use Bitrix\Calendar\OpenEvents\Provider;
8use Bitrix\Calendar\OpenEvents\Controller\Filter\OpenEvent as ValidateFilter;
9use Bitrix\Calendar\OpenEvents\Controller\Request\OpenEvent as RequestDto;
10use Bitrix\Calendar\Event\Service\OpenEventPullService;
11use Bitrix\Calendar\Internals\Exception\PermissionDenied;
12use Bitrix\Calendar\OpenEvents\Service\OpenEventAttendeeService;
13use Bitrix\Calendar\OpenEvents\Service\OpenEventService;
14use Bitrix\Calendar\Ui\CountersManager;
15use Bitrix\Main\Engine\AutoWire\Parameter;
16use Bitrix\Main\Engine\Controller;
17use Bitrix\Main\Engine\CurrentUser;
18use Bitrix\Main\Error;
19use Bitrix\Main\Type\Date;
20
21final class Event extends Controller
22{
23 use FeatureTrait;
24
25 protected int $userId;
27
28 protected function init(): void
29 {
30 parent::init();
31
32 $this->userId = (int)CurrentUser::get()->getId();
33 $this->eventProvider = new Provider\EventProvider($this->userId);
34 }
35
36 public function configureActions(): array
37 {
38 return [
39 'list' => [
40 '+prefilters' => [
41 new ValidateFilter\ValidateGetOpenEventList(),
42 ],
43 ],
44 'setAttendeeStatus' => [
45 '+prefilters' => [
46 new ValidateFilter\ValidateSetEventAttendeeStatus(),
47 ],
48 ],
49 'setWatched' => [
50 '+prefilters' => [
51 new ValidateFilter\ValidateSetEventsWatched(),
52 ],
53 ],
54 ];
55 }
56
57 public function getAutoWiredParameters(): array
58 {
59 $request = $this->getRequest();
60
61 return [
62 new Parameter(
63 RequestDto\SetEventAttendeeStatusDto::class,
64 static fn () => RequestDto\SetEventAttendeeStatusDto::fromRequest($request->toArray())
65 ),
66 new Parameter(
67 RequestDto\GetOpenEventListDto::class,
68 static function () use ($request)
69 {
70 $requestData = $request->toArray();
71 $today = new \DateTimeImmutable();
72 $plus3month = new \DateTimeImmutable('+3 month');
73 $fromYear = $request['fromYear'] ?? $today->format('Y');
74 $fromMonth = $request['fromMonth'] ?? $today->format('m');
75 $toYear = $request['toYear'] ?? $plus3month->format('Y');
76 $toMonth = $request['toMonth'] ?? $plus3month->format('m');
77
78 return RequestDto\GetOpenEventListDto::fromRequest([
79 ...$requestData,
80 'fromYear' => $fromYear,
81 'fromMonth' => $fromMonth,
82 'toYear' => $toYear,
83 'toMonth' => $toMonth,
84 ]);
85 }
86 ),
87 new Parameter(
88 RequestDto\SetEventWatchedDto::class,
89 static fn () => RequestDto\SetEventWatchedDto::fromRequest($request->toArray())
90 )
91 ];
92 }
93
94 public function listAction(RequestDto\GetOpenEventListDto $getOpenEventListDto): array
95 {
96 OpenEventPullService::getInstance()->addToWatch($this->userId);
97
98 $fromDate = "01.$getOpenEventListDto->fromMonth.$getOpenEventListDto->fromYear";
99 $toMonth = $getOpenEventListDto->toMonth + 1;
100 $toDate = "00.$toMonth.$getOpenEventListDto->toYear";
101
103 categoriesIds: $getOpenEventListDto->categoryId ? [$getOpenEventListDto->categoryId] : null,
104 fromDate: (new Date($fromDate, 'd.m.Y'))->toString(),
105 toDate: (new Date($toDate, 'd.m.Y'))->toString(),
106 );
107
108 return $this->eventProvider->list($filter);
109 }
110
111 public function getTsRangeAction(int $categoryId): array
112 {
114 categoriesIds: $categoryId ? [$categoryId] : null,
115 );
116
117 return $this->eventProvider->getTsRange($filter);
118 }
119
120 public function setAttendeeStatusAction(RequestDto\SetEventAttendeeStatusDto $setEventAttendeeStatusDto): void
121 {
122 try
123 {
124 OpenEventAttendeeService::getInstance()->setEventAttendeeStatus($this->userId, $setEventAttendeeStatusDto);
125 }
126 catch (PermissionDenied)
127 {
128 $this->addError(new Error('permission denied', 'permission_denied'));
129
130 return;
131 }
133 {
134 $this->addError(new Error('max attendees reached', 'max_attendees_reached'));
135
136 return;
137 }
138 catch (EventBusyException)
139 {
140 $this->addError(new Error('internal error', 'internal_error'));
141
142 return;
143 }
144 }
145
146 public function setWatchedAction(RequestDto\SetEventWatchedDto $setEventWatchedDto): void
147 {
148 OpenEventService::getInstance()->setEventsWatched($this->userId, $setEventWatchedDto->eventIds);
149 }
150}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
setWatchedAction(RequestDto\SetEventWatchedDto $setEventWatchedDto)
Определения Event.php:146
Provider EventProvider $eventProvider
Определения Event.php:26
setAttendeeStatusAction(RequestDto\SetEventAttendeeStatusDto $setEventAttendeeStatusDto)
Определения Event.php:120
getTsRangeAction(int $categoryId)
Определения Event.php:111
listAction(RequestDto\GetOpenEventListDto $getOpenEventListDto)
Определения Event.php:94
Определения error.php:15
Определения date.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54