public function ImportSectionArray($arSectionName, $level = 0)
 {
     $sectionID = 0;
     $level = intval($level);
     if (is_array($arSectionName) && $this->iblockModuleIncluded) {
         $nSections = count($arSectionName);
         if ($nSections > 0 && $level < $nSections && $this->catalogID > 0) {
             $curSectionName = trim(strval($arSectionName[$level]));
             if ($curSectionName !== '') {
                 $curSectionHash = md5($curSectionName);
                 $parentSectionID = 0;
                 if ($level > 0) {
                     $parentSectionHash = md5(strval($arSectionName[$level - 1]));
                     if (is_array($this->sectionByNameCache[$level - 1]) && isset($this->sectionByNameCache[$level - 1][$parentSectionHash])) {
                         $parentSectionID = $this->sectionByNameCache[$level - 1][$parentSectionHash];
                     }
                 }
                 if ($parentSectionID > 0 || $level === 0) {
                     $curSectionID = 0;
                     if (is_array($this->sectionByNameCache[$level]) && isset($this->sectionByNameCache[$level][$curSectionHash])) {
                         $curSectionID = $this->sectionByNameCache[$level][$curSectionHash];
                     } else {
                         $dbRes = CIBlockSection::GetTreeList(array('=IBLOCK_ID' => $this->catalogID, '=SECTION_ID' => $parentSectionID, '=NAME' => $curSectionName, '=DEPTH_LEVEL' => $level + 1, 'CHECK_PERMISSIONS' => 'N'), array('ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN'));
                         if ($arRes = $dbRes->Fetch()) {
                             $curSectionID = $this->sectionByNameCache[$level][$curSectionHash] = intval($arRes['ID']);
                         }
                         unset($dbRes, $arRes);
                     }
                     if ($curSectionID === 0) {
                         $arSectionFields = array('CATALOG_ID' => $this->catalogID, 'SECTION_ID' => $parentSectionID, 'NAME' => $curSectionName);
                         $res = CCrmProductSection::Add($arSectionFields);
                         if ($res !== false) {
                             $curSectionID = $this->sectionByNameCache[$level][$curSectionHash] = intval($res);
                         }
                     }
                     if ($level === $nSections - 1) {
                         $sectionID = $curSectionID;
                     } else {
                         $sectionID = $this->ImportSectionArray($arSectionName, $level + 1);
                     }
                 }
             }
         }
     }
     return $sectionID;
 }
Beispiel #2
0
 protected function innerAdd(&$fields, &$errors, array $params = null)
 {
     if (!CCrmProduct::CheckCreatePermission()) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProductSection::Add($fields);
     if (!(is_int($result) && $result > 0)) {
         $errors[] = CCrmProductSection::GetLastError();
     }
     return $result;
 }