ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilExerciseSubmissionFeedbackGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
20 
25 {
30 
31  public function __construct(
32  InternalDomainService $domain,
33  InternalGUIService $gui,
34  ?ilObjExercise $exercise,
35  ILIAS\Exercise\Notification\NotificationManager $notification
36  ) {
37  $this->domain = $domain;
38  $this->gui = $gui;
39  $lng = $domain->lng();
40  $lng->loadLanguageModule("exc");
41  $this->exercise = $exercise;
42  $this->notification = $notification;
43  }
44 
45  public function executeCommand(): void
46  {
47  $ctrl = $this->gui->ctrl();
48 
49  $next_class = $ctrl->getNextClass($this);
50  $cmd = $ctrl->getCmd("showFeedbackForm");
51 
52  switch ($next_class) {
53  default:
54  if (in_array($cmd, [
55  "showFeedbackForm",
56  "validateAndSubmitFeedbackForm",
57  "saveCommentForLearners"
58  ])) {
59  $this->$cmd();
60  }
61  }
62  }
63 
64  public function getComponents(int $ass_id, int $usr_id): array
65  {
66  $lng = $this->domain->lng();
67  $ctrl = $this->gui->ctrl();
68 
69  $ctrl->setParameter($this, "ass_id", $ass_id);
70  $ctrl->setParameter($this, "member_id", $usr_id);
71 
72  $components = $this
73  ->gui
74  ->modal($lng->txt("exc_tbl_action_feedback_text"))
75  ->getAsyncTriggerButtonComponents(
76  $lng->txt("exc_tbl_action_feedback_text"),
77  $ctrl->getLinkTarget($this, "showFeedbackForm", "", true),
78  true
79  );
80 
81  return $components;
82  }
83 
84  protected function showFeedbackForm(): void
85  {
86  $lng = $this->domain->lng();
87  $this->gui
88  ->modal($lng->txt("exc_tbl_action_feedback_text"))
89  ->form($this->getFeedbackForm())
90  ->send();
91  }
92 
93  protected function getFeedbackForm(): \ILIAS\Repository\Form\FormAdapterGUI
94  {
95  $lng = $this->domain->lng();
96  $ctrl = $this->gui->ctrl();
97  $request = $this->gui->request();
98 
99  $ass_id = $request->getAssId();
100  $ass = $this->domain->assignment()->getAssignment($ass_id);
101  $user_id = $request->getMemberId();
102 
103  $ctrl->setParameter($this, "ass_id", $ass_id);
104  $ctrl->setParameter($this, "member_id", $user_id);
105 
106  $form = $this
107  ->gui
108  ->form(self::class, "validateAndSubmitFeedbackForm")
109  ->asyncModal()
110  ->textarea(
111  "comment",
112  $lng->txt("exc_comment_for_learner"),
113  $lng->txt("exc_comment_for_learner_info"),
114  $ass->getMemberStatus($user_id)->getComment()
115  );
116 
117  return $form;
118  }
119 
120  protected function validateAndSubmitFeedbackForm(): void
121  {
122  $lng = $this->domain->lng();
123  $ctrl = $this->gui->ctrl();
124  $request = $this->gui->request();
125  $form = $this->getFeedbackForm();
126  if (!$form->isValid()) {
127  $this->gui->modal($lng->txt("exc_tbl_action_feedback_text"))
128  ->form($form)
129  ->send();
130  }
131 
132  $user_id = $request->getMemberId();
133  $ass_id = $request->getAssId();
134  $comment = $form->getData("comment");
135 
136  $ctrl->setParameter($this, "member_id", $user_id);
137  $ctrl->setParameter($this, "ass_id", $ass_id);
138  $ctrl->setParameter($this, "comment", $comment);
139 
140  $target = $ctrl->getLinkTarget($this, "saveCommentForLearners");
141  $this->gui->send("<script>window.location.href = '" . $target . "';</script>");
142  }
143 
144  protected function saveCommentForLearners(): void
145  {
146  $ctrl = $this->gui->ctrl();
147  $request = $this->gui->request();
148 
149  $ass_id = $request->getAssId();
150  $ass = $this->domain->assignment()->getAssignment($ass_id);
151  $user_id = $request->getMemberId();
152  $comment = trim($request->getComment());
153 
154  if ($ass_id && $user_id) {
155  $submission = new ilExSubmission($ass, $user_id);
156  $user_ids = $submission->getUserIds();
157 
158  $all_members = new ilExerciseMembers($this->exercise);
159  $all_members = $all_members->getMembers();
160 
161  $reci_ids = array();
162  foreach ($user_ids as $user_id) {
163  if (in_array($user_id, $all_members)) {
164  $member_status = $ass->getMemberStatus($user_id);
165  $member_status->setComment(ilUtil::stripSlashes($comment));
166  $member_status->setFeedback(true);
167  $member_status->update();
168 
169  if (trim($comment) !== '' && trim($comment) !== '0') {
170  $reci_ids[] = $user_id;
171  }
172  }
173  }
174 
175  if ($reci_ids !== []) {
176  // send notification
177  $this->notification->sendFeedbackNotification(
178  $ass_id,
179  $reci_ids,
180  "",
181  true
182  );
183  }
184  }
185 
186  $ctrl->redirectByClass("ilexercisemanagementgui", $request->getParticipantId()
187  ? "showParticipant"
188  : "members");
189  }
190 }
Exercise UI frontend presentation service class.
Interface Observer Contains several chained tasks and infos about them.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
__construct(InternalDomainService $domain, InternalGUIService $gui, ?ilObjExercise $exercise, ILIAS\Exercise\Notification\NotificationManager $notification)
ILIAS Exercise Notification NotificationManager $notification
notification()
description: > Example for rendring a notification glyph.
$components
Class ilObjExercise.
$comment
Definition: buildRTE.php:72
form( $class_path, string $cmd, string $submit_caption="")
global $lng
Definition: privfeed.php:32
Exercise submission //TODO: This class has many static methods related to delivered "files"...
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:97