Exemplo n.º 1
1
 /**
  * Gets specific folder in storage by code. If folder does not exist, creates it.
  * @param Storage $storage Target storage.
  * @param string $code Code of specific folder.
  * @return Folder|null|static
  */
 public static function getFolder(Storage $storage, $code)
 {
     $folder = Folder::load(array('=CODE' => $code, 'STORAGE_ID' => $storage->getId()));
     if ($folder) {
         return $folder;
     }
     return static::createFolder($storage, $code);
 }
Exemplo n.º 2
0
 /**
  * @return Storage|null
  */
 public function getRealStorage()
 {
     if (!$this->realStorageId) {
         return null;
     }
     if (isset($this->realStorage) && $this->realStorageId === $this->realStorage->getId()) {
         return $this->realStorage;
     }
     $this->realStorage = Storage::loadById($this->realStorageId);
     return $this->realStorage;
 }
Exemplo n.º 3
0
 /**
  * Returns storage model.
  * @return Storage|null
  */
 public function getStorage()
 {
     if (!$this->storageId) {
         return null;
     }
     if (isset($this->storage) && $this->storageId == $this->storage->getId()) {
         return $this->storage;
     }
     $this->storage = Storage::loadById($this->storageId, array('ROOT_OBJECT'));
     return $this->storage;
 }
Exemplo n.º 4
0
 public function getVersionDelete($element)
 {
     if (empty($element) || !is_array($element)) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", empty element", 11160)));
         return false;
     }
     $v = \Bitrix\Disk\Internals\DeletedLogTable::getList(array('filter' => array('STORAGE_ID' => $this->storage->getId(), 'OBJECT_ID' => $element['extra']['id']), 'order' => array('CREATE_TIME' => 'DESC')))->fetch();
     if ($v) {
         return $v['CREATE_TIME']->getTimestamp();
     }
     $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", find deletedLog", 111601)));
     return false;
 }
Exemplo n.º 5
0
 /**
  * Returns grid id.
  * @return string
  */
 public function getGridId()
 {
     return 'folder_list_' . $this->storage->getId();
 }
Exemplo n.º 6
0
 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);
 }