Airship\Cabin\Bridge\Blueprint\Files::getDirectoryTree PHP Method

getDirectoryTree() public method

Build a recursive directory tree
public getDirectoryTree ( string $cabin = '', string $rootDir = '', string $ignore = '', string $pieces = '' ) : array
$cabin string
$rootDir string
$ignore string
$pieces string
return array
    public function getDirectoryTree(string $cabin = '', string $rootDir = '', string $ignore = '', string $pieces = '') : array
    {
        if (empty($rootDir)) {
            $children = $this->db->run('SELECT
                     *
                 FROM
                     airship_dirs
                 WHERE
                         parent IS NULL
                     AND cabin = ?
                 ORDER BY name ASC', $cabin);
        } else {
            $children = $this->db->run('SELECT
                     *
                 FROM
                     airship_dirs
                 WHERE
                         parent = ?
                     AND cabin = ?                     
                 ORDER BY name ASC', $this->getDirectoryId(\Airship\chunk($rootDir), $cabin), $cabin);
            $rootDir .= '/';
        }
        if (!empty($pieces)) {
            $pieces .= '/';
        }
        $dirs = [];
        foreach ($children as $child) {
            if (!empty($ignore)) {
                if (\strpos($pieces . $child['name'] . '/', $ignore) !== false) {
                    // We're ignoring this
                    continue;
                }
            }
            $dirs[] = $pieces . $child['name'];
            $subDirs = $this->getDirectoryTree($cabin, $rootDir . $child['name'], $ignore, $pieces . $child['name']);
            foreach ($subDirs as $sub) {
                $dirs[] = $sub;
            }
        }
        return $dirs;
    }

Usage Example

Esempio n. 1
0
 /**
  * Move/rename a file
  *
  * @param string $file
  * @param string $path
  * @param string $cabin
  */
 protected function commonMoveFile(string $file, string $path, string $cabin)
 {
     if (!$this->permCheck()) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     list($publicPath, $root) = $this->loadCommonData($path, $cabin);
     if (empty($root)) {
         $fileInfo = $this->files->getFileInfo($cabin, null, $file);
     } else {
         $fileInfo = $this->files->getFileInfo($cabin, $root, $file);
     }
     $post = $this->post(new MoveFileFilter());
     if (!empty($post)) {
         $this->files->moveFile($fileInfo, $post, $cabin);
         \Airship\redirect($this->airship_cabin_prefix . '/' . $this->path_middle . '/' . $cabin, ['dir' => $path]);
     }
     $this->lens('files/move', ['cabins' => $this->getCabinNamespaces(), 'file' => $fileInfo, 'root_dir' => $this->root_dir, 'all_dirs' => $this->files->getDirectoryTree($cabin, $this->root_dir), 'dir' => $path, 'cabin' => $cabin, 'pathinfo' => $publicPath]);
 }