ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
InstructionFileManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
29  protected \ilExcInstructionFilesStakeholder $stakeholder;
30  protected \ILIAS\FileUpload\FileUpload $upload;
31  protected int $ass_id;
33 
34  public function __construct(
35  int $ass_id,
38  ) {
39  global $DIC;
40 
41  $this->upload = $DIC->upload();
42 
43  $this->repo = $repo;
44  $this->ass_id = $ass_id;
45  $this->stakeholder = $stakeholder;
46  }
47 
49  {
50  return $this->stakeholder;
51  }
52 
53  public function getCollectionIdString(): string
54  {
55  return $this->repo->getIdStringForAssId($this->ass_id);
56  }
57 
58  public function createCollection(): void
59  {
60  $this->repo->createCollection($this->ass_id);
61  }
62 
63  public function importFromLegacyUpload(array $file_input): void
64  {
65  $this->repo->importFromLegacyUpload(
66  $this->ass_id,
67  $file_input,
68  $this->stakeholder
69  );
70  }
71 
72  public function importFromDirectory(string $dir): void
73  {
74  $this->repo->importFromDirectory(
75  $this->ass_id,
76  $dir,
77  $this->stakeholder
78  );
79  }
80 
81  public function deleteCollection(): void
82  {
83  $this->repo->deleteCollection(
84  $this->ass_id,
85  $this->stakeholder
86  );
87  }
88 
89  public function getCollection(): ?ResourceCollection
90  {
91  return $this->repo->getCollection($this->ass_id);
92  }
93 
94  public function getFiles(): array
95  {
96  if ($this->repo->hasCollection($this->ass_id)) {
97  return array_map(function (ResourceInformation $info): array {
98  return [
99  'rid' => $info->getRid(),
100  'name' => $info->getTitle(),
101  'size' => $info->getSize(),
102  'ctime' => $info->getCreationTimestamp(),
103  'fullpath' => $info->getSrc(),
104  'mime' => $info->getMimeType(), // this is additional to still use the image delivery in class.ilExAssignmentGUI.php:306
105  'order' => 0 // sorting is currently not supported
106  ];
107  }, iterator_to_array($this->repo->getCollectionResourcesInfo($this->ass_id)));
108  } else {
109  $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
110  $storage = new \ilFSWebStorageExercise($exc_id, $this->ass_id);
111  return $storage->getFiles();
112  }
113  }
114 
115  public function deliver(string $full_path, string $file): void
116  {
117  if ($this->repo->hasCollection($this->ass_id)) {
118  $this->repo->deliverFile($this->ass_id, $file);
119  } else {
120  // deliver file
121  \ilFileDelivery::deliverFileLegacy($full_path, $file);
122  exit();
123  }
124  }
125 
126  public function cloneTo(
127  int $to_ass_id
128  ): void {
129  $this->repo->clone($this->ass_id, $to_ass_id);
130  }
131 }
exit
Definition: login.php:29
__construct(int $ass_id, InstructionFileRepository $repo, \ilExcInstructionFilesStakeholder $stakeholder)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
static lookupExerciseId(int $a_ass_id)