protected function processActionShowObjectInGrid() { if (!$this->checkRequiredGetParams(array('objectId'))) { $this->sendJsonErrorResponse(); } /** @var Folder|File $object */ $object = BaseObject::loadById((int) $this->request->getQuery('objectId'), array('STORAGE')); if (!$object) { $this->errorCollection->addOne(new Error('Could not find file or folder', self::ERROR_COULD_NOT_FIND_FILE)); $this->sendJsonErrorResponse(); } $storage = $object->getStorage(); $securityContext = $storage->getCurrentUserSecurityContext(); if (!$object->canRead($securityContext)) { $this->errorCollection->addOne(new Error('Could not find file or folder', self::ERROR_COULD_NOT_READ_FILE)); $this->sendJsonErrorResponse(); } $gridOptions = new Internals\Grid\FolderListOptions($storage); $pageSize = $gridOptions->getPageSize(); $parameters = array('select' => array('ID'), 'filter' => array('PARENT_ID' => $object->getParentId(), 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE), 'order' => $gridOptions->getOrderForOrm(), 'limit' => $pageSize); $countQuery = new Query(ObjectTable::getEntity()); $countQuery->addSelect(new ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($parameters['filter']); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); $totalCount = $totalCount['CNT']; $pageCount = ceil($totalCount / $pageSize); $driver = Driver::getInstance(); $finalPage = null; for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) { $fullParameters = $driver->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY')); $fullParameters['offset'] = $pageSize * ($pageNumber - 1); $query = ObjectTable::getList($fullParameters); while ($row = $query->fetch()) { if ($row['ID'] == $object->getId()) { $finalPage = $pageNumber; break; } } if ($finalPage !== null) { break; } } $finalPage = $finalPage ?: 1; $command = $this->request->getQuery('cmd') ?: ''; if ($command) { $command = '!' . $command; } LocalRedirect($driver->getUrlManager()->getPathInListing($object) . "?&pageNumber={$finalPage}#hl-" . $object->getId() . $command); }
public static function GetMaxFileId($chatId) { $maxId = 0; if (!self::Enabled()) { return $maxId; } if (intval($chatId) <= 0) { return $maxId; } $folderModel = self::GetFolderModel($chatId); if (!$folderModel) { return $maxId; } $result = \Bitrix\Disk\Internals\ObjectTable::getList(array('select' => array('MAX_ID'), 'filter' => array('PARENT_ID' => $folderModel->getId(), 'TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FILE), 'runtime' => array('MAX_ID' => array('data_type' => 'integer', 'expression' => array('MAX(ID)'))))); if ($data = $result->fetch()) { $maxId = $data['MAX_ID']; } return intval($maxId); }
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); }
/** * Tells if name is not unique in object. * @param string $name Name. * @param int $underObjectId Id of parent object. * @param null $excludeId Id which will be excluded from query. * @param null &$opponentId Opponent object which has same name. * @return bool * @throws \Bitrix\Main\ArgumentException */ public static function isUniqueName($name, $underObjectId, $excludeId = null, &$opponentId = null) { $opponent = ObjectTable::getList(array('select' => array('ID'), 'filter' => array('!ID' => $excludeId, 'PARENT_ID' => $underObjectId, '=NAME' => $name), 'limit' => 1))->fetch(); if (!$opponent) { return true; } $opponentId = $opponent['ID']; return false; }