コード例 #1
0
ファイル: FileService.php プロジェクト: nyeholt/relapse
 /**
  * Get all the items in a given path. If it is a directory,
  * a string value is entered. If it is a file, a File object
  * is entered.
  * 
  * ArrayObject(
  * 	0 => 'string',
  *  1 => File{}
  *  2 => 'etc'
  * )
  *
  * @param string $path
  * @return ArrayObject
  */
 public function listDirectory($path)
 {
     // Get all the directories
     $list = new ArrayObject();
     $listFrom = $this->fileRoot . $this->normalizePath($path);
     try {
         $dir = new DirectoryIterator($listFrom);
     } catch (Exception $e) {
         return $list;
     }
     foreach ($dir as $entry) {
         /* @var $entry DirectoryIterator */
         if ($entry->isDot()) {
             continue;
         }
         if (is_dir($this->fileRoot . $this->normalizePath($path) . DIRECTORY_SEPARATOR . $entry->getFilename())) {
             $list->append($entry->getFilename());
         }
     }
     $conditions = array('path' => $this->normalizePath($path));
     if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) {
         $conditions = array('isprivate' => 0);
     }
     $results = $this->dbService->getManyByFields($conditions, 'File');
     foreach ($results as $file) {
         $list->append($file);
     }
     return $list;
 }