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; }
public static function Delete($ID) { if (!CModule::IncludeModule('iblock')) { return false; } $section = new CIBlockSection(); $dbResult = $section->GetList(array(), array('ID' => $ID, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('IBLOCK_ID'), false); $currentFields = $dbResult ? $dbResult->Fetch() : null; if (!(is_array($currentFields) && CCrmCatalog::Exists(intval($currentFields['IBLOCK_ID'])))) { self::$LAST_ERROR_CODE = self::ERR_SECTION_NOT_FOUND; self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_NOT_FOUND'); return false; } if (self::isIncludesUsedProducts($currentFields['IBLOCK_ID'], $ID)) { // Section includes used products self::$LAST_ERROR_CODE = self::ERR_SECTION_INCLUDES_USED_PRODUCTS; self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_SECTION_INCLUDES_USED_PRODUCTS'); return false; } $result = $section->Delete($ID, false); if ($result === false) { self::$LAST_ERROR_CODE = self::ERR_IBLOCK_SECTION_DELETE; self::$LAST_ERROR = $section->LAST_ERROR; } return $result !== false; }
protected function innerDelete($ID, &$errors) { if (!CCrmProduct::CheckDeletePermission($ID)) { $errors[] = 'Access denied.'; return false; } $result = CCrmProductSection::Delete($ID); if ($result !== true) { $errors[] = CCrmProductSection::GetLastError(); } return $result; }
if ($rsSections->Fetch()) { $section = new CIBlockSection(); $section->Update($renamedSectionID, array('IBLOCK_ID' => $catalogID, 'NAME' => $newSectionName)); if (!isset($_GET['AJAX_CALL'])) { LocalRedirect($arResult['SECTION_LIST_URL']); } } } } $gridActionName = 'action_button_' . $arResult['GRID_ID']; $gridAction = isset($_POST[$gridActionName]) ? $_POST[$gridActionName] : ''; if ($gridAction === 'delete' && $arResult['CAN_DELETE']) { $arIDs = isset($_POST['ID']) && is_array($_POST['ID']) ? $_POST['ID'] : array(); if (!empty($arIDs)) { $dbSection = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $catalogID, 'ID' => $arIDs, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('ID')); $section = new CCrmProductSection(); while ($arSection = $dbSection->Fetch()) { $section->Delete($arSection['ID']); } } if (!isset($_GET['AJAX_CALL'])) { LocalRedirect($arResult['SECTION_LIST_URL']); } } elseif ($gridAction === 'edit' && $arResult['CAN_EDIT']) { $section = new CIBlockSection(); $arFields = isset($_POST['FIELDS']) && is_array($_POST['FIELDS']) ? $_POST['FIELDS'] : array(); $arIDs = array_keys($arFields); if (!empty($arIDs)) { $dbSection = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $catalogID, 'ID' => $arIDs, 'GLOBAL_ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, array('ID')); $section = new CIBlockSection(); while ($arSection = $dbSection->Fetch()) {
} else { if ($elementType === 'S') { $result = CCrmProductSection::Delete($ID) || CCrmProductSection::GetLastErrorCode() === CCrmProductSection::ERR_SECTION_NOT_FOUND; } } if ($result) { $DB->Commit(); } else { if ($errorMessage !== '') { $errorMessage .= '<br />'; } if ($elementType === 'P') { $errorMessage .= CCrmProduct::GetLastError(); } else { if ($elementType === 'S') { $errorMessage .= CCrmProductSection::GetLastError(); } } $DB->Rollback(); } } } if (strlen($errorMessage) > 0) { $errorID = uniqid('crm_err_'); $_SESSION[$errorID] = $errorMessage; LocalRedirect(CHTTP::urlAddParams($APPLICATION->GetCurPage(), array('error' => $errorID))); } if (!$actionData['AJAX_CALL']) { LocalRedirect($bInternal ? '?' . $arParams['FORM_ID'] . '_active_tab=tab_product' : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_LIST'], array('section_id' => $sectionID))); } }