1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
norelationpermission.php
См. документацию.
1<?php
2namespace Bitrix\Im\Disk;
3
5use \Bitrix\Main\Type\DateTime,
7
8use \Bitrix\Im\Model\RelationTable;
9
11{
12 const ACCESS_TIME = 86400;
13
14 public static function add($chatId, $userId)
15 {
16 $result = false;
17
18 $rowRelation = RelationTable::getRow([
19 'select' => ['ID'],
20 'filter' => [
21 '=CHAT_ID' => $chatId,
22 '=USER_ID' => $userId
23 ],
24 ]);
25 if (empty($rowRelation))
26 {
28 if ($provider->isCodeAlreadyExists($chatId, $userId))
29 {
30 return $result;
31 }
32
34 {
36 'select' => ['ID'],
37 'filter' => [
38 '=CHAT_ID' => $chatId,
39 '=USER_ID' => $userId
40 ],
41 ]);
42
43 $count = 0;
44 while ($row = $raw->fetch())
45 {
46 $count++;
47
48 if ($count > 1)
49 {
51 }
52 else
53 {
54 $updateRaw = NoRelationPermissionDiskTable::update($row['ID'], [
55 'ACTIVE_TO' => DateTime::createFromTimestamp(time() + self::ACCESS_TIME)
56 ]);
57
58 if ($updateRaw->isSuccess())
59 {
60 $result = true;
61 }
62 }
63 }
64
65 if ($count === 0)
66 {
68 'CHAT_ID' => $chatId,
69 'USER_ID' => $userId,
70 'ACTIVE_TO' => DateTime::createFromTimestamp(time() + self::ACCESS_TIME)
71 ]);
72
73 if ($addRaw->isSuccess())
74 {
75 $result = true;
76 }
77 }
78 }
79 }
80
81 return $result;
82 }
83
84 public static function delete($chatId, $userId, $permissionDisk = true)
85 {
86 $result = false;
87
88 if ($permissionDisk)
89 {
90 $rowRelation = RelationTable::getRow([
91 'select' => ['ID'],
92 'filter' => [
93 '=CHAT_ID' => $chatId,
94 '=USER_ID' => $userId
95 ],
96 ]);
97 if (empty($rowRelation))
98 {
99 if (\CIMDisk::ChangeFolderMembers($chatId, $userId, false))
100 {
101 $result = true;
102 }
103 }
104 }
105
107 'select' => ['ID'],
108 'filter' => ['=CHAT_ID' => $chatId, '=USER_ID' => $userId],
109 ]);
110
111 while ($row = $raw->fetch())
112 {
113 if (NoRelationPermissionDiskTable::delete($row['ID'])->isSuccess())
114 {
115 $result = true;
116 }
117 }
118
119 return $result;
120 }
121
122 public static function cleaningAgent(): string
123 {
125 {
126 return __METHOD__.'();';
127 }
128
130
131 $relationTbl = RelationTable::getTableName();
132 $noRelationPermTbl = NoRelationPermissionDiskTable::getTableName();
133
134 $connection->queryExecute("
135 DELETE
136 FROM
137 {$noRelationPermTbl}
138 WHERE (CHAT_ID, USER_ID) in (
139 select CHAT_ID, USER_ID FROM {$relationTbl}
140 )
141 ");
142
144 'select' => ['CHAT_ID', 'USER_ID'],
145 'filter' => [
146 '<=ACTIVE_TO' => DateTime::createFromTimestamp(time())
147 ]
148 ]);
149 $pseudoRelation = [];
150 while ($row = $result->fetch())
151 {
152 $pseudoRelation[$row['CHAT_ID']][$row['USER_ID']] = $row['USER_ID'];
153 }
154
155 $connection->queryExecute("DELETE FROM {$noRelationPermTbl} WHERE ACTIVE_TO <= now()");
156
157 foreach ($pseudoRelation as $chatId => $userDelete)
158 {
159 \CIMDisk::changeFolderMembers($chatId, $userDelete, false);
160 }
161
162 return __METHOD__.'();';
163 }
164}
$connection
Определения actionsdefinitions.php:38
$count
Определения admin_tab.php:4
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static add($chatId, $userId)
Определения norelationpermission.php:14
static getInstance()
Определения application.php:98
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
static delete($primary)
Определения datamanager.php:1644
static add(array $data)
Определения datamanager.php:877
static update($primary, array $data)
Определения datamanager.php:1256
static ChangeFolderMembers($chatId, $userId, $append=true)
Определения im_disk.php:1974
$result
Определения get_property_values.php:14