ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TutorFeedbackFileManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
30{
32 protected int $ass_id;
33 protected \ILIAS\FileUpload\FileUpload $upload;
34 protected \ilExAssignmentTypeInterface $type;
38
39 public function __construct(
40 int $ass_id,
46 ) {
47 global $DIC;
48
49 $this->upload = $DIC->upload();
50
51 $this->file_observer = $file_observer;
53 $this->type = $types->getById(\ilExAssignment::lookupType($ass_id));
54 if ($this->type->usesTeams()) {
55 $this->repo = $repo->tutorFeedbackFileTeam();
56 $this->stakeholder = $team_stakeholder;
57 } else {
58 $this->repo = $repo->tutorFeedbackFile();
59 $this->stakeholder = $stakeholder;
60 }
61 $this->domain = $domain;
62 $this->ass_id = $ass_id;
63 }
64
66 {
67 return $this->stakeholder;
68 }
69
70 public function addObserver(): void
71 {
72 $this->domain->resourceStorage()->events()->attach(
73 $this->file_observer,
74 Event::COLLECTION_RESOURCE_ADDED
75 );
76 }
77
78 public function sendNotification(string $rcid, string $rid): void
79 {
80 $log = $this->domain->log();
81 $log->debug("Ass id: " . $this->ass_id);
82
83 $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
84 $ref_id = (int) current(\ilObject::_getAllReferences($exc_id));
85
86 $log->debug("Ref id: " . $ref_id);
87
88 if ($ref_id === 0) {
89 return;
90 }
91 $log->debug("Get notification");
92 $notification = $this->domain->notification($ref_id);
93 $log->debug("Get participant");
94 $part_id = $this->repo->getParticipantIdForRcid($this->ass_id, $rcid);
95 $log->debug("Get filename");
96 $filename = $this->repo->getFilenameForRid($this->ass_id, $part_id, $rid);
97 $log->debug("Get assignment");
98 $ass = new \ilExAssignment($this->ass_id);
99 $log->debug("Get submission");
100 $submission = new \ilExSubmission($ass, $part_id);
101 $feedback_id = $submission->getFeedbackId();
102 $noti_rec_ids = $submission->getUserIds();
103
104 $log->debug("Feedback id: " . $feedback_id);
105 if ($feedback_id) {
106 if ($noti_rec_ids) {
107 foreach ($noti_rec_ids as $user_id) {
108 $member_status = $ass->getMemberStatus($user_id);
109 $member_status->setFeedback(true);
110 $member_status->update();
111 }
112
113 $notification->sendFeedbackNotification(
114 $ass->getId(),
115 $noti_rec_ids,
117 );
118 }
119 }
120 }
121
122 public function hasCollection(int $participant_id): bool
123 {
124 return ($this->getCollectionIdString($participant_id) !== "");
125 }
126
127 protected function getLegacyFeedbackId(int $participant_id): string
128 {
129 if ($this->type->usesTeams()) {
130 $team_id = $this->domain->team()->getTeamForMember($this->ass_id, $participant_id);
131 if (is_null($team_id)) {
132 throw new \ilExerciseException("Team for user " . $participant_id . " in assignment " . $this->ass_id . " not found.");
133 }
134 return "t" . $team_id;
135 } else {
136 return (string) $participant_id;
137 }
138 }
139
140 public function count(int $participant_id): int
141 {
142 if ($this->hasCollection($participant_id)) {
143 // IRSS
144 return $this->repo->count($this->ass_id, $participant_id);
145 }
146 return 0;
147 }
148
149 public function getFeedbackTitle(int $participant_id): string
150 {
151 $title = $this->domain->lng()->txt('exc_fb_files');
152 if ($this->type->usesTeams()) {
153 $name = \ilObjUser::_lookupName($participant_id);
154 return $title . ": " . $name["lastname"] . ", " . $name["firstname"];
155 } else {
156 $name = \ilObjUser::_lookupName($participant_id);
157 return $title . ": " . $name["lastname"] . ", " . $name["firstname"];
158 }
159 }
160
161 public function getCollectionIdString(int $participant_id): string
162 {
163 return $this->repo->getIdStringForAssIdAndUserId($this->ass_id, $participant_id);
164 }
165
166 public function createCollection(int $participant_id): void
167 {
168 $this->repo->createCollection($this->ass_id, $participant_id);
169 }
170
171 public function deleteCollection(int $participant_id): void
172 {
173 $this->repo->deleteCollection(
174 $this->ass_id,
175 $participant_id,
176 $this->stakeholder
177 );
178 }
179
180 public function getFiles(int $participant_id): array
181 {
182 $files = [];
183 if ($this->repo->hasCollection($this->ass_id, $participant_id)) {
184 $files = array_map(function (ResourceInformation $info): string {
185 return $info->getTitle();
186 }, iterator_to_array($this->repo->getCollectionResourcesInfo($this->ass_id, $participant_id)));
187 }
188 return $files;
189 }
190
191 public function deliver(int $participant_id, string $file): void
192 {
193 $assignment = $this->domain->assignment()->getAssignment($this->ass_id);
194 if ($assignment->notStartedYet()) {
195 return;
196 }
197
198 if ($this->repo->hasCollection($this->ass_id, $participant_id)) {
199 // IRSS
200 $this->repo->deliverFile($this->ass_id, $participant_id, $file);
201 }
202 }
203
204}
$filename
Definition: buildRTE.php:78
__construct(int $ass_id, InternalRepoService $repo, InternalDomainService $domain, \ilExcTutorFeedbackFileStakeholder $stakeholder, \ilExcTutorTeamFeedbackFileStakeholder $team_stakeholder, TutorFeedbackFileObserver $file_observer)
static lookupExerciseId(int $a_ass_id)
static lookupType(int $a_id)
static _lookupName(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
$info
Definition: entry_point.php:21
$ref_id
Definition: ltiauth.php:66
$log
Definition: ltiresult.php:34
global $DIC
Definition: shib_login.php:26