1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
SyncService.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Sync;
4
5use Bitrix\Im\Model\LogTable;
6use Bitrix\Im\V2\Common\ContextCustomer;
7use Bitrix\Im\V2\Sync\Entity\EntityFactory;
8use Bitrix\Main\Config\Option;
9use Bitrix\Main\Type\DateTime;
10
12{
13 use ContextCustomer;
14
15 private const OFFSET_INTERVAL_IN_SECONDS = 5;
16 private const MODULE_ID = 'im';
17 private const ENABLE_OPTION_NAME = 'sync_logger_enable';
18
19 public static function isEnable(): bool
20 {
21 return Option::get(self::MODULE_ID, self::ENABLE_OPTION_NAME, 'Y') === 'Y';
22 }
23
24 public function getChangesFromDate(DateTime $date, int $limit): array
25 {
26 if (!self::isEnable())
27 {
28 return [];
29 }
30
31 $date = $this->getDateWithOffset($date);
32 $logEntities = LogTable::query()
33 ->setSelect(['ID', 'USER_ID', 'ENTITY_TYPE', 'ENTITY_ID', 'EVENT', 'DATE_CREATE'])
34 ->where('USER_ID', $this->getContext()->getUserId())
35 ->where('DATE_CREATE', '>=', $date)
36 ->setLimit($limit)
37 ->fetchAll()
38 ;
39
40 return $this->formatData($logEntities, $limit);
41 }
42
43 private function getDateWithOffset(DateTime $date): DateTime
44 {
45 $offset = self::OFFSET_INTERVAL_IN_SECONDS;
46 $date->add("- {$offset} seconds");
47
48 return $date;
49 }
50
51 private function formatData(array $logEntities, int $limit): array
52 {
53 $entities = (new EntityFactory())->createEntities(Event::initByArray($logEntities));
54 $rest = $entities->getRestData();
55
56 $rest['hasMore'] = count($logEntities) >= $limit;
57 $rest['lastServerDate'] = $this->getLastServerDate($logEntities);
58
59 return $rest;
60 }
61
62 protected function getLastServerDate(array $logEntities): ?DateTime
63 {
64 $maxDateTime = null;
65 $maxTimestamp = 0;
66 foreach ($logEntities as $logEntity)
67 {
68 $dateCreate = $logEntity['DATE_CREATE'];
69
70 if (!$dateCreate instanceof DateTime)
71 {
72 continue;
73 }
74 if ($dateCreate->getTimestamp() > $maxTimestamp)
75 {
76 $maxTimestamp = $dateCreate->getTimestamp();
77 $maxDateTime = $dateCreate;
78 }
79 }
80
81 return $maxDateTime;
82 }
83}
static initByArray(array $logEntities)
Определения Event.php:64
getLastServerDate(array $logEntities)
Определения SyncService.php:62
static isEnable()
Определения SyncService.php:19
getChangesFromDate(DateTime $date, int $limit)
Определения SyncService.php:24
add($interval)
Определения date.php:145
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
</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