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

getDirectoryId() public method

Get a directory ID, should it exist.
public getDirectoryId ( array $parts, string $cabin ) : integer
$parts array
$cabin string
return integer
    public function getDirectoryId(array $parts, string $cabin) : int
    {
        $part = \array_shift($parts);
        $parent = $this->db->cell('SELECT
                 directoryid
             FROM
                 airship_dirs
             WHERE
                     parent IS NULL
                 AND name = ?
                 AND cabin = ?', $part, $cabin);
        if (empty($parent)) {
            throw new FileNotFound();
        }
        foreach ($parts as $part) {
            $parent = $this->db->cell('SELECT
                     *
                 FROM
                     airship_dirs
                 WHERE
                         name = ?
                     AND parent = ?
                     AND cabin = ?', $part, $parent, $cabin);
            if (empty($parent)) {
                throw new FileNotFound();
            }
        }
        return $parent;
    }

Usage Example

Esempio n. 1
0
 /**
  * Reduce code duplication
  *
  * @param string $path
  * @param string $cabin
  * @return array (array $publicPath, int|null $root)
  */
 protected function loadCommonData(string $path, string $cabin) : array
 {
     if (!$this->permCheck()) {
         \Airship\redirect($this->airship_cabin_prefix);
     }
     $root = null;
     $publicPath = \Airship\chunk($path);
     $pathInfo = $this->getPath($path);
     if (!empty($pathInfo)) {
         try {
             $root = $this->files->getDirectoryId($pathInfo, $cabin);
         } catch (FileNotFound $ex) {
             \Airship\redirect($this->airship_cabin_prefix);
         }
     }
     // return [$pathInfo, $publicPath, $root];
     return [$publicPath, $root];
 }