Esempio n. 1
0
 function GetSectionsTree($options = array())
 {
     static $dataType = 'SectionsTree';
     if (empty($options['prependPath'])) {
         $options['prependPath'] = '';
     }
     $dataCache = $options;
     $dataCache['IBLOCK_ID'] = $this->IBLOCK_ID;
     $dataCache['ROOT_SECTION_ID'] = empty($this->arRootSection['ID']) ? 0 : $this->arRootSection['ID'];
     $id = md5(serialize($dataCache));
     $sections = $this->_dataCache($dataType . $id);
     if ($sections === false) {
         $arElement = $this->GetObject($options, false, true);
         if ($arElement["not_found"]) {
             $sections = array();
         } else {
             $arFilter = array("IBLOCK_ID" => $this->IBLOCK_ID);
             if (isset($options['not_check_permissions'])) {
                 $arFilter['CHECK_PERMISSIONS'] = 'N';
             }
             $bRootFounded = empty($this->arRootSection) ? true : false;
             if ($arElement["item_id"] > 0 && !empty($arElement["dir_array"])) {
                 $arFilter["LEFT_MARGIN"] = intVal($arElement["dir_array"]["LEFT_MARGIN"]) + 1;
                 $arFilter["RIGHT_MARGIN"] = intVal($arElement["dir_array"]["RIGHT_MARGIN"]) - 1;
             } elseif (!empty($this->arRootSection)) {
                 $arFilter["LEFT_MARGIN"] = intVal($this->arRootSection["LEFT_MARGIN"]) + 1;
                 $arFilter["RIGHT_MARGIN"] = intVal($this->arRootSection["RIGHT_MARGIN"]) - 1;
             }
             if (!empty($arElement["is_dir"]) && $arElement["item_id"]) {
                 list($contextType, $contextEntityId) = $this->getContextData();
                 $sectionData = $this->getSectionDataForLinkAnalyze($arElement["item_id"], $arElement);
                 $iblockId = $sectionData['IBLOCK_ID'];
                 if (CWebDavSymlinkHelper::isLink($contextType, $contextEntityId, $sectionData)) {
                     $arFilter['IBLOCK_ID'] = $iblockId;
                     $symlinkSectionData = CWebDavSymlinkHelper::getLinkData($contextType, $contextEntityId, $sectionData);
                     if (!empty($symlinkSectionData[self::UF_LINK_SECTION_ID]) && $symlinkSectionData['ID'] == $arElement["item_id"]) {
                         $margins = CIBlockSection::GetList(array(), array('ID' => $symlinkSectionData[self::UF_LINK_SECTION_ID], 'IBLOCK_ID' => $symlinkSectionData[self::UF_LINK_IBLOCK_ID], 'CHECK_PERMISSIONS' => 'N'), false, array('LEFT_MARGIN', 'RIGHT_MARGIN', 'IBLOCK_ID'))->fetch();
                         if ($margins) {
                             $arFilter["LEFT_MARGIN"] = intVal($margins["LEFT_MARGIN"]) + 1;
                             $arFilter["RIGHT_MARGIN"] = intVal($margins["RIGHT_MARGIN"]) - 1;
                         }
                     }
                 }
             }
             $arResult = array();
             $db_res = CIBlockSection::GetTreeList($arFilter, array('ID', 'CREATED_BY', 'MODIFIED_BY', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL', 'SOCNET_GROUP_ID', 'IBLOCK_CODE', 'TIMESTAMP_X'));
             // TODO: add e_rights check
             $trashID = $this->GetMetaID('TRASH');
             if ($db_res && ($res = $db_res->Fetch())) {
                 $deep = -1;
                 $arPath = array();
                 $arExclude = array();
                 do {
                     if ($this->MetaNames($res)) {
                         $res["DEPTH_LEVEL"] = intVal($res["DEPTH_LEVEL"]);
                         if (isset($arExclude[(int) $res["IBLOCK_SECTION_ID"]]) || $this->MetaSectionHide($res, !empty($options['NON_DROPPED_SECTION']))) {
                             $arExclude[(int) $res["ID"]] = true;
                         } else {
                             if ($res["DEPTH_LEVEL"] > $deep) {
                                 $deep = $res["DEPTH_LEVEL"];
                                 array_push($arPath, strtolower(htmlspecialcharsbx($res["NAME"])));
                             } elseif ($res["DEPTH_LEVEL"] == $deep) {
                                 array_pop($arPath);
                                 array_push($arPath, strtolower(htmlspecialcharsbx($res["NAME"])));
                             } else {
                                 while ($res["DEPTH_LEVEL"] < $deep) {
                                     array_pop($arPath);
                                     $deep--;
                                 }
                                 array_pop($arPath);
                                 array_push($arPath, strtolower(htmlspecialcharsbx($res["NAME"])));
                             }
                             $res["PATH"] = $options['prependPath'] . implode("/", $arPath);
                             $arResult[$res["ID"]] = $res;
                         }
                     } else {
                         $arExclude[(int) $res["ID"]] = true;
                     }
                 } while ($res = $db_res->Fetch());
             }
             $sections = $arResult;
         }
         $this->_dataCache($dataType . $id, $sections);
     }
     if (!empty($options['setERights'])) {
         $sectionIds = array();
         foreach ($sections as $section) {
             $sectionIds[] = $section['ID'];
         }
         unset($section);
         $sectionRights = $this->GetPermissions('SECTION', $sectionIds);
         foreach ($sections as &$section) {
             if (isset($sectionRights[$section['ID']])) {
                 $section['E_RIGHTS'] = $sectionRights[$section['ID']];
             }
         }
         unset($section);
     }
     global $USER;
     if (!empty($options['SET_IS_SHARED']) && $USER->getId()) {
         $querySelfSharedSections = \Bitrix\Webdav\FolderInviteTable::getList(array('filter' => array('USER_ID' => $USER->getId(), '!=INVITE_USER_ID' => $USER->getId()), 'select' => array('SECTION_ID', 'IBLOCK_ID')));
         while ($folderInvite = $querySelfSharedSections->fetch()) {
             $selfSharedSections[$folderInvite['SECTION_ID']] = $folderInvite;
         }
         unset($folderInvite);
         foreach ($sections as &$section) {
             if (isset($selfSharedSections[$section['ID']])) {
                 $section['IS_SHARED'] = true;
             }
         }
         unset($section);
     }
     return $sections;
 }
Esempio n. 2
0
function WDUFSetAccessToEdit(&$files, $contextEntity)
{
    global $USER;
    if (!is_array($files)) {
        return;
    }
    static $rootDataForCurrentUser = null;
    if ($rootDataForCurrentUser === null && $USER->getId()) {
        $rootDataForCurrentUser = CWebDavIblock::getRootSectionDataForUser($USER->getId());
    }
    $listIdFile = $iBlockCacheID = array();
    foreach ($files as &$file) {
        if (!empty($file['ID']) && !empty($file['NAME'])) {
            if ($USER->getId() && !isset($file['IN_PERSONAL_LIB'])) {
                $file['IN_PERSONAL_LIB'] = !CWebDavSymlinkHelper::isLink(CWebDavSymlinkHelper::ENTITY_TYPE_USER, $USER->getId(), array('ID' => $file['IBLOCK_SECTION_ID'], 'IBLOCK_ID' => $file['IBLOCK_ID']));
                if (!$file['IN_PERSONAL_LIB']) {
                    $file['IN_PERSONAL_LIB'] = (bool) CWebDavSymlinkHelper::getLinkData(CWebDavSymlinkHelper::ENTITY_TYPE_USER, $USER->getId(), array('ID' => $file['IBLOCK_SECTION_ID'], 'IBLOCK_ID' => $file['IBLOCK_ID']));
                }
                if ($file['IN_PERSONAL_LIB']) {
                    $file['EXTERNAL_ID'] = "st{$rootDataForCurrentUser['IBLOCK_ID']}|{$rootDataForCurrentUser['SECTION_ID']}|f{$file['ID']}";
                }
            }
            //file can may editable if in personal lib (local edit) or if office doc - in services
            if (CWebDavEditDocGoogle::isEditable($file['NAME']) || !empty($file['IN_PERSONAL_LIB'])) {
                $listIdFile[$file['ID']] = $file['ID'];
                $iBlockCacheID[] = $file['IBLOCK_ID'];
            }
        }
    }
    unset($file);
    if (empty($listIdFile)) {
        return;
    }
    $obCache = new CPHPCache();
    $cachePath = SITE_ID . "/webdav/inline";
    //user - entity - id of files
    $cacheID = md5('u' . (int) $USER->getId() . '_e' . $contextEntity . '_f' . implode('|', $listIdFile));
    if ($obCache->InitCache(30 * 86400, $cacheID, $cachePath)) {
        $vars = $obCache->GetVars();
        $result = $vars["RESULT"];
    }
    if (empty($result) && $obCache->StartDataCache()) {
        $result = array();
        $rightsByElements = CIBlockElementRights::GetUserOperations($listIdFile);
        foreach ($files as &$file) {
            if (!isset($listIdFile[$file['ID']])) {
                continue;
            }
            if (!empty($rightsByElements[$file['ID']]) && !empty($rightsByElements[$file['ID']]['element_edit'])) {
                $file['EDITABLE'] = true;
                $result[$file['ID']] = $file['ID'];
                continue;
            }
        }
        unset($file);
        global $CACHE_MANAGER;
        $CACHE_MANAGER->StartTagCache($cachePath);
        foreach ($iBlockCacheID as $ibID) {
            $CACHE_MANAGER->RegisterTag("iblock_id_" . $ibID);
        }
        $CACHE_MANAGER->EndTagCache();
        $obCache->EndDataCache(array("RESULT" => $result));
    } else {
        foreach ($files as &$file) {
            if (!isset($listIdFile[$file['ID']])) {
                continue;
            }
            $file['EDITABLE'] = isset($result[$file['ID']]);
        }
    }
}