Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
topichandler.php
1<?php
3
5
6if (Loader::includeModule('replica'))
7{
8 class TopicHandler extends \Bitrix\Replica\Client\BaseHandler
9 {
10 protected $tasksForumId = 0;
11
12 protected $tableName = "b_forum_topic";
13 protected $moduleId = "forum";
14
15 protected $primary = array(
16 "ID" => "auto_increment",
17 );
18 protected $predicates = array(
19 );
20 protected $translation = array(
21 "ID" => "b_forum_topic.ID",
22 "USER_START_ID" => "b_user.ID",
23 "LAST_POSTER_ID" => "b_user.ID",
24 //"LAST_MESSAGE_ID" => "b_forum_message.ID", //TODO
25 "ABS_LAST_POSTER_ID" => "b_user.ID",
26 //"ABS_LAST_MESSAGE_ID" => "b_forum_message.ID", //TODO
27 "RESPONSIBLE_ID" => "b_user.ID",
28 "OWNER_ID" => "b_user.ID",
29 );
30 protected $children = array(
31 "ID" => "b_forum_message.TOPIC_ID",
32 );
33
38 public function __construct()
39 {
40 if (\Bitrix\Main\Loader::includeModule('tasks'))
41 {
42 $this->tasksForumId = (int)\CTasksTools::GetForumIdForIntranet();
43 }
44 }
45
55 public function onAfterTopicAdd($id, &$data)
56 {
57 \Bitrix\Replica\Db\Operation::writeInsert($this->tableName, array('ID'), array('ID' => $id));
58 }
59
70 public function onAfterTopicUpdate($id, $newTopic, $oldTopic)
71 {
72 \Bitrix\Replica\Db\Operation::writeUpdate($this->tableName, array('ID'), array('ID' => $id));
73 }
74
84 public function onAfterTopicDelete(&$id, $topic)
85 {
86 \Bitrix\Replica\Db\Operation::writeDelete($this->tableName, array('ID'), array('ID' => $id));
87 }
88
98 public function beforeInsertTrigger(array &$newRecord)
99 {
100 unset($newRecord["SOCNET_GROUP_ID"]);
101 if ($this->tasksForumId > 0 && $newRecord['FORUM_ID'] === 'tasks_forum')
102 {
103 $newRecord['FORUM_ID'] = $this->tasksForumId;
104 if (preg_match("/^TASK_(.+)\$/", $newRecord["XML_ID"], $match))
105 {
106 $mapper = \Bitrix\Replica\Mapper::getInstance();
107 $taskId = $mapper->resolveLogGuid(false, 'b_tasks.ID', $match[1]);
108 if ($taskId)
109 {
110 $newRecord['XML_ID'] = 'TASK_'.$taskId;
111 }
112 }
113 }
114 return null;
115 }
116
125 public function beforeUpdateTrigger(array $oldRecord, array &$newRecord)
126 {
127 unset($newRecord["SOCNET_GROUP_ID"]);
128
129 if ($this->tasksForumId > 0 && $newRecord['FORUM_ID'] === 'tasks_forum')
130 {
131 $newRecord['FORUM_ID'] = $this->tasksForumId;
132 if (preg_match("/^TASK_(.+)\$/", $newRecord["XML_ID"], $match))
133 {
134 $mapper = \Bitrix\Replica\Mapper::getInstance();
135 $taskId = $mapper->resolveLogGuid(false, 'b_tasks.ID', $match[1]);
136 if ($taskId)
137 {
138 $newRecord['XML_ID'] = 'TASK_'.$taskId;
139 }
140 }
141 }
142 }
143
151 public function beforeLogInsert(array $record)
152 {
153 if ($this->tasksForumId > 0 && $record['FORUM_ID'] == $this->tasksForumId)
154 {
155 return true;
156 }
157 else
158 {
159 return false;
160 }
161 }
162
170 public function beforeLogFormat(array &$record)
171 {
172 if ($this->tasksForumId > 0 && $record['FORUM_ID'] == $this->tasksForumId)
173 {
174 $record['FORUM_ID'] = 'tasks_forum';
175 if (preg_match("/^TASK_([0-9]+)\$/", $record["XML_ID"], $match))
176 {
177 $mapper = \Bitrix\Replica\Mapper::getInstance();
178 $guid = $mapper->getLogGuid("b_tasks.ID", $match[1]);
179 if ($guid)
180 $record['XML_ID'] = 'TASK_'.$guid;
181 }
182 }
183 }
184 }
185}