ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 }
134
135 $user_id = $request->getMemberId();
136 $ass_id = $request->getAssId();
137 $comment = $form->getData("comment");
138
139 $ctrl->setParameter($this, "member_id", $user_id);
140 $ctrl->setParameter($this, "ass_id", $ass_id);
141 $ctrl->setParameter($this, "comment", $comment);
142
143 $target = $ctrl->getLinkTarget($this, "saveCommentForLearners");
144 $this->gui->send("<script>window.location.href = '" . $target . "';</script>");
145 }
146
147 protected function saveCommentForLearners(): void
148 {
149 $ctrl = $this->gui->ctrl();
150 $request = $this->gui->request();
151
152 $ass_id = $request->getAssId();
153 $ass = $this->domain->assignment()->getAssignment($ass_id);
154 $user_id = $request->getMemberId();
155 $comment = trim($request->getComment());
156
157 if ($ass_id && $user_id) {
158 $submission = new ilExSubmission($ass, $user_id);
159 $user_ids = $submission->getUserIds();
160
161 $all_members = new ilExerciseMembers($this->exercise);
162 $all_members = $all_members->getMembers();
163
164 $reci_ids = array();
165 foreach ($user_ids as $user_id) {
166 if (in_array($user_id, $all_members)) {
167 $member_status = $ass->getMemberStatus($user_id);
168 $member_status->setComment(ilUtil::stripSlashes($comment));
169 $member_status->setFeedback(true);
170 $member_status->update();
171
172 if (trim($comment) !== '' && trim($comment) !== '0') {
173 $reci_ids[] = $user_id;
174 }
175 }
176 }
177
178 if ($reci_ids !== []) {
179 // send notification
180 $this->notification->sendFeedbackNotification(
181 $ass_id,
182 $reci_ids,
183 "",
184 true
185 );
186 }
187 }
188
189 $ctrl->redirectByClass("ilexercisemanagementgui", $request->getParticipantId()
190 ? "showParticipant"
191 : "members");
192 }
193}
$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:31