private function formatFileToResponse(File $file) { if (empty($file) || !$file->getName()) { return array(); } $path = $this->getBreadcrumbs($file); if (!$path) { return array(); } $result = array('id' => $this->generateId(array('FILE' => true, 'ID' => $file->getId())), 'isDirectory' => false, 'isDeleted' => false, 'storageId' => $this->getStringStorageId(), 'path' => '/' . trim($path, '/'), 'name' => (string) $file->getName(), 'revision' => $file->getFileId(), 'version' => (string) $this->generateTimestamp($file->getUpdateTime()->getTimestamp()), 'extra' => array('id' => (string) $file->getId(), 'iblockId' => (string) $file->getStorageId(), 'sectionId' => (string) $file->getParentId(), 'rootSectionId' => (string) $this->storage->getRootObjectId(), 'name' => (string) $file->getName()), 'size' => (string) $file->getSize(), 'permission' => 'W', 'createdBy' => (string) $file->getCreatedBy(), 'modifiedBy' => (string) $file->getUpdatedBy()); if ($this->storage->getRootObjectId() != $file->getParentId()) { $result['parentId'] = $this->generateId(array('FILE' => false, 'ID' => $file->getParentId())); } return $result; }
private function resolvePath(Storage $storage, $path, $lookUpFromFolderId, $lastPart = FolderTable::TYPE_FOLDER) { Diag::getInstance()->collectDebugInfo('urlmanager'); $path = trim($path, '/'); $relativeItems = array(); if ($path == 'index.php' || !$path) { if ($lastPart == FolderTable::TYPE_FILE) { return null; } //by default we show root folder. return array('STORAGE' => $storage, 'OBJECT_ID' => $storage->getRootObjectId(), 'RELATIVE_PATH' => '/', 'RELATIVE_ITEMS' => array()); } $filter = array('TYPE' => FolderTable::TYPE_FOLDER, 'STORAGE_ID' => $storage->getId()); if ($lookUpFromFolderId !== null) { $filter['PARENT_ID'] = $lookUpFromFolderId; } $partsOfPath = explode('/', $path); if (end($partsOfPath) == 'index.php') { array_pop($partsOfPath); } foreach ($partsOfPath as $i => $pieceOfPath) { if ($i === count($partsOfPath) - 1) { if ($lastPart !== null) { $filter['TYPE'] = $lastPart; } else { unset($filter['TYPE']); } } $filter['=NAME'] = $pieceOfPath; $folder = ObjectTable::getList(array('filter' => $filter, 'select' => array('ID', 'NAME', 'REAL_OBJECT_ID', 'STORAGE_ID', 'PARENT_ID')))->fetch(); if (!$folder) { return null; } if ($folder['REAL_OBJECT_ID']) { $filter['PARENT_ID'] = $folder['REAL_OBJECT_ID']; unset($filter['STORAGE_ID']); } else { $filter['PARENT_ID'] = $folder['ID']; $filter['STORAGE_ID'] = $folder['STORAGE_ID']; } $lookUpFromFolderId = $folder['ID']; $relativeItems[] = array('ID' => $folder['ID'], 'NAME' => $pieceOfPath); } unset($pieceOfPath); Diag::getInstance()->logDebugInfo('urlmanager'); return array('STORAGE' => $storage, 'OBJECT_ID' => $lookUpFromFolderId, 'RELATIVE_PATH' => implode('/', $partsOfPath), 'RELATIVE_ITEMS' => $relativeItems); }