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