ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
InstructionFileRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
30{
32 protected \ilDBInterface $db;
33
34 public function __construct(
37 ) {
38 $this->db = $db;
39 $this->wrapper = $wrapper;
40 }
41
42 public function createCollection(int $ass_id): void
43 {
44 $new_id = $this->wrapper->createEmptyCollection();
45 $this->db->update(
46 "exc_assignment",
47 [
48 "if_rcid" => ["text", $new_id]
49 ],
50 [ // where
51 "id" => ["integer", $ass_id]
52 ]
53 );
54 }
55
56 public function getIdStringForAssId(int $ass_id): string
57 {
58 $set = $this->db->queryF(
59 "SELECT if_rcid FROM exc_assignment " .
60 " WHERE id = %s ",
61 ["integer"],
62 [$ass_id]
63 );
64 $rec = $this->db->fetchAssoc($set);
65 return ($rec["if_rcid"] ?? "");
66 }
67
68 public function hasCollection(int $ass_id): bool
69 {
70 $rcid = $this->getIdStringForAssId($ass_id);
71 return ($rcid !== "");
72 }
73
75 {
76 $rcid = $this->getIdStringForAssId($ass_id);
77 if ($rcid !== "") {
78 return $this->wrapper->getCollectionForIdString($rcid);
79 }
80 return null;
81 }
82
83 public function importFromLegacyUpload(
84 int $ass_id,
85 array $file_input,
86 ResourceStakeholder $stakeholder
87 ): void {
88 $collection = $this->getCollection($ass_id);
89 if ($collection) {
90 $this->wrapper->importFilesFromLegacyUploadToCollection(
91 $collection,
92 $file_input,
93 $stakeholder
94 );
95 }
96 }
97
98 public function importFromDirectory(
99 int $ass_id,
100 string $dir,
101 ResourceStakeholder $stakeholder
102 ): void {
103 $collection = $this->getCollection($ass_id);
104 if ($collection) {
105 $this->wrapper->importFilesFromDirectoryToCollection(
106 $collection,
107 $dir,
108 $stakeholder
109 );
110 }
111 }
112
113 public function deliverFile($ass_id, $file): void
114 {
116 foreach ($this->getCollectionResourcesInfo($ass_id) as $info) {
117 if ($file === $info->getTitle()) {
118 $this->wrapper->deliverFile($info->getRid());
119 }
120 }
121 throw new \ilExerciseException("Resource $file not found.");
122 }
123
124 public function getStream(
125 int $ass_id,
126 string $rid
127 ): ?FileStream {
129 foreach ($this->getCollectionResourcesInfo($ass_id) as $info) {
130 if ($rid === $info->getRid()) {
131 return $this->wrapper->stream($info->getRid());
132 }
133 }
134 return null;
135 }
136
138 int $ass_id
139 ): \Generator {
140 $collection = $this->getCollection($ass_id);
141 return $this->wrapper->getCollectionResourcesInfo($collection);
142 }
143
144 public function deleteCollection(
145 int $ass_id,
146 ResourceStakeholder $stakeholder
147 ): void {
148 $rcid = $this->getIdStringForAssId($ass_id);
149 if ($rcid === "") {
150 return;
151 }
152 $this->wrapper->deleteCollectionForIdString(
153 $rcid,
154 $stakeholder
155 );
156 }
157
158 public function clone(
159 int $from_ass_id,
160 int $to_ass_id
161 ): void {
162 $from_rcid = $this->getIdStringForAssId($from_ass_id);
163 $to_rcid = $this->wrapper->clone($from_rcid);
164 if ($to_rcid !== "") {
165 $this->db->update(
166 "exc_assignment",
167 [
168 "if_rcid" => ["text", $to_rcid]
169 ],
170 [ // where
171 "id" => ["integer", $to_ass_id]
172 ]
173 );
174 }
175 }
176}
importFromLegacyUpload(int $ass_id, array $file_input, ResourceStakeholder $stakeholder)
importFromDirectory(int $ass_id, string $dir, ResourceStakeholder $stakeholder)
deleteCollection(int $ass_id, ResourceStakeholder $stakeholder)
$info
Definition: entry_point.php:21
The base interface for all filesystem streams.
Definition: FileStream.php:32
Interface ilDBInterface.