ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExSubmissionTextGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 protected \ILIAS\Exercise\Submission\SubmissionManager $sub_manager;
30 protected ilObjUser $user;
31 protected ilHelpGUI $help;
32
33 public function __construct(
34 ilObjExercise $a_exercise,
35 ilExSubmission $a_submission
36 ) {
37 global $DIC;
38
39 parent::__construct($a_exercise, $a_submission);
40 $this->user = $DIC->user();
41 $this->help = $DIC["ilHelp"];
42 $this->sub_manager = $DIC->exercise()->internal()->domain()->submission(
43 $a_submission->getAssignment()->getId()
44 );
45 }
46
47 public function executeCommand(): void
48 {
49 $ilCtrl = $this->ctrl;
50
51 if (!$this->assignment ||
52 $this->assignment->getType() != ilExAssignment::TYPE_TEXT ||
53 !$this->submission->canView()) {
54 return;
55 }
56
57 $class = $ilCtrl->getNextClass($this);
58 $cmd = $ilCtrl->getCmd("showassignmenttext");
59
60 switch ($class) {
61 default:
62 $this->{$cmd . "Object"}();
63 break;
64 }
65 }
66
67 public static function getOverviewContent(
68 ilInfoScreenGUI $a_info,
69 ilExSubmission $a_submission
70 ): void {
71 global $DIC;
72
73 $lng = $DIC->language();
74 $ilCtrl = $DIC->ctrl();
75 $gui = $DIC->exercise()->internal()->gui();
76
77 if ($a_submission->canSubmit()) {
78 $link = $gui->link(
79 $lng->txt("exc_text_assignment_edit"),
80 $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionTextGUI"), "editAssignmentText")
81 )->primary();
82 } else {
83 $link = $gui->link(
84 $lng->txt("exc_text_assignment_show"),
85 $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionTextGUI"), "showAssignmentText")
86 )->emphasised();
87 }
88 $files_str = $link->render();
89
90 $a_info->addProperty($lng->txt("exc_files_returned_text"), $files_str);
91 }
92
93
94 //
95 // TEXT ASSIGNMENT (EDIT)
96 //
97
98 protected function initAssignmentTextForm(
99 bool $a_read_only = false
101 $ilCtrl = $this->ctrl;
103
104 $form = new ilPropertyFormGUI();
105 $form->setTitle($this->lng->txt("exc_assignment") . " \"" . $this->assignment->getTitle() . "\"");
106
107 if (!$a_read_only) {
108 $text = new ilTextAreaInputGUI($this->lng->txt("exc_your_text"), "atxt");
109 $text->setRequired(
110 $this->mandatory_manager->isMandatoryForUser($this->submission->getAssignment()->getId(), $this->user->getId())
111 );
112 $text->setRows(15);
113 $text->setMaxNumOfChars($this->assignment->getMaxCharLimit());
114 $text->setMinNumOfChars($this->assignment->getMinCharLimit());
115
116 if ($text->isCharLimited()) {
117 $char_msg = "";
118 if ($this->assignment->getMinCharLimit() !== 0) {
119 $char_msg .= $lng->txt("exc_min_char_limit") . ": " . $this->assignment->getMinCharLimit();
120 }
121 if ($this->assignment->getMaxCharLimit() !== 0) {
122 $char_msg .= " " . $lng->txt("exc_max_char_limit") . ": " . $this->assignment->getMaxCharLimit();
123 }
124 $text->setInfo($char_msg);
125 }
126
127 $form->addItem($text);
128
129 if ((new ilRTESettings($this->lng, $this->user))->getRichTextEditor() === "tinymce") {
130 $text->setUseRte(true);
131 $text->setRteTagSet("mini");
132 }
133
134 $form->setFormAction($ilCtrl->getFormAction($this, "updateAssignmentText"));
135 $form->addCommandButton("updateAssignmentTextAndReturn", $this->lng->txt("save_return"));
136 $form->addCommandButton("updateAssignmentText", $this->lng->txt("save"));
137 $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
138 } else {
139 $form->setFormAction($ilCtrl->getFormAction($this, "returnToParent"));
140 $text = new ilNonEditableValueGUI($this->lng->txt("exc_files_returned_text"), "atxt", true);
141 $form->addItem($text);
142 }
143
144 return $form;
145 }
146
148 ?ilPropertyFormGUI $a_form = null
149 ): void {
150 $ilCtrl = $this->ctrl;
151
152 if (!$this->submission->canSubmit()) {
153 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
154 $ilCtrl->redirect($this, "returnToParent");
155 }
156
157 $this->triggerAssignmentTool();
158
159 $this->handleTabs();
160
161 $ilHelp = $this->help;
162 $ilHelp->setScreenIdComponent("exc");
163 $ilHelp->setScreenId("text_submission");
164
165 if ($a_form === null) {
166 $a_form = $this->initAssignmentTextForm();
167
168 $sub = $this->sub_manager->getSubmissionsOfUser($this->submission->getUserId())->current();
169 if ($sub) {
170 if (trim($sub->getText()) !== '' && trim($sub->getText()) !== '0') {
171 $text = $a_form->getItemByPostVar("atxt");
172 // mob id to mob src
173 $text->setValue(ilRTE::_replaceMediaObjectImageSrc($sub->getText(), 1));
174 }
175 }
176 }
177
178 $this->tpl->setContent($a_form->getHTML());
179 }
180
182 {
183 $this->updateAssignmentTextObject(true);
184 }
185
191 bool $a_return = false
192 ): void {
193 $ilCtrl = $this->ctrl;
194
195 if (!$this->submission->canSubmit()) {
196 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
197 $ilCtrl->redirect($this, "returnToParent");
198 }
199
200 $form = $this->initAssignmentTextForm();
201
202 // we are not using a purifier, so we have to set the valid RTE tags
203 // :TODO:
204 $rte = $form->getItemByPostVar("atxt");
205 $rte->setRteTags(ilRTESettings::_getUsedHTMLTags("exc_ass"));
206
207 if ($form->checkInput()) {
208 $text = trim($form->getInput("atxt"));
209
210 $returned_id = $this->submission->updateTextSubmission(
211 // mob src to mob id
213 );
214
215 // no empty text
216 if ($returned_id) {
217 // #16532 - always send notifications
218 $this->handleNewUpload();
219
220 // mob usage
221 $mobs = ilRTE::_getMediaObjects($text, 0);
222 foreach ($mobs as $mob) {
223 if (ilObjMediaObject::_exists($mob)) {
224 ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
225 ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
226 }
227 }
228 } else {
229 $this->handleRemovedUpload();
230 }
231
232 $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_text_saved"), true);
233 if ($a_return) {
234 $ilCtrl->redirect($this, "returnToParent");
235 } else {
236 $ilCtrl->redirect($this, "editAssignmentText");
237 }
238 }
239
240 $form->setValuesByPost();
241 $this->editAssignmentTextObject($form);
242 }
243
244 public function showAssignmentTextObject(): void
245 {
246 if (!$this->submission->isTutor()) {
247 $this->handleTabs();
248 }
249
250 $a_form = $this->initAssignmentTextForm(true);
251
252 $sub = $this->sub_manager->getSubmissionsOfUser($this->submission->getUserId())->current();
253 if ($sub) {
254 if (trim($sub->getText()) !== '' && trim($sub->getText()) !== '0') {
255 if ($sub->getLate() &&
256 !$this->submission->hasPeerReviewAccess()) {
257 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_late_submission"));
258 }
259
260 $text = $a_form->getItemByPostVar("atxt");
261 // mob id to mob src
262 $val = nl2br(ilRTE::_replaceMediaObjectImageSrc($sub->getText(), 1));
263 $val = $this->gui->html()->escapeCurly($val);
264 $text->setValue($val);
265 }
266 }
267 $this->tpl->setContent($a_form->getHTML());
268 }
269}
getNextClass($a_gui_class=null)
@inheritDoc
Exercise submission base gui.
ILIAS Exercise InternalGUIService $gui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
updateAssignmentTextObject(bool $a_return=false)
ILIAS Exercise Submission SubmissionManager $sub_manager
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initAssignmentTextForm(bool $a_read_only=false)
editAssignmentTextObject(?ilPropertyFormGUI $a_form=null)
Exercise submission //TODO: This class has many static methods related to delivered "files".
Help GUI class.
Class ilInfoScreenGUI.
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a non editable value in a property form.
Class ilObjExercise.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
User class.
This class represents a property form user interface.
static _getUsedHTMLTags(string $module='')
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static _getMediaObjects(string $a_text, int $a_direction=0)
Returns all media objects found in the passed string.
This class represents a text area property in a property form.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26