Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
recording.php
1<?php
2
3
5
6
15
17{
18 public const RECORDING_KIND_VIDEO = 'VIDEO';
19 public const RECORDING_KIND_AUDIO = 'AUDIO';
20
21 public const LENGTH_FORMAT_SHORT = 'short';
22 public const LENGTH_FORMAT_FULL = 'full';
23
24 public static function getRecordings($conferenceId): Result
25 {
26 $result = new Result();
27 if (!Loader::includeModule('socialservices'))
28 {
29 return $result->addError(new Error('Module socialservices is not installed.'));
30 }
31
32 $meetingResult = ZoomMeetingTable::getById($conferenceId);
33
34 if ($meetingData = $meetingResult->fetch())
35 {
36 $recordingsResult = ZoomMeetingRecordingTable::getList([
37 'select' => ['*'],
38 'filter' => [
39 '=MEETING_ID' => $meetingData['ID'],
40 ],
41 'order' => [
42 'START_DATE' => 'ASC'
43 ]
44 ]);
45 $currentStartDate = '';
46 while ($recording = $recordingsResult->fetch())
47 {
48 if ($currentStartDate != $recording['START_DATE']->format(DATE_ATOM))
49 {
50 $currentStartDate = $recording['START_DATE']->format(DATE_ATOM);
51 $allRecordings[$currentStartDate] = [];
52 }
53 $recording['LENGTH'] = static::getRecordingLength($recording['START_DATE'], $recording['END_DATE']);
54 $recording['LENGTH_FORMATTED'] = static::formatLength($recording['LENGTH']);
55 $recording['LENGTH_HUMAN'] = static::formatLength($recording['LENGTH'], static::LENGTH_FORMAT_FULL);
56
57 $recording['END_DATE_TS'] = $recording['END_DATE']->getTimestamp();
58
59 if ($recording['FILE_ID'] > 0 && Loader::includeModule('disk') && $file = \Bitrix\Disk\File::loadById($recording['FILE_ID']))
60 {
61 $recording['DOWNLOAD_URL'] = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlForDownloadFile($file, true);
62 }
63 else
64 {
65 $parsedDownloadUrl = new Uri($recording['DOWNLOAD_URL']);
66 $recording['DOWNLOAD_URL'] = $parsedDownloadUrl->addParams(['access_token' => $recording['DOWNLOAD_TOKEN']])->__toString();
67 }
68 $allRecordings[$currentStartDate][static::getRecordingKind($recording['FILE_TYPE'])] = $recording;
69 }
70 }
71 if (!empty($allRecordings))
72 {
73 $result->setData(array_values($allRecordings));
74 }
75
76 return $result;
77 }
78
79 public static function getRecordingKind($fileType): ?string
80 {
81 switch ($fileType)
82 {
83 case 'MP4':
84 return static::RECORDING_KIND_VIDEO;
85 case 'M4A':
86 return static::RECORDING_KIND_AUDIO;
87 default:
88 return null;
89 }
90 }
91
97 public static function getRecordingLength(DateTime $startDate, DateTime $endDate): int
98 {
99 return $endDate->getTimestamp() - $startDate->getTimestamp();
100 }
101
102 public static function formatLength(int $lengthSeconds, $format = self::LENGTH_FORMAT_SHORT): string
103 {
104 $hours = intdiv($lengthSeconds, 3600);
105 $lengthSeconds -= $hours * 3600;
106 $minutes = intdiv($lengthSeconds, 60);
107 $seconds = $lengthSeconds - $minutes * 60;
108
109 if ($format === self::LENGTH_FORMAT_FULL)
110 {
111 if($hours)
112 {
113 $result = Loc::getMessage("CRM_ZOOM_CONFERENCE_HOUR_F" . static::getNumericSuffix($hours), ["#VALUE#" => $hours]) . " ";
114 }
115 else
116 {
117 $result = "";
118 }
119 $result .= Loc::getMessage("CRM_ZOOM_CONFERENCE_MINUTE_F" . static::getNumericSuffix($minutes), ["#VALUE#" => $minutes]) . " ";
120 $result .= Loc::getMessage("CRM_ZOOM_CONFERENCE_SECOND_F" . static::getNumericSuffix($seconds), ["#VALUE#" => $seconds]);
121 }
122 else
123 {
124 $result = $hours ? str_pad($hours, 2, "0", STR_PAD_LEFT) . ":" : "";
125 $minutes = str_pad($minutes, 2, "0", STR_PAD_LEFT);
126 $seconds = str_pad($seconds, 2, "0", STR_PAD_LEFT);
127 $result .= "$minutes:$seconds";
128 }
129
130 return $result;
131 }
132
133 protected static function getNumericSuffix($number): int
134 {
135 $keys = [2, 0, 1, 1, 1, 2];
136 $mod = $number % 100;
137 return $mod > 4 && $mod < 20 ? 2 : $keys[min($mod%10, 5)];
138 }
139
140 public static function onRecordingStopped(int $conferenceId, array $recordingsData): Result
141 {
142 $result = new Result();
143 if (!Loader::includeModule('socialservices'))
144 {
145 return $result->addError(new Error('Module socialservices is not installed.'));
146 }
147 $conferenceRecord = ZoomMeetingTable::getRowByExternalId($conferenceId);
148 if (!$conferenceRecord)
149 {
150 return $result->addError(new Error('Conference is not found'));
151 }
152 $updateResult = ZoomMeetingTable::update($conferenceRecord['ID'], [
153 'HAS_RECORDING' => 'Y'
154 ]);
155 if (!$updateResult->isSuccess())
156 {
157 return $result->addErrors($updateResult->getErrors());
158 }
159 return $result;
160 }
161
162 public static function delete(int $conferenceId): Result
163 {
164 $result = new Result();
165 if (!Loader::includeModule('socialservices'))
166 {
167 return $result->addError(new Error('Module socialservices is not installed.'));
168 }
169
170 $recordingsResult = ZoomMeetingRecordingTable::getList([
171 'select' => ['*'],
172 'filter' => [
173 '=MEETING_ID' => $conferenceId,
174 ],
175 ]);
176
177 while ($recording = $recordingsResult->fetch())
178 {
179 $deleteRecordingsResult = ZoomMeetingRecordingTable::delete($recording['ID']);
180 if (!$deleteRecordingsResult->isSuccess())
181 {
182 return $result->addErrors($deleteRecordingsResult->getErrors());
183 }
184 }
185
186 return $result;
187 }
188}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getRecordingLength(DateTime $startDate, DateTime $endDate)
Definition recording.php:97
static onRecordingStopped(int $conferenceId, array $recordingsData)
static formatLength(int $lengthSeconds, $format=self::LENGTH_FORMAT_SHORT)