parent_id == 0) return [$directory->id]; else return array_merge(MyFile::getPathToRoot($directory->parent_id), [$directory->id]); } return []; } public static function getPathToRootString($did) { $a = MyFile::getPathToRoot($did); return (count($a)>0) ? ";" . implode(";", $a) . ";" : ''; } public static function getPathArray($did) { if(!isset($did) || $did==null) return []; $directory = MyFile::find($did); if($directory) { if($directory->parent_id == 0) return [$directory->id => $directory->name]; else return MyFile::getPathArray($directory->parent_id) + [$directory->id => $directory->name]; } return []; } public function getName() { if($this->file_type == 1 && $this->name_org != null) return $this->name_org; else return $this->name; } public function getFileType() { if($this->file_type == 1) return pathinfo($this->name, PATHINFO_EXTENSION); return ''; } public function getPathOrg() { return $this->place_of_the_file . '/' . $this->name; } public function getPathPdf() { if($this->file_type == 1) return $this->place_of_the_file . '/' . pathinfo($this->name, PATHINFO_FILENAME) . '.pdf'; return ''; } public function getReadableName() { if($this->file_type == 1) return pathinfo($this->name_org, PATHINFO_FILENAME) . '.' . pathinfo($this->name, PATHINFO_EXTENSION); return ''; } // public function getFileTypeAttribute($attribute) // { // try{ // $v = $this->getFileTypeOptions()[$attribute]; // } // catch(\Throwable $th){ // $v = "Error"; // } // return $v; // } // public function getFileTypeOptions() // { // return [ // 0 => 'D', // 1 => 'F', // ]; // } }