Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
calllog.php
1<?php
2
3namespace Bitrix\Im\Call;
4
18
20{
21 const TYPE_NOW = 'now';
22 const TYPE_ALL = 'all';
23 const TYPE_SEARCH = 'search';
24
25 public static function getTypes()
26 {
27 return [
31 ];
32 }
33 public static function get($params = [])
34 {
35 $filterType = in_array($params['TYPE'], self::getTypes(), true)? $params['TYPE']: self::TYPE_ALL;
36 $filterCallId = $params['TYPE'] === self::TYPE_SEARCH? intval($params['CALL_ID']): 0;
37
38 $select = [
39 'ID', 'UUID', 'TYPE', 'INITIATOR_ID', 'PROVIDER', 'STATE', 'LOG_URL',
40 'ENTITY_TYPE', 'ENTITY_ID',
41 'START_DATE', 'END_DATE',
42 'CHAT_TITLE' => 'CHAT.TITLE'
43 ];
44
45 $runtime = [
46 new \Bitrix\Main\Entity\ReferenceField(
47 'CHAT',
48 \Bitrix\Im\Model\ChatTable::class,
49 [
50 "=ref.ID" => "this.CHAT_ID",
51 ],
52 ["join_type"=>"LEFT"]
53 )
54 ];
55
56 $filter = [];
57
58 if ($filterType == self::TYPE_SEARCH)
59 {
60 $filter = [
61 '=ID' => $filterCallId
62 ];
63 }
64 else
65 {
66 if ($filterType == self::TYPE_NOW)
67 {
68 $filter = [
69 '!=STATE' => \Bitrix\Im\Call\Call::STATE_FINISHED
70 ];
71 }
72
73 if ($params['LAST_ID'])
74 {
75 $filter['<ID'] = $params['LAST_ID'];
76 }
77 }
78
79 $result = \Bitrix\Im\Model\CallTable::getList([
80 'select' => $select,
81 'runtime' => $runtime,
82 'filter' => $filter,
83 'order' => ['ID' => 'DESC'],
84 'limit' => '50'
85 ]);
86
87 $list = [];
88 while($row = $result->fetch())
89 {
90 $call = $row;
91
92 if (!$call['CHAT_TITLE'])
93 {
94 $call['CHAT_TITLE'] = User::getInstance($call['INITIATOR_ID'])->getLastName(false);
95
96 if ($call['ENTITY_TYPE'] === 'chat' && !Common::isChatId($call['ENTITY_ID']))
97 {
98 $call['CHAT_TITLE'] .= ' -> '.User::getInstance($call['ENTITY_ID'])->getLastName(false);
99 }
100 else
101 {
102 $call['CHAT_TITLE'] .= ' -> '.ucfirst($call['ENTITY_TYPE']);
103 }
104 }
105
106 $call['DURATION'] = 0;
107 $startDate = $call['START_DATE'] instanceof DateTime? $call['START_DATE']->getTimestamp(): 0;
108 $endDate = $call['END_DATE'] instanceof DateTime? $call['END_DATE']->getTimestamp(): (new DateTime())->getTimestamp();
109
110 $call['DURATION'] = $endDate - $startDate;
111 $call['DURATION_TEXT'] = \CModule::includeModule('voximplant') ? \CVoxImplantHistory::convertDurationToText($call['DURATION']) : $call['DURATION'];
112
113 $call['CONNECTIONS'] = [];
114
115 $list[$row['ID']] = $call;
116 }
117
118 $result = \Bitrix\Im\Model\CallUserTable::getList([
119 'select' => ['CALL_ID', 'USER_ID', 'STATE', 'LAST_SEEN'],
120 'filter' => [
121 '=CALL_ID' => array_keys($list)
122 ],
123 ]);
124
125 while($row = $result->fetch())
126 {
127 $connection = $row;
128
129 $connection['INITIATOR'] = $list[$row['CALL_ID']]['INITIATOR_ID'] === $row['USER_ID'];
130 $connection['USER_NAME'] = User::getInstance($row['USER_ID'])->getFullName(false);
131 $connection['USER_AVATAR'] = User::getInstance($row['USER_ID'])->getAvatar();
132 $connection['USER_COLOR'] = User::getInstance($row['USER_ID'])->getColor();
133
134 if (defined('IM_CALL_LOG_PATH'))
135 {
136 $connection['LOG_URL'] = IM_CALL_LOG_PATH."{$row['CALL_ID']}-{$row['USER_ID']}.txt";
137 }
138 if ($list[$row['CALL_ID']]['PROVIDER'] === Call::PROVIDER_VOXIMPLANT && defined('IM_CALL_STAT_URL'))
139 {
140 $connection['STAT_URL'] = str_replace(
141 [
142 '#callId#',
143 '#userId#',
144 '#tsFrom#',
145 '#tsTo#',
146 ],
147 [
148 $row['CALL_ID'],
149 $row['USER_ID'],
150 $list[$row['CALL_ID']]['START_DATE']->getTimestamp() * 1000,
151 $list[$row['CALL_ID']]['END_DATE']
152 ? $list[$row['CALL_ID']]['END_DATE']->getTimestamp() * 1000
153 : ($list[$row['CALL_ID']]['START_DATE']->getTimestamp() + 7200) * 1000
154 ,
155 ],
156 IM_CALL_STAT_URL
157 );
158 }
159
160 unset($connection['CALL_ID']);
161
162 $list[$row['CALL_ID']]['CONNECTIONS'][] = $connection;
163 }
164
165 return $list;
166 }
167}
168
169
const PROVIDER_VOXIMPLANT
Definition call.php:36
static isChatId($id)
Definition common.php:64
static getInstance($userId=null)
Definition user.php:44