本文整理汇总了PHP中CIBlockElementRights::ChangeParents方法的典型用法代码示例。如果您正苦于以下问题:PHP CIBlockElementRights::ChangeParents方法的具体用法?PHP CIBlockElementRights::ChangeParents怎么用?PHP CIBlockElementRights::ChangeParents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIBlockElementRights
的用法示例。
在下文中一共展示了CIBlockElementRights::ChangeParents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SetElementSection
function SetElementSection($ID, $arSections, $bNew = false, $bRightsIBlock = 0, $sectionId = null)
{
global $DB;
$ID = intval($ID);
$min_old_id = null;
$min_new_id = null;
$arToDelete = array();
$arToInsert = array();
if (is_array($arSections)) {
foreach ($arSections as $section_id) {
$section_id = intval($section_id);
if ($section_id > 0) {
if (!isset($min_new_id) || $section_id < $min_new_id) {
$min_new_id = $section_id;
}
$arToInsert[$section_id] = $section_id;
}
}
} else {
$section_id = intval($arSections);
if ($section_id > 0) {
$arToInsert[$section_id] = $section_id;
$min_new_id = $section_id;
}
}
$arOldParents = array();
$arNewParents = $arToInsert;
$bParentsChanged = false;
//Read database
if (!$bNew) {
$rs = $DB->Query("\n\t\t\t\tSELECT * FROM b_iblock_section_element\n\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ID . "\n\t\t\t\tAND ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t", false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
while ($ar = $rs->Fetch()) {
$section_id = intval($ar["IBLOCK_SECTION_ID"]);
$arOldParents[] = $section_id;
if (!isset($min_old_id) || $section_id < $min_old_id) {
$min_old_id = $section_id;
}
if (isset($arToInsert[$section_id])) {
unset($arToInsert[$section_id]);
//This already in DB
} else {
$arToDelete[] = $section_id;
}
}
if (!empty($arToDelete)) {
$bParentsChanged = true;
$DB->Query($s = "\n\t\t\t\t\tDELETE FROM b_iblock_section_element\n\t\t\t\t\tWHERE IBLOCK_ELEMENT_ID = " . $ID . "\n\t\t\t\t\tAND ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t\t\tAND IBLOCK_SECTION_ID in (" . implode(", ", $arToDelete) . ")\n\t\t\t\t", false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
//And this should be deleted
}
}
if (!empty($arToInsert)) {
$bParentsChanged = true;
$DB->Query("\n\t\t\t\tINSERT INTO b_iblock_section_element(IBLOCK_SECTION_ID, IBLOCK_ELEMENT_ID)\n\t\t\t\tSELECT S.ID, E.ID\n\t\t\t\tFROM b_iblock_section S, b_iblock_element E\n\t\t\t\tWHERE S.IBLOCK_ID = E.IBLOCK_ID\n\t\t\t\tAND S.ID IN (" . implode(", ", $arToInsert) . ")\n\t\t\t\tAND E.ID = " . $ID . "\n\t\t\t");
}
if ($bParentsChanged && $bRightsIBlock) {
$obElementRights = new CIBlockElementRights($bRightsIBlock, $ID);
if (empty($arOldParents)) {
$arOldParents[] = 0;
}
if (empty($arNewParents)) {
$arNewParents[] = 0;
}
$obElementRights->ChangeParents($arOldParents, $arNewParents);
}
if ($sectionId !== null || $min_old_id !== $min_new_id) {
CIBlockElement::RecalcSections($ID, $sectionId);
}
return !empty($arToDelete) || !empty($arToInsert);
}