1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Message.php
См. документацию.
1<?php
2
4
12
13class Message extends Controller
14{
15 protected function getDefaultPreFilters()
16 {
17 return array_merge(
18 parent::getDefaultPreFilters(),
19 [
20 new \Bitrix\Rest\Engine\ActionFilter\Scope('im.import'),
21 new \Bitrix\Main\Engine\ActionFilter\Scope(\Bitrix\Main\Engine\ActionFilter\Scope::REST),
22 new \Bitrix\Rest\Engine\ActionFilter\AuthType(\Bitrix\Rest\Engine\ActionFilter\AuthType::APPLICATION)
23 ]
24 );
25 }
26
27 public function addAction(int $chatId, array $messages, CurrentUser $user): ?array
28 {
29 if (count($messages) > 2000)
30 {
31 $this->addError(new MessageError(MessageError::TOO_MANY_MESSAGES));
32
33 return null;
34 }
35
36 $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']);
37 if (!$chat)
38 {
39 $this->addError(new ChatError(ChatError::NOT_FOUND));
40
41 return null;
42 }
43
44 $importService = new ImportService($chat, (int)$user->getId());
45
46 if (!$importService->hasAccess())
47 {
48 $this->addError(new ImportError(ImportError::ACCESS_ERROR));
49
50 return null;
51 }
52
53 $addResult = $importService->addMessages($messages);
54
55 if (!$addResult->isSuccess())
56 {
57 $this->addErrors($addResult->getErrors());
58
59 return null;
60 }
61
62 return $this->convertKeysToCamelCase($addResult->getResult());
63 }
64
65 public function updateAction(array $messages, int $chatId, CurrentUser $user): ?array
66 {
67 if (count($messages) > 2000)
68 {
69 $this->addError(new MessageError(MessageError::TOO_MANY_MESSAGES));
70
71 return null;
72 }
73
74 $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']);
75 if (!$chat)
76 {
77 $this->addError(new ChatError(ChatError::NOT_FOUND));
78
79 return null;
80 }
81
82 $importService = new ImportService($chat, (int)$user->getId());
83
84 if (!$importService->hasAccess())
85 {
86 $this->addError(new ImportError(ImportError::ACCESS_ERROR));
87
88 return null;
89 }
90
91 $updateResult = $importService->updateMessages($messages);
92
93 if (!$updateResult->isSuccess())
94 {
95 $this->addErrors($updateResult->getErrors());
96
97 return null;
98 }
99
100 return $this->convertKeysToCamelCase($updateResult->getResult());
101 }
102}
const NOT_FOUND
Определения ChatError.php:20
updateAction(array $messages, int $chatId, CurrentUser $user)
Определения Message.php:65
addAction(int $chatId, array $messages, CurrentUser $user)
Определения Message.php:27
static getById($id)
Определения datamanager.php:364
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
Определения action.php:3
Определения handlers.php:8
$user
Определения mysql_to_pgsql.php:33
</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
$messages
Определения template.php:8