function onExecuteStartWriting(\Bitrix\Main\Event $event)
 {
     $parameters = $event->getParameters();
     $userId = $parameters[0];
     $dialogId = $parameters[1] . $parameters[2];
     if ($userId > 0) {
         if (!\Bitrix\Main\Loader::includeModule('pull')) {
             return;
         }
         \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
         if (intval($dialogId) > 0) {
             \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
         } elseif (substr($dialogId, 0, 4) == 'chat') {
             $chatId = substr($dialogId, 4);
             $arRelation = \CIMChat::GetRelationById($chatId);
             unset($arRelation[$userId]);
             $pullMessage = array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId));
             \CPullStack::AddByUsers(array_keys($arRelation), $pullMessage);
             $orm = \Bitrix\Im\ChatTable::getById($chatId);
             $chat = $orm->fetch();
             if ($chat['TYPE'] == IM_MESSAGE_OPEN) {
                 \CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessage);
             }
         }
     }
 }
 /**
  * @param \Bitrix\Main\Event $event
  * @return mixed
  */
 public static function handleEvent(Event $event)
 {
     $eventData = $event->getParameters();
     $eventData = $eventData[0];
     $eventName = $eventData['EVENT_NAME'];
     $fields = is_array($eventData['C_FIELDS']) ? $eventData['C_FIELDS'] : array();
     if (static::isPreventable($eventName, $fields)) {
         // error
         $result = new EventResult(EventResult::ERROR);
     } else {
         // success
         $result = new EventResult(EventResult::SUCCESS);
     }
     return $result;
 }
Beispiel #3
0
 public function onStartUserReplication(\Bitrix\Main\Event $event)
 {
     $parameters = $event->getParameters();
     $userId = $parameters[0];
     $domain = $parameters[2];
     $domainId = getNameByDomain($domain);
     if (!$domainId) {
         return;
     }
     $mapper = \Bitrix\Replica\Mapper::getInstance();
     $map = $mapper->getByPrimaryValue("b_user.ID", false, $userId);
     if (!$map) {
         return;
     }
     $guid = key($map);
     $event = array("operation" => "im_status_bind", "guid" => $guid);
     \Bitrix\Replica\Log\Client::getInstance()->write(array($domainId), $event);
     \Bitrix\Replica\Mapper::getInstance()->add("b_im_status.USER_ID", $userId, $domainId, $event["guid"]);
 }
 function onExecuteStartWriting(\Bitrix\Main\Event $event)
 {
     $parameters = $event->getParameters();
     $userId = $parameters[0];
     $dialogId = $parameters[1] . $parameters[2];
     if ($userId > 0) {
         if (!\Bitrix\Main\Loader::includeModule('pull')) {
             return;
         }
         \CPushManager::DeleteFromQueueBySubTag($userId, 'IM_MESS');
         if (intval($dialogId) > 0) {
             \CPullStack::AddByUser($dialogId, array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
         } elseif (substr($dialogId, 0, 4) == 'chat') {
             $arRelation = \CIMChat::GetRelationById(substr($dialogId, 4));
             foreach ($arRelation as $rel) {
                 if ($rel['USER_ID'] == $userId) {
                     continue;
                 }
                 \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'startWriting', 'expiry' => 60, 'params' => array('senderId' => $userId, 'dialogId' => $dialogId)));
             }
         }
     }
 }
 /**
  * @param Main\Event $event
  *
  * @return Main\EventResult
  */
 public static function onBasketItemChange(Main\Event $event)
 {
     $parameters = $event->getParameters();
     /** @var Sale\BasketItem $basketItem */
     $basketItem = $parameters[0];
     if (!$basketItem instanceof Sale\BasketItem) {
         return new Main\EventResult(Main\EventResult::ERROR, new Sale\ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_COMPATIBILITY_BASKET_ITEM_CHANGE_WRONG_BASKET'), 'SALE_EVENT_COMPATIBILITY_BASKET_ITEM_CHANGE_WRONG_BASKET'), 'sale');
     }
     $currentBasketFields = $basketFields = BasketCompatibility::convertBasketItemToArray($basketItem);
     if ($basketItem->getId() == 0) {
         foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_BEFORE_BASKET_ITEM_ADD, true) as $oldEvent) {
             if (ExecuteModuleEventEx($oldEvent, array(&$basketFields)) === false) {
                 continue;
             }
         }
     } else {
         foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_BEFORE_BASKET_ITEM_UPDATE, true) as $oldEvent) {
             if (ExecuteModuleEventEx($oldEvent, array($basketItem->getId(), &$basketFields)) === false) {
                 continue;
             }
         }
     }
     foreach ($currentBasketFields as $key => $value) {
         if (isset($basketFields[$key]) && $basketFields[$key] != $value) {
             $basketItem->setFieldNoDemand($key, $basketFields[$key]);
         }
     }
     return new Main\EventResult(Main\EventResult::SUCCESS, null, 'sale');
 }
Beispiel #6
0
 private function sendToEventHandler(array $handler, Event $event)
 {
     try {
         $result = true;
         $event->addDebugInfo($handler);
         if (isset($handler["TO_MODULE_ID"]) && !empty($handler["TO_MODULE_ID"]) && $handler["TO_MODULE_ID"] != 'main') {
             $result = Loader::includeModule($handler["TO_MODULE_ID"]);
         } elseif (isset($handler["TO_PATH"]) && !empty($handler["TO_PATH"])) {
             $path = ltrim($handler["TO_PATH"], "/");
             if (($path = Loader::getLocal($path)) !== false) {
                 $result = (include_once $path);
             }
         } elseif (isset($handler["FULL_PATH"]) && !empty($handler["FULL_PATH"]) && IO\File::isFileExists($handler["FULL_PATH"])) {
             $result = (include_once $handler["FULL_PATH"]);
         }
         $event->addDebugInfo($result);
         if (isset($handler["TO_METHOD_ARG"]) && is_array($handler["TO_METHOD_ARG"]) && !empty($handler["TO_METHOD_ARG"])) {
             $args = $handler["TO_METHOD_ARG"];
         } else {
             $args = array();
         }
         if ($handler["VERSION"] > 1) {
             $args[] = $event;
         } else {
             $args = array_merge($args, array_values($event->getParameters()));
         }
         $callback = null;
         if (isset($handler["CALLBACK"])) {
             $callback = $handler["CALLBACK"];
         } elseif (!empty($handler["TO_CLASS"]) && !empty($handler["TO_METHOD"]) && class_exists($handler["TO_CLASS"])) {
             $callback = array($handler["TO_CLASS"], $handler["TO_METHOD"]);
         }
         if ($callback != null) {
             $result = call_user_func_array($callback, $args);
         }
         if ($result != null && !$result instanceof EventResult) {
             $result = new EventResult(EventResult::UNDEFINED, $result, $handler["TO_MODULE_ID"]);
         }
         $event->addDebugInfo($result);
         if ($result != null) {
             $event->addResult($result);
         }
     } catch (\Exception $ex) {
         if ($event->isDebugOn()) {
             $event->addException($ex);
         } else {
             throw $ex;
         }
     }
 }
 /**
  * @param Main\Event $event
  *
  * @return Main\EventResult
  * @throws Main\ObjectNotFoundException
  */
 public static function onSaleBeforeStatusOrderChange(Main\Event $event)
 {
     $parameters = $event->getParameters();
     /** @var Sale\Order $basketItem */
     $order = $parameters['ENTITY'];
     $value = $parameters['VALUE'];
     $oldValue = $parameters['OLD_VALUE'];
     if (!$order instanceof Sale\Order) {
         return new Main\EventResult(Main\EventResult::ERROR, new Sale\ResultError(Main\Localization\Loc::getMessage('SALE_EVENT_COMPATIBILITY_BEFORE_ORDER_STATUS_CHANGE_WRONG_ORDER'), 'SALE_EVENT_COMPATIBILITY_BEFORE_ORDER_STATUS_CHANGE_WRONG_ORDER'), 'sale');
     }
     foreach (GetModuleEvents("sale", static::EVENT_COMPATIBILITY_ON_BEFORE_ORDER_STATUS_CHANGE, true) as $oldEvent) {
         ExecuteModuleEventEx($oldEvent, array($order->getId(), $value));
     }
     return new Main\EventResult(Main\EventResult::SUCCESS, null, 'sale');
 }