- Модуль: disk
- Путь к файлу: ~/bitrix/modules/disk/lib/uf/controller.php
- Класс: BitrixDiskUfController
- Вызов: Controller::processActionLoadItems
protected function processActionLoadItems()
{
$this->checkRequiredPostParams(array(
'FORM_TAB_TYPE', 'FORM_TAB_ID', 'FORM_PATH',
));
if($this->errorCollection->hasErrors())
{
$this->sendJsonErrorResponse();
}
$dialogName = $this->request->getPost('FORM_NAME') ?: 'DiskFileDialog';
$typeStorage = mb_strtolower($this->request->getPost('FORM_TAB_TYPE'));
if(!in_array($typeStorage, array('user', 'common', 'group', 'cloud', 'recently_used'), true))
{
$this->errorCollection->add(array(new Error("Invalid storage type {$typeStorage}")));
$this->sendJsonErrorResponse();
}
$storageId = (int)$this->request->getPost('FORM_TAB_ID');
$path = $this->request->getPost('FORM_PATH');
$storage = null;
if($typeStorage === 'recently_used')
{
$this->sendJsonSuccessResponse(array(
'FORM_NAME' => $dialogName,
'FORM_ITEMS' => Driver::getInstance()->getRecentlyUsedManager()->getFileListByUser($this->getUser()->getId()),
'FORM_ITEMS_DISABLED' => array(),
'FORM_PATH' => $path,
'FORM_IBLOCK_ID' => 0,
));
}
elseif($typeStorage === 'cloud')
{
$documentHandlersManager = Driver::getInstance()->getDocumentHandlersManager();
$documentHandler = $documentHandlersManager->getHandlerByCode($this->request->getQuery('service'));
if(!$documentHandler)
{
$this->errorCollection->add($documentHandlersManager->getErrors());
$this->sendJsonErrorResponse();
}
if (!($documentHandler instanceof CloudImportInterface))
{
$this->errorCollection[] = new Error("Document handler {{$documentHandler::getCode()}} does not implement " . CloudImportInterface::class);
$this->sendJsonErrorResponse();
}
if(!$documentHandler->checkAccessibleTokenService())
{
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_CONTROLLER_ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE_B24', array('#NAME#' => $documentHandler::getName())), self::ERROR_COULD_NOT_WORK_WITH_TOKEN_SERVICE)));
$this->errorCollection->add($documentHandler->getErrors());
$this->sendJsonErrorResponse();
}
if(!$documentHandler->queryAccessToken()->hasAccessToken() || $documentHandler->isRequiredAuthorization())
{
$this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener'));
}
$itemsCloud = $this->listItemsCloud($documentHandler, $path);
if($itemsCloud === null && $documentHandler->isRequiredAuthorization())
{
$this->sendNeedAuth($documentHandler->getUrlForAuthorizeInTokenService('opener'));
}
$this->sendJsonSuccessResponse(array(
'sortMode' => InternalsGridFolderListOptions::SORT_MODE_ORDINARY,
'FORM_NAME' => $dialogName,
'FORM_ITEMS' => $itemsCloud,
'FORM_ITEMS_DISABLED' => array(),
'FORM_PATH' => $path,
'FORM_IBLOCK_ID' => 0,
));
}
else
{
$storage = $this->getStorageByType($typeStorage, $storageId);
}
if(!$storage)
{
$this->errorCollection->add(array(new Error('Could not find storage for current user')));
$this->sendJsonErrorResponse();
}
$options = new InternalsGridFolderListOptions($storage);
$this->sendJsonSuccessResponse(array(
'sortMode' => $options->getSortMode(),
'FORM_NAME' => $dialogName,
'FORM_ITEMS' => $this->listItems($storage, $path),
'FORM_ITEMS_DISABLED' => array(),
'FORM_PATH' => $path,
'FORM_IBLOCK_ID' => 0,
));
}