ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 public function deleteCurrent(
60 int $ass_id,
61 int $tutor_id,
62 ResourceStakeholder $stakeholder
63 ): void {
64 $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
65 $this->wrapper->deleteResource($rid, $stakeholder);
66 }
67
68 public function importFromUploadResult(
69 int $ass_id,
70 int $tutor_id,
71 UploadResult $result,
72 ResourceStakeholder $stakeholder
73 ): string {
74 $rid = $this->wrapper->importFileFromUploadResult(
75 $result,
76 $stakeholder
77 );
78 if ($rid !== "") {
79 $this->db->replace(
80 "exc_multi_feedback",
81 [
82 "tutor_id" => ["integer", $tutor_id],
83 "ass_id" => ["integer", $ass_id],
84 ],
85 [
86 "zip_rid" => ["text", $rid]
87 ]
88 );
89 }
90 return $rid;
91 }
92
93 public function getFiles(int $ass_id, int $tutor_id, array $valid_members): array
94 {
95 $files = [];
96 $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
97 if ($rid !== "") {
98 $zip = new \ZipArchive();
99 if ($zip->open($this->wrapper->stream($rid)->getMetadata()['uri'], \ZipArchive::RDONLY)) {
100 $cnt = $zip->count();
101 for ($i = 0; $i < $cnt; $i++) {
102 $full_entry = $zip->getNameIndex($i);
103 $main_parts = explode("/", $full_entry);
104 if (count($main_parts) === 3 && trim($main_parts[2]) !== ""
105 && substr($main_parts[2], 0, 1) !== ".") {
106 $dir = $main_parts[1];
107 $file = $main_parts[2];
108 $dir_parts = explode("_", $dir);
109 $user_id = (int) $dir_parts[count($dir_parts) - 1];
110 if (in_array($user_id, $valid_members)) {
111 // read dir of user
113 $files[] = array(
114 "lastname" => $name["lastname"],
115 "firstname" => $name["firstname"],
116 "login" => $name["login"],
117 "user_id" => (int) $name["user_id"],
118 "full_entry" => $full_entry,
119 "file" => $file);
120 }
121 }
122 }
123 $zip->close();
124 }
125 }
126 return $files;
127 }
128
130 int $ass_id,
131 int $tutor_id,
132 string $entry,
133 ResourceCollection $target_collection,
134 ResourceStakeholder $target_stakeholder
135 ): void {
136 $rid = $this->getIdStringForAssAndTutorId($ass_id, $tutor_id);
137 if ($rid !== "") {
138 $this->wrapper->addEntryOfZipResourceToCollection(
139 $rid,
140 $entry,
141 $target_collection,
142 $target_stakeholder
143 );
144 }
145 }
146}
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.