- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/sectionslist.php
- Класс: BitrixSaleTradingPlatformVkSectionsList
- Вызов: SectionsList::getSectionsToMap
public function getSectionsToMap()
{
if (empty($this->mappedAlbums))
{
$this->mappedAlbums = Map::getMappedAlbums($this->exportId);
}
if (empty($this->mappedSections))
{
$this->mappedSections = Map::getMappedSections($this->exportId);
}
$sectionsUnformatted = $this->getListMappedSections();
$sectionsFormatted = array();
// Empty settings = empty result. It's law
if (empty($this->mappedSections))
{
return array();
}
$sections = $this->getSections(true);
$vkCategories = new VkCategories($this->exportId);
$vkCategoriesList = $vkCategories->getList(false);
foreach ($sectionsUnformatted as $sectionUnformatted)
{
$currSection = $sections[$sectionUnformatted["IBLOCK"]][$sectionUnformatted["BX_ID"]];
// processing only not empty sections
// if ($currSection["ELEMENT_CNT"] <= 0)
// continue;
// if first item to this vk-album
if (!array_key_exists($sectionUnformatted["TO_ALBUM"], $sectionsFormatted))
{
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]] = array(
"TO_ALBUM" => $sectionUnformatted["TO_ALBUM"],
"ITEMS" => array(),
"ELEMENT_CNT" => 0,
);
if (array_key_exists($sectionUnformatted["TO_ALBUM"], $this->mappedAlbums))
{
$albumVkId = $this->mappedAlbums[$sectionUnformatted["TO_ALBUM"]]["ALBUM_VK_ID"];
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]]["ALBUM_VK_ID"] = $albumVkId;
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]]["ALBUM_VK_URL"] = $this->createVkAlbumLink($albumVkId);
}
}
// create toAlbum name only from section, then root for this album. Take alias if exist, or just name
if ($sectionUnformatted["TO_ALBUM"] == $sectionUnformatted["BX_ID"])
{
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]]["TO_ALBUM_NAME"] = $sectionUnformatted["TO_ALBUM_ALIAS"] ?
$sectionUnformatted["TO_ALBUM_ALIAS"] :
trim($currSection["NAME"]);
}
// format current item
$vkCategoryName = $vkCategoriesList[$sectionUnformatted["VK_CATEGORY"]]['NAME'];
$sectionName = $currSection["NAME"];
$sectionElementCnt = $currSection["ELEMENT_CNT"];
$item = array(
"BX_ID" => $sectionUnformatted["BX_ID"],
"NAME" => $sectionName,
"VK_CATEGORY_ID" => $sectionUnformatted["VK_CATEGORY"],
"VK_CATEGORY_NAME" => $vkCategoryName,
"ELEMENT_CNT" => $sectionElementCnt,
"IBLOCK" => $sectionUnformatted["IBLOCK"],
"LEFT_MARGIN" => $currSection["LEFT_MARGIN"],
"DEPTH_LEVEL" => $currSection["DEPTH_LEVEL"],
);
if (isset($item["BX_ID"]) && isset($item["IBLOCK"]))
{
$item["SECTION_URL"] = $this->createSectionLink($item["IBLOCK"], $item["BX_ID"]);
}
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]]["ITEMS"][$item["LEFT_MARGIN"]] = $item;
$sectionsFormatted[$sectionUnformatted["TO_ALBUM"]]["ELEMENT_CNT"] += $sectionElementCnt;
}
// sorted sections for each album by level, add tabs to names
$sectionsFormatted = self::sortMapElementItems($sectionsFormatted);
return $sectionsFormatted;
}