ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportImportDirectory.php
Go to the documentation of this file.
1<?php
18declare(strict_types=1);
19
21
28{
29 private const PATH_PREFIX = 'export';
30
31 protected function getPathPrefix(): string
32 {
33 return self::PATH_PREFIX;
34 }
35
36 public function hasFilesFor(int $user_id, string $type): bool
37 {
38 return (bool) count($this->getFilesFor($user_id, $type));
39 }
40
41 public function getFilesFor(int $user_id): array
42 {
43 if (!$this->exists()) {
44 return [];
45 }
46 $finder = $this->storage->finder()
47 ->in([$this->getRelativePath()])
48 ->files()
49 ->depth('< 1')
50 ->sortByName();
51 $files = [];
52 foreach ($finder as $file) {
53 $basename = basename($file->getPath());
54 $files[base64_encode($file->getPath())] = $basename;
55 }
56 if ($this->storage->hasDir($this->getRelativePath() . '/' . $user_id)) {
57 $finder = $this->storage->finder()->in([$this->getRelativePath() . '/' . $user_id])
58 ->depth('< 1')
59 ->files()
60 ->sortByName();
61 foreach ($finder as $file) {
62 $basename = basename($file->getPath());
63 $files[base64_encode($file->getPath())] = $basename;
64 }
65 }
66 asort($files);
67 return $files;
68 }
69
70 public function getAbsolutePathForHash(int $user_id, string $type, string $post_hash): string
71 {
72 foreach ($this->getFilesFor($user_id, $type) as $hash => $file) {
73 if (strcmp($hash, $post_hash) === 0) {
74 $file_path = base64_decode($hash);
75 return ilFileUtils::getDataDir() . '/' . base64_decode($hash);
76 }
77 }
78 return '';
79 }
80}
getAbsolutePathForHash(int $user_id, string $type, string $post_hash)
hasFilesFor(int $user_id, string $type)
static getDataDir()
get data directory (outside webspace)
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37