/** * Simple logic. * @param array $sectionData * @return array */ private function getOwnerBySection(array $sectionData) { //shared docs if ($sectionData['IBLOCK_TYPE'] == 'shared_files' && !empty($sectionData['SECTION_ID']) && !empty($sectionData['CREATED_BY'])) { $user = \Bitrix\Main\UserTable::getById($sectionData['CREATED_BY'])->fetch(); return empty($user) ? array() : $this->reformatUserRow($user); } $row = \Bitrix\Webdav\FolderInviteTable::getList(array('select' => array('*', 'USER'), 'limit' => 1, 'filter' => array('=IBLOCK_ID' => $sectionData['IBLOCK_ID'], '=SECTION_ID' => $sectionData['SECTION_ID'])))->fetch(); return empty($row) ? array() : $this->reformatInviteRow($row); }
private function getDataSymlinkSections() { global $USER; $invitesQuery = \Bitrix\Webdav\FolderInviteTable::getList(array('filter' => array('INVITE_USER_ID' => $USER->getId(), 'IS_APPROVED' => true, 'IS_DELETED' => false))); $symlinkSections = array(); while ($invite = $invitesQuery->fetch()) { $symlinkSections[$invite['LINK_SECTION_ID']] = $invite; } return $symlinkSections; }
} } $selfSharedSections = $sectionsIds = $dataNavResults = array(); while ($res = $arResult["NAV_RESULT"]->Fetch()) { $dataNavResults[] = $res; if ($res["TYPE"] == "S") { $sectionsIds[] = $res['ID']; } } if ($sectionsIds) { //todo optimize! $filter = array('SECTION_ID' => $sectionsIds); if ($currentIblockCode && $currentIblockCode == 'shared_files') { $filter['USER_ID'] = $USER->getId(); } $querySelfSharedSections = \Bitrix\Webdav\FolderInviteTable::getList(array('filter' => $filter, 'select' => array('ID', 'SECTION_ID', 'IBLOCK_ID'))); while ($folderInvite = $querySelfSharedSections->fetch()) { $selfSharedSections[$folderInvite['SECTION_ID']] = $folderInvite; } unset($folderInvite); } foreach ($dataNavResults as $res) { if (isset($res["~NAME"]) && $res["~NAME"] === $ob->meta_names['TRASH']['name']) { continue; } if ($res["TYPE"] == "S") { if (!empty($res[CWebDavIblock::UF_LINK_SECTION_ID])) { $res['LINK'] = array('SECTION_ID' => $res[CWebDavIblock::UF_LINK_SECTION_ID], 'IBLOCK_ID' => $res[CWebDavIblock::UF_LINK_IBLOCK_ID], 'CAN_FORWARD' => $res[CWebDavIblock::UF_LINK_CAN_FORWARD]); } if ($res["TYPE"] == "S" && isset($selfSharedSections[$res['ID']])) { $res['SHARED_SECTION'] = array('SECTION_ID' => $selfSharedSections['SECTION_ID'], 'IBLOCK_ID' => $selfSharedSections['IBLOCK_ID'], 'USER_ID' => $selfSharedSections['USER_ID']);
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; }
public function processActionDelete(array $params) { $this->enableIgnoreQuotaError(); $this->checkRequiredParams($params, array('id', 'version', 'extra', 'storageExtra', 'storageId')); //isDirectory $id = $params['id']; $version = $params['version']; $isDirectory = (bool) $params['isDirectory']; $lastVersion = null; $isDirectory = (bool) $isDirectory; $storage = $this->getStorageObject($params['storageExtra'], $params['storageId']); $extra = $storage->parseElementExtra($params['extra']); $element = $isDirectory ? $storage->getDirectory($id, $extra) : $storage->getFile($id, $extra); //todo check invite, if file under symlink if ($element && $extra['inSymlink']) { $chain = CWebDavSymlinkHelper::getNavChain($element['extra']['iblockId'], $element['extra']['sectionId']); $sectionIds = array(); foreach ($chain as $item) { $sectionIds[] = $item['ID']; } unset($item, $chain); //has current user invite on this section? $query = \Bitrix\Webdav\FolderInviteTable::getList(array('select' => array('ID'), 'filter' => array('INVITE_USER_ID' => $this->getUser()->getId(), 'IS_APPROVED' => true, 'IS_DELETED' => false, 'SECTION_ID' => $sectionIds))); $row = $query->fetch(); if (!isset($row['ID'])) { return $this->sendResponse(array('status' => static::STATUS_NOT_FOUND, 'message' => 'Link detached')); } } if ($element) { if ($storage::compareVersion($element['version'], $version) > 0) { $element['status'] = static::STATUS_OLD_VERSION; return $this->sendResponse($element); } $lastVersion = $isDirectory ? $storage->deleteDirectory($element) : $storage->deleteFile($element); } else { $lastVersion = $storage->getVersionDelete(array('id' => $id, 'version' => $version, 'isDirectory' => $isDirectory, 'extra' => $extra)); } if ((bool) $lastVersion) { CWebDavTools::runEvent($isDirectory ? static::ON_AFTER_DISK_FOLDER_DELETE : static::ON_AFTER_DISK_FILE_DELETE, array($element['extra']['id'], $element)); return $this->sendSuccess(array('version' => $this->convertToExternalVersion((string) $lastVersion))); } return $this->sendResponse(array('status' => static::STATUS_NOT_FOUND)); }