ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TutorFeedbackZipManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
28{
29 protected \ilExcTutorFeedbackFileStakeholder $user_feedback_stakeholder;
31 protected \ilExcTutorFeedbackZipStakeholder $stakeholder;
32 protected int $ass_id;
35
36 public function __construct(
41 ) {
42 $this->domain = $domain;
43 $this->repo = $repo->tutorFeedbackZip();
44 $this->stakeholder = $stakeholder;
45 $this->user_feedback_stakeholder = $user_feedback_stakeholder;
46 $this->participant_repo = $repo->tutorFeedbackFile();
47 }
48
49 protected function toAscii(string $filename): string
50 {
51 global $DIC;
52 return (new \ilFileServicesPolicy($DIC->fileServiceSettings()))->ascii($filename);
53 }
54
56 \ilExAssignment $assignment,
58 ): object {
59 $access = $this->domain->access();
60 $exmem = new \ilExerciseMembers($exercise);
61
62 $tmp_file = tmpfile();
63 $tmp_location = stream_get_meta_data($tmp_file)['uri'];
64 $zip = new \ZipArchive();
65 $res = $zip->open($tmp_location, \ZipArchive::OVERWRITE);
66
67 // send and delete the zip file
68 $base_name = trim(str_replace(" ", "_", $assignment->getTitle() . "_" . $assignment->getId()));
69 $base_name = "multi_feedback_" . $this->toAscii($base_name);
70
71 // create subfolders <lastname>_<firstname>_<id> for each participant
72 $mems = $exmem->getMembers();
73
74 $mems = $access->filterUserIdsByRbacOrPositionOfCurrentUser(
75 'edit_submissions_grades',
76 'edit_submissions_grades',
77 $exercise->getRefId(),
78 $mems
79 );
80 foreach ($mems as $mem) {
81 $name = \ilObjUser::_lookupName($mem);
82 $subdir = $name["lastname"] . "_" . $name["firstname"] . "_" . $name["login"] . "_" . $name["user_id"];
83 $subdir = $this->toAscii($subdir);
84 $zip->addEmptyDir($base_name . "/" . $subdir);
85 }
86 $zip->close();
87 $ret = new \StdClass();
88 $ret->content = file_get_contents($tmp_location);
89 $ret->filename = $base_name . ".zip";
90 return $ret;
91 }
92
93 public function importFromUploadResult(
94 int $ass_id,
95 int $tutor_id,
96 UploadResult $result
97 ): string {
98 $this->repo->deleteCurrent($ass_id, $tutor_id, $this->stakeholder);
99 return $this->repo->importFromUploadResult(
100 $ass_id,
101 $tutor_id,
102 $result,
103 $this->stakeholder
104 );
105 }
106
107 public function getFiles(\ilObjExercise $exc, int $ass_id, int $tutor_id): array
108 {
109 $exmem = new \ilExerciseMembers($exc);
110 $mems = $exmem->getMembers();
111
112 return $this->repo->getFiles($ass_id, $tutor_id, $mems);
113 }
114
115 public function getFileMd5(int $user_id, string $filename): string
116 {
117 return md5($user_id . ":" . $filename);
118 }
119
120 public function saveMultiFeedbackFiles(
121 \ilObjExercise $exc,
122 int $ass_id,
123 int $tutor_id,
124 array $file_md5s
125 ) {
126 $notification = $this->domain->notification($exc->getRefId());
127 foreach ($this->getFiles($exc, $ass_id, $tutor_id) as $file) {
128 $user_id = (int) $file["user_id"];
129 $md5 = $this->getFileMd5((int) $file["user_id"], $file["file"]);
130 if (is_array($file_md5s[$user_id] ?? null) && in_array($md5, $file_md5s[$user_id])) {
131 $target_collection = $this->participant_repo->getCollection($ass_id, $user_id);
132 if ($target_collection) {
133 $this->repo->addFileFromZipToCollection(
134 $ass_id,
135 $tutor_id,
136 $file["full_entry"],
137 $target_collection,
138 $this->user_feedback_stakeholder
139 );
140 }
141
142 $ass = new \ilExAssignment($ass_id);
143 $submission = new \ilExSubmission($ass, $user_id);
144 $feedback_id = $submission->getFeedbackId();
145 $noti_rec_ids = $submission->getUserIds();
146
147 if ($feedback_id) {
148 if ($noti_rec_ids) {
149 foreach ($noti_rec_ids as $user_id) {
150 $member_status = $ass->getMemberStatus($user_id);
151 $member_status->setFeedback(true);
152 $member_status->update();
153 }
154
155 $notification->sendFeedbackNotification(
156 $ass->getId(),
157 $noti_rec_ids,
158 $file["file"]
159 );
160 }
161 }
162 }
163 }
164 }
165
166}
$filename
Definition: buildRTE.php:78
__construct(InternalRepoService $repo, InternalDomainService $domain, \ilExcTutorFeedbackZipStakeholder $stakeholder, \ilExcTutorFeedbackFileStakeholder $user_feedback_stakeholder)
getMultiFeedbackStructureFile(\ilExAssignment $assignment, \ilObjExercise $exercise)
importFromUploadResult(int $ass_id, int $tutor_id, UploadResult $result)
saveMultiFeedbackFiles(\ilObjExercise $exc, int $ass_id, int $tutor_id, array $file_md5s)
getFiles(\ilObjExercise $exc, int $ass_id, int $tutor_id)
Exercise assignment.
Class ilFileServicesPolicy.
Class ilObjExercise.
static _lookupName(int $a_user_id)
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26