1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
EntityChat.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Chat;
4
5use Bitrix\Im\Model\ChatTable;
6use Bitrix\Im\Model\RelationTable;
7use Bitrix\Im\V2\Chat;
8use Bitrix\Im\V2\Result;
9use Bitrix\Im\V2\Service\Context;
10use Bitrix\Main\Localization\Loc;
11
12class EntityChat extends GroupChat
13{
14 protected const ENTITY_SEPARATOR = '|';
15
16 protected const ENTITY_MAP_FIELDS = ['entityId', 'entityData1', 'entityData2', 'entityData3'];
17
18 protected $entityMap = [
19 'entityId' => [],
20 'entityData1' => [],
21 'entityData2' => [],
22 'entityData3' => [],
23 ];
24
25 protected $entityData = [];
26
27 public function setEntityMap(array $entityMap): self
28 {
29 foreach ($entityMap as $field => $map)
30 {
31 if (in_array($field, self::ENTITY_MAP_FIELDS, true) && is_array($map))
32 {
33 $this->entityMap[$field] = array_values($map);
34 }
35 }
36
37 return $this;
38 }
39
40 public function getEntityMap(): array
41 {
42 return $this->entityMap;
43 }
44
49 public function getEntityData(bool $force = false): array
50 {
51 if (!count($this->entityData) || $force)
52 {
53 $this->entityData = $this->unmapEntity();
54 }
55
56 return $this->entityData;
57 }
58
59 private function unmapEntity(): array
60 {
61 $result = [];
62 foreach ($this->getEntityMap() as $entityType => $entityFields)
63 {
64 if (!count($entityFields))
65 {
66 continue;
67 }
68
69 if ($this->$entityType)
70 {
71 $data = explode(self::ENTITY_SEPARATOR, $this->$entityType);
72 if (count($entityFields) === count($data))
73 {
74 $result[$entityType] = array_combine($entityFields, $data);
75 }
76 else
77 {
78 $result[$entityType] = $data;
79 }
80 }
81 else
82 {
83 $result[$entityType] = array_fill_keys($entityFields, null);
84 }
85 }
86 return $result;
87 }
88
99 public static function find(array $params = [], ?Context $context = null): Result
100 {
101 $result = new Result;
102
103 if (empty($params['ENTITY_TYPE']) || empty($params['ENTITY_ID']))
104 {
105 return $result->addError(new ChatError(ChatError::WRONG_PARAMETER));
106 }
107
108 $row = ChatTable::query()
109 ->setSelect(['ID', 'TYPE', 'ENTITY_TYPE', 'ENTITY_ID'])
110 ->where('ENTITY_TYPE', $params['ENTITY_TYPE'])
111 ->where('ENTITY_ID', $params['ENTITY_ID'])
112 ->fetch()
113 ;
114
115 if ($row)
116 {
117 $result->setResult([
118 'ID' => (int)$row['ID'],
119 'TYPE' => $row['TYPE'],
120 'ENTITY_TYPE' => $row['ENTITY_TYPE'],
121 'ENTITY_ID' => $row['ENTITY_ID'],
122 ]);
123 }
124
125 return $result;
126 }
127}
const WRONG_PARAMETER
Определения ChatError.php:12
static find(array $params=[], ?Context $context=null)
Определения EntityChat.php:99
setEntityMap(array $entityMap)
Определения EntityChat.php:27
const ENTITY_MAP_FIELDS
Определения EntityChat.php:16
const ENTITY_SEPARATOR
Определения EntityChat.php:14
getEntityData(bool $force=false)
Определения EntityChat.php:49
Определения result.php:20
fetch(\Bitrix\Main\Text\Converter $converter=null)
Определения result.php:179
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$context
Определения csv_new_setup.php:223
$map
Определения config.php:5
Определения culture.php:9
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799