Ejemplo n.º 1
0
 public static function notify($arParams, $n, $server)
 {
     global $USER;
     $arParams = array_change_key_case($arParams, CASE_UPPER);
     if (!isset($arParams['TYPE']) || !in_array($arParams['TYPE'], array('USER', 'SYSTEM'))) {
         $arParams['TYPE'] = 'USER';
     }
     if ($arParams['TYPE'] == 'SYSTEM') {
         $result = \CBitrix24App::getList(array(), array('APP_ID' => $server->getAppId()));
         $result = $result->fetch();
         $moduleName = isset($result['APP_NAME']) ? $result['APP_NAME'] : $result['CODE'];
         $fromUserId = 0;
         $notifyType = IM_NOTIFY_SYSTEM;
         $message = $moduleName . "#BR#" . $arParams['MESSAGE'];
     } else {
         $fromUserId = $USER->GetID();
         $notifyType = IM_NOTIFY_FROM;
         $message = $arParams['MESSAGE'];
     }
     $message = trim($message);
     if (strlen($message) <= 0) {
         return false;
     }
     $arMessageFields = array("TO_USER_ID" => $arParams['TO'], "FROM_USER_ID" => $fromUserId, "NOTIFY_TYPE" => $notifyType, "NOTIFY_MODULE" => "rest", "NOTIFY_EVENT" => "rest_notify", "NOTIFY_MESSAGE" => $message);
     return CIMNotify::Add($arMessageFields);
 }
Ejemplo n.º 2
0
 /**
  * Returns storage for current application.
  * @return Disk\Storage|null
  * @throws RestException
  */
 protected function getForApp()
 {
     $driver = Disk\Driver::getInstance();
     $appData = \CBitrix24App::getList(array(), array('APP_ID' => $this->restServer->getAppId()))->fetch();
     if (!$appData || empty($appData['ID']) || empty($appData['CODE'])) {
         throw new RestException('Could not find application by app_id.', RestException::ERROR_NOT_FOUND);
     }
     $storage = $driver->getStorageByRestApp($appData['ID']);
     if (!$storage) {
         $storage = $driver->addRestAppStorage(array('ENTITY_ID' => $appData['ID'], 'NAME' => $appData['CODE']));
         if (!$storage) {
             $this->errorCollection->add($driver->getErrors());
             return null;
         }
     }
     return $storage;
 }
Ejemplo n.º 3
0
 /**
  * @param $server
  * @return array|bool|false|mixed|null
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\LoaderException
  */
 private static function getApp($server)
 {
     if (self::$app == null) {
         if (Loader::includeModule('bitrix24')) {
             $result = \CBitrix24App::getList(array(), array('APP_ID' => $server->getAppId()));
             self::$app = $result->fetch();
         } elseif (Loader::includeModule('oauth')) {
             $result = ClientTable::getList(array('filter' => array('=CLIENT_ID' => $server->getAppId())));
             self::$app = $result->fetch();
             if (is_array(self::$app) && is_array(self::$app['SCOPE'])) {
                 self::$app['SCOPE'] = implode(',', self::$app['SCOPE']);
             }
         }
     }
     return self::$app;
 }