Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.74 KB | None | 0 0
  1. public static function getBrandTreeBySectionID($currentSectionId = "0")
  2.     {
  3.         $arBrandTree = ['BRAND' => [], 'GAMMA' => [], 'LINE' => [], 'TYPE' => ''];
  4.  
  5.         if (empty($currentSectionId))
  6.         {
  7.             return $arBrandTree;
  8.         }
  9.  
  10.         $brandsTreeDictionary = new Dictionary();
  11.  
  12.         $cacheId = 'brandsTreeDictionary_' . self::CATALOG_IBLOCK_ID;
  13.         $cacheDir = 'tagged_brands_tree';
  14.         $cache = Cache::createInstance();
  15.  
  16.         if ($cache->initCache(14400, $cacheId, $cacheDir))
  17.         {
  18.             $brandsTreeDictionary->set($cache->getVars());
  19.         }
  20.         elseif ($cache->startDataCache())
  21.         {
  22.             $rCatalogSections = CIBlockSection::GetList([
  23.                 'IBLOCK_ID' => self::CATALOG_IBLOCK_ID
  24.             ], [
  25.                 'ID',
  26.                 'NAME',
  27.                 'CODE',
  28.                 'XML_ID',
  29.                 'ACTIVE',
  30.                 'SECTION_PAGE_URL',
  31.                 'IBLOCK_SECTION_ID',
  32.                 'DEPTH_LEVEL'
  33.             ]);
  34.  
  35.             global $CACHE_MANAGER;
  36.             $CACHE_MANAGER->StartTagCache($cacheDir);
  37.             while ($arSection = $rCatalogSections->GetNext())
  38.             {
  39.                 $CACHE_MANAGER->RegisterTag("iblock_id_".$arSection["ID"]."_".$arSection["IBLOCK_SECTION_ID"]);
  40.                 $arSection['SECTION_PAGE_URL'] = str_replace('/catalog/', '/brands/', $arSection['SECTION_PAGE_URL']);
  41.                 $brandsTreeDictionary[$arSection['ID']] = $arSection;
  42.             }
  43.             $CACHE_MANAGER->RegisterTag("iblock_id_new");
  44.             $CACHE_MANAGER->EndTagCache();
  45.             $cache->endDataCache($brandsTreeDictionary->toArray());
  46.         }
  47.  
  48.         $arCurrentSection = $brandsTreeDictionary->get($currentSectionId);
  49.  
  50.         switch ($arCurrentSection['DEPTH_LEVEL'])
  51.         {
  52.             case '1':
  53.             {
  54.                 $arBrandTree['TYPE'] = "BRAND";
  55.                 $arBrandTree['GAMMA'] = [];
  56.                 $arBrandTree['LINE'] = [];
  57.                 $arBrandTree['BRAND'] = $arCurrentSection;
  58.  
  59.                 break;
  60.             }
  61.             case '2':
  62.             {
  63.                 $arBrandTree['TYPE'] = "GAMMA";
  64.                 $arBrandTree['LINE'] = [];
  65.                 $arBrandTree['GAMMA'] = $arCurrentSection;
  66.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  67.  
  68.                 break;
  69.             }
  70.             case '3':
  71.             {
  72.                 $arBrandTree['TYPE'] = "LINE";
  73.                 $arBrandTree['LINE'] = $arCurrentSection;
  74.                 $arBrandTree['GAMMA'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  75.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arBrandTree['GAMMA']['IBLOCK_SECTION_ID']);
  76.  
  77.                 break;
  78.             }
  79.         }
  80.  
  81.         return $arBrandTree;
  82.     }public static function getBrandTreeBySectionID($currentSectionId = "0")
  83.     {
  84.         $arBrandTree = ['BRAND' => [], 'GAMMA' => [], 'LINE' => [], 'TYPE' => ''];
  85.  
  86.         if (empty($currentSectionId))
  87.         {
  88.             return $arBrandTree;
  89.         }
  90.  
  91.         $brandsTreeDictionary = new Dictionary();
  92.  
  93.         $cacheId = 'brandsTreeDictionary_' . self::CATALOG_IBLOCK_ID;
  94.         $cacheDir = 'tagged_brands_tree';
  95.         $cache = Cache::createInstance();
  96.  
  97.         if ($cache->initCache(14400, $cacheId, $cacheDir))
  98.         {
  99.             $brandsTreeDictionary->set($cache->getVars());
  100.         }
  101.         elseif ($cache->startDataCache())
  102.         {
  103.             $rCatalogSections = CIBlockSection::GetList([
  104.                 'IBLOCK_ID' => self::CATALOG_IBLOCK_ID
  105.             ], [
  106.                 'ID',
  107.                 'NAME',
  108.                 'CODE',
  109.                 'XML_ID',
  110.                 'ACTIVE',
  111.                 'SECTION_PAGE_URL',
  112.                 'IBLOCK_SECTION_ID',
  113.                 'DEPTH_LEVEL'
  114.             ]);
  115.  
  116.             global $CACHE_MANAGER;
  117.             $CACHE_MANAGER->StartTagCache($cacheDir);
  118.             while ($arSection = $rCatalogSections->GetNext())
  119.             {
  120.                 $CACHE_MANAGER->RegisterTag("iblock_id_".$arSection["ID"]."_".$arSection["IBLOCK_SECTION_ID"]);
  121.                 $arSection['SECTION_PAGE_URL'] = str_replace('/catalog/', '/brands/', $arSection['SECTION_PAGE_URL']);
  122.                 $brandsTreeDictionary[$arSection['ID']] = $arSection;
  123.             }
  124.             $CACHE_MANAGER->RegisterTag("iblock_id_new");
  125.             $CACHE_MANAGER->EndTagCache();
  126.             $cache->endDataCache($brandsTreeDictionary->toArray());
  127.         }
  128.  
  129.         $arCurrentSection = $brandsTreeDictionary->get($currentSectionId);
  130.  
  131.         switch ($arCurrentSection['DEPTH_LEVEL'])
  132.         {
  133.             case '1':
  134.             {
  135.                 $arBrandTree['TYPE'] = "BRAND";
  136.                 $arBrandTree['GAMMA'] = [];
  137.                 $arBrandTree['LINE'] = [];
  138.                 $arBrandTree['BRAND'] = $arCurrentSection;
  139.  
  140.                 break;
  141.             }
  142.             case '2':
  143.             {
  144.                 $arBrandTree['TYPE'] = "GAMMA";
  145.                 $arBrandTree['LINE'] = [];
  146.                 $arBrandTree['GAMMA'] = $arCurrentSection;
  147.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  148.  
  149.                 break;
  150.             }
  151.             case '3':
  152.             {
  153.                 $arBrandTree['TYPE'] = "LINE";
  154.                 $arBrandTree['LINE'] = $arCurrentSection;
  155.                 $arBrandTree['GAMMA'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  156.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arBrandTree['GAMMA']['IBLOCK_SECTION_ID']);
  157.  
  158.                 break;
  159.             }
  160.         }
  161.  
  162.         return $arBrandTree;
  163.     }public static function getBrandTreeBySectionID($currentSectionId = "0")
  164.     {
  165.         $arBrandTree = ['BRAND' => [], 'GAMMA' => [], 'LINE' => [], 'TYPE' => ''];
  166.  
  167.         if (empty($currentSectionId))
  168.         {
  169.             return $arBrandTree;
  170.         }
  171.  
  172.         $brandsTreeDictionary = new Dictionary();
  173.  
  174.         $cacheId = 'brandsTreeDictionary_' . self::CATALOG_IBLOCK_ID;
  175.         $cacheDir = 'tagged_brands_tree';
  176.         $cache = Cache::createInstance();
  177.  
  178.         if ($cache->initCache(14400, $cacheId, $cacheDir))
  179.         {
  180.             $brandsTreeDictionary->set($cache->getVars());
  181.         }
  182.         elseif ($cache->startDataCache())
  183.         {
  184.             $rCatalogSections = CIBlockSection::GetList([
  185.                 'IBLOCK_ID' => self::CATALOG_IBLOCK_ID
  186.             ], [
  187.                 'ID',
  188.                 'NAME',
  189.                 'CODE',
  190.                 'XML_ID',
  191.                 'ACTIVE',
  192.                 'SECTION_PAGE_URL',
  193.                 'IBLOCK_SECTION_ID',
  194.                 'DEPTH_LEVEL'
  195.             ]);
  196.  
  197.             global $CACHE_MANAGER;
  198.             $CACHE_MANAGER->StartTagCache($cacheDir);
  199.             while ($arSection = $rCatalogSections->GetNext())
  200.             {
  201.                 $CACHE_MANAGER->RegisterTag("iblock_id_".$arSection["ID"]."_".$arSection["IBLOCK_SECTION_ID"]);
  202.                 $arSection['SECTION_PAGE_URL'] = str_replace('/catalog/', '/brands/', $arSection['SECTION_PAGE_URL']);
  203.                 $brandsTreeDictionary[$arSection['ID']] = $arSection;
  204.             }
  205.             $CACHE_MANAGER->RegisterTag("iblock_id_new");
  206.             $CACHE_MANAGER->EndTagCache();
  207.             $cache->endDataCache($brandsTreeDictionary->toArray());
  208.         }
  209.  
  210.         $arCurrentSection = $brandsTreeDictionary->get($currentSectionId);
  211.  
  212.         switch ($arCurrentSection['DEPTH_LEVEL'])
  213.         {
  214.             case '1':
  215.             {
  216.                 $arBrandTree['TYPE'] = "BRAND";
  217.                 $arBrandTree['GAMMA'] = [];
  218.                 $arBrandTree['LINE'] = [];
  219.                 $arBrandTree['BRAND'] = $arCurrentSection;
  220.  
  221.                 break;
  222.             }
  223.             case '2':
  224.             {
  225.                 $arBrandTree['TYPE'] = "GAMMA";
  226.                 $arBrandTree['LINE'] = [];
  227.                 $arBrandTree['GAMMA'] = $arCurrentSection;
  228.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  229.  
  230.                 break;
  231.             }
  232.             case '3':
  233.             {
  234.                 $arBrandTree['TYPE'] = "LINE";
  235.                 $arBrandTree['LINE'] = $arCurrentSection;
  236.                 $arBrandTree['GAMMA'] = $brandsTreeDictionary->get($arCurrentSection['IBLOCK_SECTION_ID']);
  237.                 $arBrandTree['BRAND'] = $brandsTreeDictionary->get($arBrandTree['GAMMA']['IBLOCK_SECTION_ID']);
  238.  
  239.                 break;
  240.             }
  241.         }
  242.  
  243.         return $arBrandTree;
  244.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement