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