protected function saveStat()
{
$callLength = 0;
if ($this->startDate instanceof DateTime && $this->endDate instanceof DateTime)
{
$callLength = $this->endDate->getTimestamp() - $this->startDate->getTimestamp();
}
$userCountChat = count($this->users);
$usersActive = 0;
$mobileUsers = 0;
$externalUsers = 0;
$screenShared = false;
$recorded = false;
$authTypes = UserTable::getList([
'select' => ['ID', 'EXTERNAL_AUTH_ID'],
'filter' => ['=ID' => $this->getUsers()]
])->fetchAll();
$authTypes = array_column($authTypes, 'EXTERNAL_AUTH_ID', 'ID');
foreach ($this->users as $userId => $user)
{
if ($user->getLastSeen() != null)
{
$usersActive++;
}
if ($user->isUaMobile())
{
$mobileUsers++;
}
if ($authTypes[$userId] === Auth::AUTH_TYPE)
{
$externalUsers++;
if ($user->getFirstJoined())
{
$userLateness = $user->getFirstJoined()->getTimestamp() - $this->startDate->getTimestamp();
AddEventToStatFile("im", "im_call_finish", $this->id, $userLateness, "user_lateness", $userId);
}
}
if ($user->wasRecorded())
{
$recorded = true;
}
if ($user->wasRecorded())
{
$screenShared = true;
}
}
$chatType = null;
$finishStatus = 'normal';
if ($this->entityType === EntityType::CHAT)
{
if(is_numeric($this->entityId))
{
$chatType = 'private';
// private chat, entity id === other user id
$otherUserState =
$this->getUser($this->entityId)
? $this->getUser($this->entityId)->getState()
: ''
;
if ($otherUserState == CallUser::STATE_DECLINED)
{
$finishStatus = 'declined';
}
else if ($otherUserState == CallUser::STATE_BUSY)
{
$finishStatus = 'busy';
}
else if ($otherUserState == CallUser::STATE_UNAVAILABLE || $otherUserState == CallUser::STATE_CALLING)
{
$finishStatus = 'unavailable';
}
}
else
{
$chatId = Dialog::getChatId($this->entityId);
$isVideoConf = (bool)AliasTable::getRow([
'filter' => ['=ENTITY_ID' => $chatId, '=ENTITY_TYPE' => BitrixImAlias::ENTITY_TYPE_VIDEOCONF]
]);
$chatType = 'group';
}
}
if ($callLength > 30 && $finishStatus === 'normal')
{
BitrixImLimit::incrementCounter(BitrixImLimit::COUNTER_CALL_SUCCESS);
}
AddEventToStatFile("im", "im_call_finish", $this->id, $userCountChat, "user_count_chat", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, $usersActive, "user_count_call", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, $mobileUsers, "user_count_mobile", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, $externalUsers, "user_count_external", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, $callLength, "call_length", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, ($screenShared ? "Y" : "N"), "screen_shared", 0);
AddEventToStatFile("im", "im_call_finish", $this->id, ($recorded ? "Y" : "N"), "recorded", 0);
if($chatType)
{
AddEventToStatFile("im","im_call_finish", $this->id, $chatType, "chat_type", 0);
}
if (isset($isVideoConf))
{
AddEventToStatFile("im","im_call_finish", $this->id, ($isVideoConf ? "Y" : "N"), "is_videoconf", 0);
}
AddEventToStatFile("im","im_call_finish", $this->id, $finishStatus, "status", 0);
}