ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
TutorFeedbackZipRepository.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 getIdStringForAssAndTutorId(int $ass_id, int $tutor_id): string
43  {
44  $set = $this->db->queryF(
45  "SELECT zip_rid FROM exc_multi_feedback " .
46  " WHERE ass_id = %s AND tutor_id = %s ",
47  ["integer", "integer"],
48  [$ass_id, $tutor_id]
49  );
50  $rec = $this->db->fetchAssoc($set);
51  return ($rec["zip_rid"] ?? "");
52  }
53 
54  public function hasFile(int $ass_id, int $tutor_id): bool
55  {
56  $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
57  return ($rid !== "");
58  }
59 
60  /*
61  public function deliverFile(int $ass_id): void
62  {
63  $rid = $this->getIdStringForAssId($ass_id);
64  $this->wrapper->deliverFile($rid);
65  }*/
66 
67  public function deleteCurrent(
68  int $ass_id,
69  int $tutor_id,
70  ResourceStakeholder $stakeholder
71  ) {
72  $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
73  $this->wrapper->deleteResource($rid, $stakeholder);
74  }
75 
76  public function importFromUploadResult(
77  int $ass_id,
78  int $tutor_id,
79  UploadResult $result,
80  ResourceStakeholder $stakeholder
81  ): string {
82  $rid = $this->wrapper->importFileFromUploadResult(
83  $result,
84  $stakeholder
85  );
86  if ($rid !== "") {
87  $this->db->replace(
88  "exc_multi_feedback",
89  [
90  "tutor_id" => ["integer", $tutor_id],
91  "ass_id" => ["integer", $ass_id],
92  ],
93  [
94  "zip_rid" => ["text", $rid]
95  ]
96  );
97  }
98  return $rid;
99  }
100 
101  public function getFiles(int $ass_id, int $tutor_id, array $valid_members): array
102  {
103  $files = [];
104  $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
105  if ($rid !== "") {
106  $zip = new \ZipArchive();
107  if ($zip->open($this->wrapper->stream($rid)->getMetadata()['uri'], \ZipArchive::RDONLY)) {
108  $cnt = $zip->count();
109  for ($i = 0; $i < $cnt; $i++) {
110  $full_entry = $zip->getNameIndex($i);
111  $main_parts = explode("/", $full_entry);
112  if (count($main_parts) === 3 && trim($main_parts[2]) !== ""
113  && substr($main_parts[2], 0, 1) !== ".") {
114  $dir = $main_parts[1];
115  $file = $main_parts[2];
116  $dir_parts = explode("_", $dir);
117  $user_id = (int) $dir_parts[count($dir_parts) - 1];
118  if (in_array($user_id, $valid_members)) {
119  // read dir of user
120  $name = \ilObjUser::_lookupName($user_id);
121  $files[] = array(
122  "lastname" => $name["lastname"],
123  "firstname" => $name["firstname"],
124  "login" => $name["login"],
125  "user_id" => (int) $name["user_id"],
126  "full_entry" => $full_entry,
127  "file" => $file);
128  }
129  }
130  }
131  $zip->close();
132  }
133  }
134  return $files;
135  }
136 
137  public function addFileFromZipToCollection(
138  int $ass_id,
139  int $tutor_id,
140  string $entry,
141  ResourceCollection $target_collection,
142  ResourceStakeholder $target_stakeholder
143  ): void {
144  $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
145  if ($rid !== "") {
146  $this->wrapper->addEntryOfZipResourceToCollection(
147  $rid,
148  $entry,
149  $target_collection,
150  $target_stakeholder
151  );
152  }
153  }
154 }
static _lookupName(int $a_user_id)
lookup user name
getFiles(int $ass_id, int $tutor_id, array $valid_members)
importFromUploadResult(int $ass_id, int $tutor_id, UploadResult $result, ResourceStakeholder $stakeholder)
addFileFromZipToCollection(int $ass_id, int $tutor_id, string $entry, ResourceCollection $target_collection, ResourceStakeholder $target_stakeholder)
deleteCurrent(int $ass_id, int $tutor_id, ResourceStakeholder $stakeholder)
__construct(CollectionWrapper $wrapper, \ilDBInterface $db)