/** * 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; }
/** * Set values for property with type G(link to section). */ protected function setSectionValue() { $iblockList = $this->getListByType('G'); $queryBuilder = new Entity\Query(Iblock\SectionTable::getEntity()); $queryBuilder->setSelect(array('ID', 'NAME', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'XML_ID'))->setFilter(array('IBLOCK_ID' => $iblockList))->setOrder(array()); $sectionResult = $queryBuilder->exec(); while ($section = $sectionResult->fetch()) { foreach ($this->iblockProperty as &$field) { if ($field['PROPERTY_TYPE'] != 'G') { continue; } if ($field['LINK_IBLOCK_ID'] == $section['IBLOCK_ID']) { $field['VALUE_LIST'][] = $section; } } } }
/** * Set values for fields type iblock_section. */ protected function setSectionValue() { $iblockList = $this->getListByType('iblock_section'); $queryBuilder = new Entity\Query(Iblock\SectionTable::getEntity()); $queryBuilder->setSelect(array('ID', 'NAME', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'XML_ID'))->setFilter(array('IBLOCK_ID' => $iblockList))->setOrder(array()); $sectionResult = $queryBuilder->exec(); while ($section = $sectionResult->fetch()) { foreach ($this->highLoadBlockFields as &$field) { if ($field['USER_TYPE_ID'] != 'iblock_section') { continue; } if ($field['SETTINGS']['IBLOCK_ID'] == $section['IBLOCK_ID']) { $field['VALUE_LIST'][] = $section; } } } }
} } if (array_key_exists('ITEMS', $arResult)) { $filterLexer = new \Citfact\FilterSubscribe\FilterLexer(); foreach ($arResult['ITEMS'] as $key => $filter) { $arResult['ITEMS'][$key]['FILTER_LINK'] = $filterLexer->getFilterUniqId(unserialize($filter['FILTER'])); $filterLexer->addFilter($filter['FILTER'], true); } $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')) {
/** * Gets the value of section * * @param array $id * @return array */ protected function getValueSection($id) { if (sizeof($id) <= 0) { return array(); } $result = array(); $queryBuilder = new Entity\Query(Iblock\SectionTable::getEntity()); $queryBuilder->setSelect(array('*'))->setFilter(array('ID' => $id)); $sectionResult = $queryBuilder->exec(); while ($section = $sectionResult->fetch()) { $result[$section['ID']] = $section; } return $result; }