Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attendeesdescription.php
1<?php
2
4
8
9IncludeModuleLangFile(__FILE__);
10
12{
14 private string $languageId;
15
16 public function __construct(string $languageId)
17 {
18 $this->languageId = $languageId;
19 }
20
21 public function cutAttendeesFromDescription(?string $description): string
22 {
23 if (!$description)
24 {
25 return '';
26 }
27
28 $pattern = "|"
29 . Loc::getMessage('CAL_SYNC_UTIL_ATTENDEES', false, $this->languageId)
30 . "(.+?)"
31 . "\D+(.?);[\r\n]*|is"
32 ;
33 $description = preg_replace($pattern, "", $description);
34
35 $acceptedAttendeePattern = "|"
36 . Loc::getMessage('CAL_SYNC_UTIL_ATTENDEES_STATUS_Y', false, $this->languageId)
37 . "(.+?)"
38 . "\D+(.?);[\r\n]*|is"
39 ;
40 $description = preg_replace($acceptedAttendeePattern, "", $description);
41
42 return trim($description);
43 }
44
55 public function addAttendeesToDescription(array $attendeesCodes, ?string $description, ?int $parentId): string
56 {
57 $result = $this->prepareUserNames($attendeesCodes, $parentId)
58 . ';'
59 ;
60
61 if ($description)
62 {
63 $result .= "\r\n\r\n" . $description;
64 }
65
66 return $result;
67 }
68
78 private function prepareUserNames(array $codes, ?int $parentId): string
79 {
80 $result = '';
81 $attendees = [];
82 $users = \CCalendar::GetDestinationUsers($codes, true);
83 $usersMeetingStatus = [];
84
85 if ($parentId)
86 {
87 $usersMeetingStatus = $this->getUsersMeetingStatus($parentId);
88 }
89
90 if (!$usersMeetingStatus)
91 {
92 $names = array_map(static function($user) {
93 return $user['FORMATTED_NAME'];
94 }, $users);
95
96 return implode(', ', $names);
97 }
98
99 foreach ($users as $user)
100 {
101 $userName = $user['FORMATTED_NAME'];
102
103 $attendees[] = $userName;
104 }
105
106 if (!empty($attendees))
107 {
108 $result .= Loc::getMessage('CAL_SYNC_UTIL_ATTENDEES', false, $this->languageId)
109 . ': '
110 . implode(', ', $attendees)
111 ;
112 }
113
114 return $result;
115 }
116
125 private function getUsersMeetingStatus(int $eventId): array
126 {
127 $result = [];
128 $events = EventTable::query()
129 ->setSelect(['OWNER_ID', 'MEETING_STATUS'])
130 ->where('PARENT_ID', $eventId)
131 ->exec()
132 ;
133 while ($event = $events->fetchObject())
134 {
135 $result[$event->getOwnerId()] = $event->getMeetingStatus();
136 }
137
138 return $result;
139 }
140}
addAttendeesToDescription(array $attendeesCodes, ?string $description, ?int $parentId)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29