Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
log.php
1<?php
9
17use Exception;
18
36{
37 public static function getTableName(): string
38 {
39 return 'b_sonet_log';
40 }
41
42 public static function getUfId(): string
43 {
44 return 'SONET_LOG';
45 }
46
47 public static function getMap(): array
48 {
49 return [
50 'ID' => [
51 'data_type' => 'integer',
52 'primary' => true,
53 'autocomplete' => true,
54 ],
55 'ENTITY_TYPE' => [
56 'data_type' => 'string',
57 ],
58 'ENTITY_ID' => [
59 'data_type' => 'integer',
60 ],
61 'EVENT_ID' => [
62 'data_type' => 'string',
63 ],
64 'USER_ID' => [
65 'data_type' => 'integer',
66 ],
67 'USER' => [
68 'data_type' => 'Bitrix\Main\UserTable',
69 'reference' => ['=this.USER_ID' => 'ref.ID'],
70 ],
71 'TITLE' => [
72 'data_type' => 'string',
73 ],
74 'MESSAGE' => [
75 'data_type' => 'text',
76 ],
77 'TEXT_MESSAGE' => [
78 'data_type' => 'text',
79 ],
80 'URL' => [
81 'data_type' => 'string',
82 ],
83 'MODULE_ID' => [
84 'data_type' => 'string',
85 ],
86 'PARAMS' => [
87 'data_type' => 'text',
88 ],
89 'SOURCE_ID' => [
90 'data_type' => 'integer',
91 ],
92 'LOG_DATE' => [
93 'data_type' => 'datetime',
94 ],
95 'LOG_UPDATE' => [
96 'data_type' => 'datetime',
97 ],
98 'COMMENTS_COUNT' => [
99 'data_type' => 'integer',
100 ],
101 'TRANSFORM' => [
102 'data_type' => 'boolean',
103 'values' => ['N', 'Y'],
104 ],
105 'INACTIVE' => [
106 'data_type' => 'boolean',
107 'values' => ['N', 'Y'],
108 ],
109 'RATING_TYPE_ID' => [
110 'data_type' => 'string',
111 ],
112 'RATING_ENTITY_ID' => [
113 'data_type' => 'integer',
114 ],
115 ];
116 }
117
121 public static function setInactive($id, $status = true): ORM\Data\UpdateResult
122 {
123 return self::update($id, array(
124 'INACTIVE' => ($status ? 'Y' : 'N')
125 ));
126 }
127
133 public static function onDelete(ORM\Event $event): ORM\EventResult
134 {
135 $result = new ORM\EventResult;
136 $primary = $event->getParameter('primary');
137 $logId = (!empty($primary['ID']) ? (int)$primary['ID'] : 0);
138
139 if ($logId > 0)
140 {
141 $tabletList = [
142 [ '\Bitrix\Socialnetwork\LogCommentTable', 'LOG_ID' ],
143 [ '\Bitrix\Socialnetwork\LogRightTable', 'LOG_ID' ],
144 [ '\Bitrix\Socialnetwork\LogSiteTable', 'LOG_ID' ],
145 [ '\Bitrix\Socialnetwork\LogFavoritesTable', 'LOG_ID' ],
146 [ '\Bitrix\Socialnetwork\LogTagTable', 'LOG_ID' ]
147 ];
148
149 foreach($tabletList as [$tablet, $fieldName])
150 {
152 $collection = $tablet::query()
153 ->where($fieldName, $logId)
154 ->fetchCollection();
155
156 foreach ($collection as $entity)
157 {
158 $entity->delete();
159 }
160 }
161 }
162
163 return $result;
164 }
165
166 public static function onAfterDelete(ORM\Event $event): ORM\EventResult
167 {
168 $result = new ORM\EventResult;
169 $primary = $event->getParameter('primary');
170 $logId = (!empty($primary['ID']) ? (int)$primary['ID'] : 0);
171
172 if ($logId > 0)
173 {
174 LogIndex::deleteIndex(array(
175 'itemType' => LogIndexTable::ITEM_TYPE_LOG,
176 'itemId' => $logId
177 ));
178 }
179
180 return $result;
181 }
182
183 public static function getObjectClass(): string
184 {
185 return Log::class;
186 }
187
188 public static function getCollectionClass(): string
189 {
190 return LogCollection::class;
191 }
192}
static update($primary, array $data)
static onAfterDelete(ORM\Event $event)
Definition log.php:166
static setInactive($id, $status=true)
Definition log.php:121