ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilExportImportDirectory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 private const PATH_PREFIX = 'export';
31
32 protected function getPathPrefix(): string
33 {
34 return self::PATH_PREFIX;
35 }
36
37 public function hasFilesFor(int $user_id, string $type): bool
38 {
39 return (bool) count($this->getFilesFor($user_id, $type));
40 }
41
42 public function getFilesFor(int $user_id): array
43 {
44 if (!$this->exists()) {
45 return [];
46 }
47 $finder = $this->storage->finder()
48 ->in([$this->getRelativePath()])
49 ->files()
50 ->depth('< 1')
51 ->sortByName();
52 $files = [];
53 foreach ($finder as $file) {
54 $basename = basename($file->getPath());
55 $files[base64_encode($file->getPath())] = $basename;
56 }
57 if ($this->storage->hasDir($this->getRelativePath() . '/' . $user_id)) {
58 $finder = $this->storage->finder()->in([$this->getRelativePath() . '/' . $user_id])
59 ->depth('< 1')
60 ->files()
61 ->sortByName();
62 foreach ($finder as $file) {
63 $basename = basename($file->getPath());
64 $files[base64_encode($file->getPath())] = $basename;
65 }
66 }
67 asort($files);
68 return $files;
69 }
70
71 public function getAbsolutePathForHash(int $user_id, string $type, string $post_hash): string
72 {
73 foreach ($this->getFilesFor($user_id, $type) as $hash => $file) {
74 if (strcmp($hash, $post_hash) === 0) {
75 $file_path = base64_decode($hash);
76 return ilFileUtils::getDataDir() . '/' . base64_decode($hash);
77 }
78 }
79 return '';
80 }
81}
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