Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pull.php
1<?php
2
4
7
8class Pull
9{
10 public const TAG = 'MESSAGESERVICE';
11 public const COMMAND = 'message_update';
12
13 private static $canUse;
14
15 public static function canUse()
16 {
17 if (static::$canUse === null)
18 {
19 static::$canUse = Loader::includeModule('pull');
20 }
21 return static::$canUse;
22 }
23
24 public static function onMessagesUpdate(array $messages)
25 {
26 if (!static::canUse())
27 {
28 return false;
29 }
30
31 return static::addToStack(
32 self::COMMAND,
33 [
34 'messages' => static::convertData($messages)
35 ]
36 );
37 }
38
44 private static function addToStack($command, array $params)
45 {
46 if (!static::canUse())
47 {
48 return false;
49 }
50
51 return \CPullWatch::addToStack(
52 self::TAG,
53 array(
54 'module_id' => 'messageservice',
55 'command' => $command,
56 'params' => $params,
57 )
58 );
59 }
60
67 private static function convertData(array $messages): array
68 {
69 foreach($messages as $k => $message)
70 {
71 foreach ($message as $field => $value)
72 {
73 if ($value instanceof DateTime)
74 {
75 $messages[$k][$field] = (string)$value;
76 }
77 }
78 }
79
80 return $messages;
81 }
82}
static onMessagesUpdate(array $messages)
Definition pull.php:24