Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
eventmanager.php
1<?php
2
4use \Bitrix\Main\Loader;
6{
7 public static function init()
8 {
9 if (IsModuleInstalled("iblock"))
10 {
11 AddEventHandler("forum", "onAfterMessageAdd", array(__CLASS__, "updateIBlockPropertyAfterAddingMessage"));
12 AddEventHandler("forum", "onMessageModerate", array(__CLASS__, "updateIBlockProperty"));
13 AddEventHandler("forum", "onAfterMessageDelete", array(__CLASS__, "updateIBlockPropertyAfterDeletingMessage"));
14 }
15 AddEventHandler("forum", "onMessageIsIndexed", array(__CLASS__, "onMessageIsIndexed"));
16 }
17
18 public static function updateIBlockPropertyAfterAddingMessage($ID, $arFields, $arTopic = array())
19 {
20 if ($ID > 0 && $arFields["PARAM1"] != "IB" && $arFields["APPROVED"] == "Y")
21 {
22 self::updateIBlockProperty($ID, "SHOW", $arFields, $arTopic);
23 }
24 }
25
26 public static function updateIBlockPropertyAfterDeletingMessage($ID, $arFields)
27 {
28 if ($ID > 0 && $arFields["PARAM1"] != "IB" && $arFields["APPROVED"] == "Y")
29 {
30 self::updateIBlockProperty($ID, "HIDE", $arFields);
31 }
32 }
33
34 public static function updateIBlockProperty($ID, $TYPE, $arMessage, $arTopic = array())
35 {
36 if ($ID > 0 && $arMessage["PARAM1"] != "IB" && IsModuleInstalled("iblock"))
37 {
38 $arTopic = (empty($arTopic) ? \CForumTopic::GetByID($arMessage["TOPIC_ID"]) : $arTopic);
39 if (!empty($arTopic) && $arTopic["XML_ID"] == "IBLOCK_".$arMessage["PARAM2"] && \CModule::IncludeModule("iblock"))
40 {
41 \CIBlockElement::SetPropertyValuesEx($arMessage["PARAM2"], 0, array(
42 "FORUM_MESSAGE_CNT" => array(
43 "VALUE" => \CForumMessage::GetList(array(), array("TOPIC_ID" => $arMessage["TOPIC_ID"], "APPROVED" => "Y", "!PARAM1" => "IB"), true),
44 "DESCRIPTION" => "",
45 )
46 ));
47 }
48 }
49 }
50
58 public static function onMessageIsIndexed($id, array $message, array &$index)
59 {
60 if (!empty($message["PARAM1"]) && !empty($message["PARAM2"]))
61 return false;
62
63 if (isset($message["XML_ID"]) && !empty($message["XML_ID"]))
64 {
65 if (
66 ($protoEntity = Entity::getEntityByXmlId($message["XML_ID"])) &&
67 (!is_null($protoEntity)) &&
68 (empty($protoEntity["moduleId"]) || Loader::includeModule($protoEntity["moduleId"])) &&
69 is_callable(array($protoEntity["className"], "onmessageisindexed"))
70 )
71 {
72 $b = call_user_func_array(
73 array($protoEntity["className"], "onmessageisindexed"),
74 array($id, $message, &$index)
75 );
76 if ($b === false)
77 return false;
78 }
79 }
80 return true;
81 }
82}
static getEntityByXmlId($xmlId="")
Definition entity.php:225
static updateIBlockPropertyAfterDeletingMessage($ID, $arFields)
static onMessageIsIndexed($id, array $message, array &$index)
static updateIBlockProperty($ID, $TYPE, $arMessage, $arTopic=array())
static updateIBlockPropertyAfterAddingMessage($ID, $arFields, $arTopic=array())