Поддержка серверов

CSocNetLogRights::Add: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=166147

//    CSocNetLogRights::Add()
//    /bitrix/modules/socialnetwork/classes/general/log_rights.php:6

    public static function Add($LOG_ID, $GROUP_CODE, $bShare = false, $followSet = true)
    {
        global $DB, $CACHE_MANAGER;

        static $logDataCache = array();

        if (is_array($GROUP_CODE))
        {
            foreach($GROUP_CODE as $GROUP_CODE_TMP)
            {
                CSocNetLogRights::Add($LOG_ID, $GROUP_CODE_TMP, $bShare, $followSet);
            }
            return false;
        }
        else
        {
            $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogRightsAdd");
            while ($arEvent = $db_events->Fetch())
            {
                if (ExecuteModuleEventEx($arEvent, array($LOG_ID, $GROUP_CODE)) === false)
                {
                    return false;
                }
            }

            if (!isset($logDataCache[$LOG_ID]))
            {
                $res = LogTable::getList(array(
                    'filter' => array(
                        'ID' => $LOG_ID
                    ),
                    'select' => array('LOG_UPDATE')
                ));
                if ($logEntry = $res->fetch())
                {
                    $logDataCache[$LOG_ID] = $logEntry;
                }
            }

            $fields = array(
                "LOG_ID" => $LOG_ID,
                "GROUP_CODE" => $GROUP_CODE,
            );

            if (
                !empty($logDataCache[$LOG_ID])
                && !empty($logDataCache[$LOG_ID]['LOG_UPDATE'])
                && ($logDataCache[$LOG_ID]['LOG_UPDATE'] instanceof \Bitrix\Main\Type\DateTime)
            )
            {
                $fields['LOG_UPDATE'] = $logDataCache[$LOG_ID]['LOG_UPDATE']->toString();
            }

            $NEW_RIGHT_ID = $DB->add(
                "b_sonet_log_right",
                $fields,
                array(),
                "",
                true // ignore errors
            );

            if ($NEW_RIGHT_ID)
            {
                if (preg_match('/^U(\d+)$/', $GROUP_CODE, $matches))
                {
                    if($followSet)
                    {
                        \Bitrix\Socialnetwork\ComponentHelper::userLogSubscribe(array(
                            'logId' => $LOG_ID,
                            'userId' => $matches[1],
                            'typeList' => array(
                                'FOLLOW',
                            ),
                            'followDate' => 'CURRENT'
                        ));
                    }
                }
                elseif (
                    $bShare
                    && preg_match('/^SG(\d+)$/', $GROUP_CODE, $matches)
                )
                {
                    // get all members who unfollow and set'em unfollow from the date
                    $arUserIDToCheck = array();

                    $rsGroupMembers = CSocNetUserToGroup::GetList(
                        array(),
                        array(
                            "GROUP_ID" => $matches[1],
                            "USER_ACTIVE" => "Y",
                            "<=ROLE" => SONET_ROLES_USER
                        ),
                        false,
                        false,
                        array("USER_ID")
                    );

                    while ($arGroupMembers = $rsGroupMembers->Fetch())
                    {
                        $arUserIDToCheck[] = $arGroupMembers["USER_ID"];
                    }

                    if (!empty($arUserIDToCheck))
                    {
                        $arUserIDFollowDefault = array(
                            "Y" => array(),
                            "N" => array()
                        );
                        $arUserIDAlreadySaved = array();
                        $default_follow_type = COption::GetOptionString("socialnetwork", "follow_default_type", "Y");

                        $rsFollow = CSocNetLogFollow::GetList(
                            array(
                                "USER_ID" => $arUserIDToCheck,
                                "CODE" => "**"
                            ),
                            array("USER_ID", "TYPE")
                        );
                        while($arFollow = $rsFollow->Fetch())
                        {
                            $arUserIDFollowDefault[$arFollow["TYPE"]][] = $arFollow["USER_ID"];
                        }

                        $rsFollow = CSocNetLogFollow::GetList(
                            array(
                                "USER_ID" => $arUserIDToCheck,
                                "CODE" => "L".$LOG_ID
                            ),
                            array("USER_ID")
                        );
                        while($arFollow = $rsFollow->Fetch())
                        {
                            $arUserIDAlreadySaved[] = $arFollow["USER_ID"];
                        }

                        foreach($arUserIDToCheck as $iUserID)
                        {
                            // for them who not followed by default and not already saved follow/unfollow for the log entry
                            if (
                                !in_array($iUserID, $arUserIDAlreadySaved)
                                && (
                                    (
                                        $default_follow_type == "N"
                                        && !in_array($iUserID, $arUserIDFollowDefault["Y"])
                                    )
                                    || (
                                        $default_follow_type == "Y"
                                        && in_array($iUserID, $arUserIDFollowDefault["N"])
                                    )
                                )
                            )
                            {
                                CSocNetLogFollow::Add(
                                    $iUserID,
                                    "L".$LOG_ID,
                                    "N",
                                    ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID)
                                );
                            }
                        }
                    }
                }
            }

            if(defined("BX_COMP_MANAGED_CACHE"))
            {
                $CACHE_MANAGER->ClearByTag("SONET_LOG_".intval($LOG_ID));
            }
            if (\Bitrix\Main\Loader::includeModule('landing'))
            {
                \Bitrix\Socialnetwork\Integration\Landing\Livefeed::onSocNetLogRightsAddHandler($GROUP_CODE);
            }

            return $NEW_RIGHT_ID;
        }
    }

Блог разработчика

9 августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение