ILIAS  release_8 Revision v8.24
class.ilExSubmissionTextGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 protected ilObjUser $user;
30 protected ilHelpGUI $help;
31
32 public function __construct(
33 ilObjExercise $a_exercise,
34 ilExSubmission $a_submission
35 ) {
36 global $DIC;
37
38 parent::__construct($a_exercise, $a_submission);
39 $this->user = $DIC->user();
40 $this->help = $DIC["ilHelp"];
41 }
42
43 public function executeCommand(): void
44 {
45 $ilCtrl = $this->ctrl;
46
47 if (!$this->assignment ||
48 $this->assignment->getType() != ilExAssignment::TYPE_TEXT ||
49 !$this->submission->canView()) {
50 return;
51 }
52
53 $class = $ilCtrl->getNextClass($this);
54 $cmd = $ilCtrl->getCmd("showassignmenttext");
55
56 switch ($class) {
57 default:
58 $this->{$cmd . "Object"}();
59 break;
60 }
61 }
62
63 public static function getOverviewContent(
64 ilInfoScreenGUI $a_info,
65 ilExSubmission $a_submission
66 ): void {
67 global $DIC;
68
69 $lng = $DIC->language();
70 $ilCtrl = $DIC->ctrl();
71
72 $button = ilLinkButton::getInstance();
73 if ($a_submission->canSubmit()) {
74 $button->setPrimary(true);
75 $button->setCaption("exc_text_assignment_edit");
76 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "editAssignmentText"));
77 } else {
78 $button->setCaption("exc_text_assignment_show");
79 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "showAssignmentText"));
80 }
81 $files_str = $button->render();
82
83 $a_info->addProperty($lng->txt("exc_files_returned_text"), $files_str);
84 }
85
86
87 //
88 // TEXT ASSIGNMENT (EDIT)
89 //
90
91 protected function initAssignmentTextForm(
92 bool $a_read_only = false
94 $ilCtrl = $this->ctrl;
96
97 $form = new ilPropertyFormGUI();
98 $form->setTitle($this->lng->txt("exc_assignment") . " \"" . $this->assignment->getTitle() . "\"");
99
100 if (!$a_read_only) {
101 $text = new ilTextAreaInputGUI($this->lng->txt("exc_your_text"), "atxt");
102 $text->setRequired(
103 $this->mandatory_manager->isMandatoryForUser($this->submission->getAssignment()->getId(), $this->user->getId())
104 );
105 $text->setRows(40);
106 $text->setMaxNumOfChars($this->assignment->getMaxCharLimit());
107 $text->setMinNumOfChars($this->assignment->getMinCharLimit());
108
109 if ($text->isCharLimited()) {
110 $char_msg = "";
111 if ($this->assignment->getMinCharLimit() !== 0) {
112 $char_msg .= $lng->txt("exc_min_char_limit") . ": " . $this->assignment->getMinCharLimit();
113 }
114 if ($this->assignment->getMaxCharLimit() !== 0) {
115 $char_msg .= " " . $lng->txt("exc_max_char_limit") . ": " . $this->assignment->getMaxCharLimit();
116 }
117 $text->setInfo($char_msg);
118 }
119
120 $form->addItem($text);
121
122 if (ilObjAdvancedEditing::_getRichTextEditor() === "tinymce") {
123 // custom rte tags
124 $text->setUseRte(true);
125 $text->setRTESupport($this->submission->getUserId(), "exca~", "exc_ass");
126
127 // see ilObjForumGUI
128 $text->disableButtons(array(
129 'charmap',
130 'undo',
131 'redo',
132 'alignleft',
133 'aligncenter',
134 'alignright',
135 'alignjustify',
136 'anchor',
137 'fullscreen',
138 'cut',
139 'copy',
140 'paste',
141 'pastetext',
142 'code',
143 // 'formatselect' #13234
144 ));
145 }
146
147 $form->setFormAction($ilCtrl->getFormAction($this, "updateAssignmentText"));
148 $form->addCommandButton("updateAssignmentTextAndReturn", $this->lng->txt("save_return"));
149 $form->addCommandButton("updateAssignmentText", $this->lng->txt("save"));
150 $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
151 } else {
152 $form->setFormAction($ilCtrl->getFormAction($this, "returnToParent"));
153 $text = new ilNonEditableValueGUI($this->lng->txt("exc_files_returned_text"), "atxt", true);
154 $form->addItem($text);
155 }
156
157 return $form;
158 }
159
161 ilPropertyFormGUI $a_form = null
162 ): void {
163 $ilCtrl = $this->ctrl;
164
165 if (!$this->submission->canSubmit()) {
166 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
167 $ilCtrl->redirect($this, "returnToParent");
168 }
169
170 $this->triggerAssignmentTool();
171
172 $this->handleTabs();
173
174 $ilHelp = $this->help;
175 $ilHelp->setScreenIdComponent("exc");
176 $ilHelp->setScreenId("text_submission");
177
178 if ($a_form === null) {
179 $a_form = $this->initAssignmentTextForm();
180
181 $files = $this->submission->getFiles();
182 if ($files !== []) {
183 $files = array_shift($files);
184 if (trim($files["atext"]) !== '' && trim($files["atext"]) !== '0') {
185 $text = $a_form->getItemByPostVar("atxt");
186 // mob id to mob src
187 $text->setValue(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1));
188 }
189 }
190 }
191
192 $this->tpl->setContent($a_form->getHTML());
193 }
194
196 {
197 $this->updateAssignmentTextObject(true);
198 }
199
205 bool $a_return = false
206 ): void {
207 $ilCtrl = $this->ctrl;
208
209 if (!$this->submission->canSubmit()) {
210 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
211 $ilCtrl->redirect($this, "returnToParent");
212 }
213
214 $form = $this->initAssignmentTextForm();
215
216 // we are not using a purifier, so we have to set the valid RTE tags
217 // :TODO:
218 $rte = $form->getItemByPostVar("atxt");
219 $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass"));
220
221 if ($form->checkInput()) {
222 $text = trim($form->getInput("atxt"));
223
224 $returned_id = $this->submission->updateTextSubmission(
225 // mob src to mob id
227 );
228
229 // no empty text
230 if ($returned_id) {
231 // #16532 - always send notifications
232 $this->handleNewUpload();
233
234 // mob usage
235 $mobs = ilRTE::_getMediaObjects($text, 0);
236 foreach ($mobs as $mob) {
237 if (ilObjMediaObject::_exists($mob)) {
238 ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
239 ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
240 }
241 }
242 } else {
243 $this->handleRemovedUpload();
244 }
245
246 $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_text_saved"), true);
247 if ($a_return) {
248 $ilCtrl->redirect($this, "returnToParent");
249 } else {
250 $ilCtrl->redirect($this, "editAssignmentText");
251 }
252 }
253
254 $form->setValuesByPost();
255 $this->editAssignmentTextObject($form);
256 }
257
258 public function showAssignmentTextObject(): void
259 {
260 if (!$this->submission->isTutor()) {
261 $this->handleTabs();
262 }
263
264 $a_form = $this->initAssignmentTextForm(true);
265
266 $files = $this->submission->getFiles();
267 if ($files !== []) {
268 $files = array_shift($files);
269 if (trim($files["atext"]) !== '' && trim($files["atext"]) !== '0') {
270 if ($files["late"] &&
271 !$this->submission->hasPeerReviewAccess()) {
272 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_late_submission"));
273 }
274
275 $text = $a_form->getItemByPostVar("atxt");
276 // mob id to mob src
277 $text->setValue(nl2br(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1)));
278 }
279 }
280
281 $this->tpl->setContent($a_form->getHTML());
282 }
283}
getNextClass($a_gui_class=null)
@inheritDoc
Exercise submission base 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)
editAssignmentTextObject(ilPropertyFormGUI $a_form=null)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initAssignmentTextForm(bool $a_read_only=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.
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 _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.
global $DIC
Definition: feed.php:28
$mobs
Definition: imgupload.php:70
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$lng