Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/vote/lib/Integration/Im/ |
Upload File : |
<?php namespace Bitrix\Vote\Integration\Im; use Bitrix\Main\Loader; use Bitrix\Main\Type\DateTime; use Bitrix\Vote\Attach; use Bitrix\Vote\Attachment\ImMessageConnector; use Bitrix\Vote\Attachment\Manager; use Bitrix\Vote\EO_Attach; class ImVoteEventHandler { public static function onDeleteByEntityId(?int $messageId, array $messageFields): void { if ( $messageId <= 0 || empty($messageFields['PARAMS']['COMPONENT_ID']) || !Loader::includeModule('im') || $messageFields['PARAMS']['COMPONENT_ID'] !== ImVote::MESSAGE_COMPONENT_ID ) { return; } $attaches = Manager::loadFromEntity([ '=MODULE_ID' => 'im', '=ENTITY_TYPE' => ImMessageConnector::className(), '=ENTITY_ID' => $messageId, ]); foreach ($attaches as $attach) { $attach->delete(); } } public static function onImMessageAdd(int $messageId, array $messageFields): void { if ( $messageId <= 0 || empty($messageFields['PARAMS']['COMPONENT_ID']) || $messageFields['PARAMS']['COMPONENT_ID'] !== ImVote::MESSAGE_COMPONENT_ID || empty($messageFields['PARAMS']['COMPONENT_PARAMS'][ImVote::MESSAGE_COMPONENT_PARAM_VOTE_ID]) ) { return; } for ($try = 1; $try <= 2; $try++) { $result = (new EO_Attach()) ->setModuleId('im') ->setObjectId($messageFields['PARAMS']['COMPONENT_PARAMS'][ImVote::MESSAGE_COMPONENT_PARAM_VOTE_ID]) ->setEntityId($messageId) ->setEntityType(ImMessageConnector::className()) ->setCreatedBy($messageFields['AUTHOR_ID'] ?? null) ->setCreateTime(new DateTime()) ->setUid(Attach::generateUid()) ->save() ; if ($result->isSuccess()) { break; } } } }