コード例 #1
0
    die;
}
use Bitrix\Main\Application;
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\Loader;
use Bitrix\Main\Entity;
use Citfact\FilterSubscribe\Model\SubscribeUserTable;
Loc::loadMessages(__FILE__);
Loader::includeModule('citfact.filter.subscribe');
$app = Application::getInstance();
$request = $app->getContext()->getRequest();
if (!$GLOBALS['USER']->IsAuthorized()) {
    return;
}
$isAjax = getenv('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
$subscribeManager = new \Citfact\FilterSubscribe\SubscribeManager();
// Check whether there is a user filter
if ($request->getQuery('CHECK_FILTER') && $isAjax) {
    $filterData = $GLOBALS[$arParams['FILTER_NAME']];
    $filterData = $subscribeManager->normalizeFilter($filterData);
    $queryBuilder = new Entity\Query(SubscribeUserTable::getEntity());
    $filter = $queryBuilder->registerRuntimeField('filter', array('data_type' => 'Citfact\\FilterSubscribe\\Model\\SubscribeTable', 'reference' => array('=this.FILTER_ID' => 'ref.ID')))->setSelect(array('*', 'filter'))->setFilter(array('USER_ID' => $GLOBALS['USER']->GetId(), 'filter.FILTER' => $filterData))->setLimit(1)->exec()->fetch();
    $GLOBALS['APPLICATION']->RestartBuffer();
    header('Content-Type: application/json');
    exit(json_encode(array('data' => $filter)));
}
// Saves the current filter,
// If such a filter not already exists
if ($request->getQuery('SAVE_FILTER') && $isAjax) {
    $filterData = $GLOBALS[$arParams['FILTER_NAME']];
    $filterResult = $subscribeManager->addFilter(array('FILTER' => $filterData, 'IBLOCK_ID' => $arParams['IBLOCK_ID'], 'SECTION_ID' => $arParams['SECTION_ID']));
コード例 #2
0
    $queryBuilder->setSelect(array('*'))->setFilter(array('ID' => $arResult['SECTION_ID']));
    $sectionResult = $queryBuilder->exec();
    while ($section = $sectionResult->fetch()) {
        $arResult['SECTIONS'][$section['ID']] = $section;
    }
}
if (array_key_exists('IBLOCKS_ID', $arResult)) {
    $queryBuilder = new Entity\Query(IBlock\IblockTable::getEntity());
    $queryBuilder->setSelect(array('*'))->setFilter(array('ID' => $arResult['IBLOCKS_ID']));
    $iblockResult = $queryBuilder->exec();
    while ($iblock = $iblockResult->fetch()) {
        $arResult['IBLOCKS'][$iblock['ID']] = $iblock;
    }
}
if ($request->isPost() && $arResult['COMPONENT_ID'] == $request->getPost('COMPONENT_ID')) {
    $subscribeManager = new \Citfact\FilterSubscribe\SubscribeManager();
    $response = array();
    if ('DELETE' == $request->getPost('ACTION')) {
        $filterUserId = (int) $request->getPost('ID');
        try {
            $removeResult = $subscribeManager->removeFilterUser($filterUserId);
            $response['success'] = $removeResult->isSuccess();
            $response['errors'] = $removeResult->getErrorMessages();
        } catch (\Exception $e) {
            $response['success'] = false;
            $response['errors'] = $e->getMessage();
        }
    }
    if (getenv('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest') {
        $GLOBALS['APPLICATION']->RestartBuffer();
        header('Content-Type: application/json');