/** * Save filter, requirement fields: IBLOCK_ID, FILTER * * @param array $fields * @return \Bitrix\Main\Entity\AddResult * @throws \InvalidArgumentException */ public function addFilter(array $fields) { $filter = $fields['FILTER']; if (!is_array($filter) || sizeof($filter) <= 0) { throw new \InvalidArgumentException('Filter can not be empty'); } $filter = $this->normalizeFilter($filter); $iblockId = (int) $fields['IBLOCK_ID']; $sectionId = (int) $fields['SECTION_ID']; $queryBuilder = new Entity\Query(Iblock\IblockTable::getEntity()); $iblockDataResult = $queryBuilder->setSelect(array('ID'))->setFilter(array('ID' => $iblockId))->exec()->fetch(); if ($this->isEmptyResult($iblockDataResult)) { throw new \InvalidArgumentException('Invalid IBLOCK_ID'); } if ($sectionId > 0) { $queryBuilder = new Entity\Query(Iblock\SectionTable::getEntity()); $sectionDataResult = $queryBuilder->setSelect(array('ID'))->setFilter(array('IBLOCK_ID' => $iblockDataResult['ID'], 'ID' => $sectionId))->exec()->fetch(); if ($this->isEmptyResult($sectionDataResult)) { throw new \InvalidArgumentException('Invalid SECTION_ID'); } } $queryBuilder = new Entity\Query(Model\SubscribeTable::getEntity()); $subscribe = $queryBuilder->setSelect(array('ID'))->setFilter(array('FILTER' => $filter, 'IBLOCK_ID' => $iblockDataResult['ID'], 'SECTION_ID' => isset($sectionDataResult) ? $sectionDataResult['ID'] : ''))->exec()->fetch(); if (!empty($subscribe)) { $addResult = new \Bitrix\Main\Entity\AddResult(); $addResult->setId($subscribe['ID']); return $addResult; } $subscribeResult = Model\SubscribeTable::add(array('FILTER' => $filter, 'IBLOCK_ID' => $iblockDataResult['ID'], 'SECTION_ID' => isset($sectionDataResult) ? $sectionDataResult['ID'] : '')); return $subscribeResult; }
/** * @inheritdoc */ public function create(ParameterDictionary $parameters) { $iblockId = (int) $parameters->get('ID'); $queryBuilder = new Entity\Query(Iblock\IblockTable::getEntity()); $iblockData = $queryBuilder->setSelect(array('ID', 'NAME'))->setFilter(array('ID' => $iblockId))->setOrder(array())->exec()->fetch(); if (empty($iblockData)) { throw new BuilderException(sprintf('Not found iblock with id = %d', $iblockId)); } // Get settings iblock $iblockDataFields = \CIBlock::GetArrayByID($iblockData['ID']); $queryBuilder = new Entity\Query(Iblock\PropertyTable::getEntity()); $propertyResult = $queryBuilder->setSelect(array('*'))->setFilter(array('IBLOCK_ID' => $iblockData['ID']))->setOrder(array())->exec(); $propertyList = array(); while ($property = $propertyResult->fetch()) { if (!empty($property['USER_TYPE_SETTINGS'])) { $property['USER_TYPE_SETTINGS'] = ($unserialize = @unserialize($property['USER_TYPE_SETTINGS'])) === false ? $property['USER_TYPE_SETTINGS'] : $unserialize; } $propertyList[$property['CODE']] = $property; } $this->iblockProperty = $propertyList; $this->setElementValue(); $this->setSectionValue(); $this->setEnumValue(); $sectionValueList = array(); if (in_array($iblockData['ID'], $this->getListByType('G'))) { foreach ($this->iblockProperty as $field) { if ($field['PROPERTY_TYPE'] == 'G' && $field['LINK_IBLOCK_ID'] == $iblockData['ID']) { $sectionValueList = isset($field['VALUE_LIST']) ? $field['VALUE_LIST'] : array(); break; } } } else { $queryBuilder = new Entity\Query(Iblock\SectionTable::getEntity()); $sectionValueList = $queryBuilder->setSelect(array('ID', 'NAME'))->setFilter(array('IBLOCK_ID' => $iblockData['ID']))->setOrder(array())->exec()->fetchAll(); } $upperLevel[] = array('ID' => 0, 'NAME' => GetMessage('IBLOCK_UPPER_LEVEL')); $sectionValueList = $upperLevel + $sectionValueList; return array('DATA' => $iblockData, 'DEFAULT_FIELDS' => $this->getDefaultFields($iblockDataFields, $sectionValueList), 'FIELDS' => $this->iblockProperty); }
$filterLexer->parse(); $arResult['FILTER'] = $filterLexer->getFilter(); $arResult['FILTER_PROPERTY'] = $filterLexer->getProperty(); $arResult['FILTER_PRICE_TYPE'] = $filterLexer->getPriceType(); $arResult['FILTER_VALUE'] = $filterLexer->getValue(); } if (array_key_exists('SECTION_ID', $arResult)) { $queryBuilder = new Entity\Query(IBlock\SectionTable::getEntity()); $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();
$navyParams = CDBResult::GetNavParams(CAdminResult::GetNavSize($sTableID, array('nPageSize' => 20, 'sNavID' => $APPLICATION->GetCurPage()))); if ($navyParams['SHOW_ALL']) { $usePageNavigation = false; } else { $navyParams['PAGEN'] = (int) $navyParams['PAGEN']; $navyParams['SIZEN'] = (int) $navyParams['SIZEN']; } } $getListParams = array('select' => array('ID', 'NAME', 'PROPERTY_INDEX', 'ACTIVE'), 'filter' => $iblockFilter, 'order' => array($by => $order)); unset($iblockFilter); if ($usePageNavigation) { $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } if ($usePageNavigation) { $countQuery = new Main\Entity\Query(\Bitrix\Iblock\IblockTable::getEntity()); $countQuery->addSelect(new Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($getListParams['filter']); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); unset($countQuery); $totalCount = (int) $totalCount['CNT']; if ($totalCount > 0) { $totalPages = ceil($totalCount / $navyParams['SIZEN']); if ($navyParams['PAGEN'] > $totalPages) { $navyParams['PAGEN'] = $totalPages; } $getListParams['limit'] = $navyParams['SIZEN']; $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1); } else { $navyParams['PAGEN'] = 1; $getListParams['limit'] = $navyParams['SIZEN'];