ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
InstructionFileRepository.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
29 {
32  protected \ilDBInterface $db;
33 
34  public function __construct(
35  CollectionWrapper $wrapper,
36  \ilDBInterface $db
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 
74  public function getCollection(int $ass_id): ?ResourceCollection
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 getCollectionResourcesInfo(
125  int $ass_id
126  ): \Generator {
127  $collection = $this->getCollection($ass_id);
128  return $this->wrapper->getCollectionResourcesInfo($collection);
129  }
130 
131  public function deleteCollection(
132  int $ass_id,
133  ResourceStakeholder $stakeholder
134  ): void {
135  $rcid = $this->getIdStringForAssId($ass_id);
136  if ($rcid === "") {
137  return;
138  }
139  $this->wrapper->deleteCollectionForIdString(
140  $rcid,
141  $stakeholder
142  );
143  }
144 
145  public function clone(
146  int $from_ass_id,
147  int $to_ass_id
148  ): void {
149  $from_rcid = $this->getIdStringForAssId($from_ass_id);
150  $to_rcid = $this->wrapper->clone($from_rcid);
151  if ($to_rcid !== "") {
152  $this->db->update(
153  "exc_assignment",
154  [
155  "if_rcid" => ["text", $to_rcid]
156  ],
157  [ // where
158  "id" => ["integer", $to_ass_id]
159  ]
160  );
161  }
162  }
163 }
deleteCollection(int $ass_id, ResourceStakeholder $stakeholder)
__construct(CollectionWrapper $wrapper, \ilDBInterface $db)
importFromLegacyUpload(int $ass_id, array $file_input, ResourceStakeholder $stakeholder)
importFromDirectory(int $ass_id, string $dir, ResourceStakeholder $stakeholder)