ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
TutorFeedbackFileManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
32 {
34  protected int $ass_id;
35  protected \ILIAS\FileUpload\FileUpload $upload;
36  protected \ilExAssignmentTypeInterface $type;
40 
41  public function __construct(
42  int $ass_id,
43  InternalRepoService $repo,
44  InternalDomainService $domain,
46  \ilExcTutorTeamFeedbackFileStakeholder $team_stakeholder,
47  TutorFeedbackFileObserver $file_observer
48  ) {
49  global $DIC;
50 
51  $this->upload = $DIC->upload();
52 
53  $this->file_observer = $file_observer;
55  $this->type = $types->getById(\ilExAssignment::lookupType($ass_id));
56  if ($this->type->usesTeams()) {
57  $this->repo = $repo->tutorFeedbackFileTeam();
58  $this->stakeholder = $team_stakeholder;
59  } else {
60  $this->repo = $repo->tutorFeedbackFile();
61  $this->stakeholder = $stakeholder;
62  }
63  $this->domain = $domain;
64  $this->ass_id = $ass_id;
65  }
66 
68  {
69  return $this->stakeholder;
70  }
71 
72  public function addObserver(): void
73  {
74  $this->domain->resourceStorage()->events()->attach(
75  $this->file_observer,
76  Event::COLLECTION_RESOURCE_ADDED
77  );
78  }
79 
80  public function sendNotification(string $rcid, string $rid): void
81  {
82  $log = $this->domain->log();
83  $log->debug("Ass id: " . $this->ass_id);
84 
85  $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
86  $ref_id = (int) current(\ilObject::_getAllReferences($exc_id));
87 
88  $log->debug("Ref id: " . $ref_id);
89 
90  if ($ref_id === 0) {
91  return;
92  }
93  $log->debug("Get notification");
94  $notification = $this->domain->notification($ref_id);
95  $log->debug("Get participant");
96  $part_id = $this->repo->getParticipantIdForRcid($this->ass_id, $rcid);
97  $log->debug("Get filename");
98  $filename = $this->repo->getFilenameForRid($this->ass_id, $part_id, $rid);
99  $log->debug("Get assignment");
100  $ass = new \ilExAssignment($this->ass_id);
101  $log->debug("Get submission");
102  $submission = new \ilExSubmission($ass, $part_id);
103  $feedback_id = $submission->getFeedbackId();
104  $noti_rec_ids = $submission->getUserIds();
105 
106  $log->debug("Feedback id: " . $feedback_id);
107  if ($feedback_id) {
108  if ($noti_rec_ids) {
109  foreach ($noti_rec_ids as $user_id) {
110  $member_status = $ass->getMemberStatus($user_id);
111  $member_status->setFeedback(true);
112  $member_status->update();
113  }
114 
115  $notification->sendFeedbackNotification(
116  $ass->getId(),
117  $noti_rec_ids,
118  $filename
119  );
120  }
121  }
122  }
123 
124  public function hasCollection(int $participant_id): bool
125  {
126  return ($this->getCollectionIdString($participant_id) !== "");
127  }
128 
129  protected function getLegacyFeedbackId(int $participant_id): string
130  {
131  if ($this->type->usesTeams()) {
132  $team_id = $this->domain->team()->getTeamForMember($this->ass_id, $participant_id);
133  if (is_null($team_id)) {
134  throw new \ilExerciseException("Team for user " . $participant_id . " in assignment " . $this->ass_id . " not found.");
135  }
136  return "t" . $team_id;
137  } else {
138  return (string) $participant_id;
139  }
140  }
141 
142  public function count(int $participant_id): int
143  {
144  if ($this->hasCollection($participant_id)) {
145  // IRSS
146  return $this->repo->count($this->ass_id, $participant_id);
147  }
148  // LEGACY
149  $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
150  try {
151  $storage = new \ilFSStorageExercise($exc_id, $this->ass_id);
152  return $storage->countFeedbackFiles($this->getLegacyFeedbackId($participant_id));
153  } catch (\ilExerciseException $e) {
154  }
155  return 0;
156  }
157 
158  public function getFeedbackTitle(int $participant_id): string
159  {
160  $title = $this->domain->lng()->txt('exc_fb_files');
161  if ($this->type->usesTeams()) {
162  $name = \ilObjUser::_lookupName($participant_id);
163  return $title . ": " . $name["lastname"] . ", " . $name["firstname"];
164  } else {
165  $name = \ilObjUser::_lookupName($participant_id);
166  return $title . ": " . $name["lastname"] . ", " . $name["firstname"];
167  }
168  }
169 
170  public function getCollectionIdString(int $participant_id): string
171  {
172  return $this->repo->getIdStringForAssIdAndUserId($this->ass_id, $participant_id);
173  }
174 
175  public function createCollection(int $participant_id): void
176  {
177  $this->repo->createCollection($this->ass_id, $participant_id);
178  }
179 
180  public function deleteCollection(int $participant_id): void
181  {
182  $this->repo->deleteCollection(
183  $this->ass_id,
184  $participant_id,
185  $this->stakeholder
186  );
187  }
188 
189  public function getFiles(int $participant_id): array
190  {
191  $files = [];
192  if ($this->repo->hasCollection($this->ass_id, $participant_id)) {
193  $files = array_map(function (ResourceInformation $info): string {
194  return $info->getTitle();
195  }, iterator_to_array($this->repo->getCollectionResourcesInfo($this->ass_id, $participant_id)));
196  } else {
197  $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
198  $storage = new \ilFSStorageExercise($exc_id, $this->ass_id);
199  $files = $storage->getFeedbackFiles($this->getLegacyFeedbackId($participant_id));
200  }
201  return $files;
202  }
203 
204  public function deliver(int $participant_id, string $file): void
205  {
206  $assignment = $this->domain->assignment()->getAssignment($this->ass_id);
207  if ($assignment->notStartedYet()) {
208  return;
209  }
210 
211  if ($this->repo->hasCollection($this->ass_id, $participant_id)) {
212  // IRSS
213  $this->repo->deliverFile($this->ass_id, $participant_id, $file);
214  } else {
215  // LEGACY
216  $exc_id = \ilExAssignment::lookupExerciseId($this->ass_id);
217  $storage = new \ilFSStorageExercise($exc_id, $this->ass_id);
218  $files = $storage->getFeedbackFiles($this->getLegacyFeedbackId($participant_id));
219  $file_exist = false;
220  foreach ($files as $fb_file) {
221  if ($fb_file === $file) {
222  $file_exist = true;
223  break;
224  }
225  }
226  if (!$file_exist) {
227  return;
228  }
229  // deliver file
230  $p = $storage->getFeedbackFilePath($this->getLegacyFeedbackId($participant_id), $file);
232  }
233  }
234 
235 }
static _getAllReferences(int $id)
get all reference ids for object ID
static lookupType(int $a_id)
static _lookupName(int $a_user_id)
lookup user name
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
__construct(int $ass_id, InternalRepoService $repo, InternalDomainService $domain, \ilExcTutorFeedbackFileStakeholder $stakeholder, \ilExcTutorTeamFeedbackFileStakeholder $team_stakeholder, TutorFeedbackFileObserver $file_observer)
$log
Definition: result.php:33
$filename
Definition: buildRTE.php:78
static lookupExerciseId(int $a_ass_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...