ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  $gui = $DIC->exercise()->internal()->gui();
72 
73  if ($a_submission->canSubmit()) {
74  $link = $gui->link(
75  $lng->txt("exc_text_assignment_edit"),
76  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionTextGUI"), "editAssignmentText")
77  )->primary();
78  } else {
79  $link = $gui->link(
80  $lng->txt("exc_text_assignment_show"),
81  $ilCtrl->getLinkTargetByClass(array(ilAssignmentPresentationGUI::class, "ilExSubmissionGUI", "ilExSubmissionTextGUI"), "showAssignmentText")
82  )->emphasised();
83  }
84  $files_str = $link->render();
85 
86  $a_info->addProperty($lng->txt("exc_files_returned_text"), $files_str);
87  }
88 
89 
90  //
91  // TEXT ASSIGNMENT (EDIT)
92  //
93 
94  protected function initAssignmentTextForm(
95  bool $a_read_only = false
97  $ilCtrl = $this->ctrl;
98  $lng = $this->lng;
99 
100  $form = new ilPropertyFormGUI();
101  $form->setTitle($this->lng->txt("exc_assignment") . " \"" . $this->assignment->getTitle() . "\"");
102 
103  if (!$a_read_only) {
104  $text = new ilTextAreaInputGUI($this->lng->txt("exc_your_text"), "atxt");
105  $text->setRequired(
106  $this->mandatory_manager->isMandatoryForUser($this->submission->getAssignment()->getId(), $this->user->getId())
107  );
108  $text->setRows(15);
109  $text->setMaxNumOfChars($this->assignment->getMaxCharLimit());
110  $text->setMinNumOfChars($this->assignment->getMinCharLimit());
111 
112  if ($text->isCharLimited()) {
113  $char_msg = "";
114  if ($this->assignment->getMinCharLimit() !== 0) {
115  $char_msg .= $lng->txt("exc_min_char_limit") . ": " . $this->assignment->getMinCharLimit();
116  }
117  if ($this->assignment->getMaxCharLimit() !== 0) {
118  $char_msg .= " " . $lng->txt("exc_max_char_limit") . ": " . $this->assignment->getMaxCharLimit();
119  }
120  $text->setInfo($char_msg);
121  }
122 
123  $form->addItem($text);
124 
125  if (ilObjAdvancedEditing::_getRichTextEditor() === "tinymce") {
126  // custom rte tags
127  $text->setUseRte(true);
128  $text->setRTESupport($this->submission->getUserId(), "exca~", "exc_ass");
129 
130  // see ilObjForumGUI
131  $text->disableButtons(array(
132  'charmap',
133  'undo',
134  'redo',
135  'alignleft',
136  'aligncenter',
137  'alignright',
138  'alignjustify',
139  'anchor',
140  'fullscreen',
141  'cut',
142  'copy',
143  'paste',
144  'pastetext',
145  'code',
146  // 'formatselect' #13234
147  ));
148  }
149 
150  $form->setFormAction($ilCtrl->getFormAction($this, "updateAssignmentText"));
151  $form->addCommandButton("updateAssignmentTextAndReturn", $this->lng->txt("save_return"));
152  $form->addCommandButton("updateAssignmentText", $this->lng->txt("save"));
153  $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
154  } else {
155  $form->setFormAction($ilCtrl->getFormAction($this, "returnToParent"));
156  $text = new ilNonEditableValueGUI($this->lng->txt("exc_files_returned_text"), "atxt", true);
157  $form->addItem($text);
158  }
159 
160  return $form;
161  }
162 
163  public function editAssignmentTextObject(
164  ilPropertyFormGUI $a_form = null
165  ): void {
166  $ilCtrl = $this->ctrl;
167 
168  if (!$this->submission->canSubmit()) {
169  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
170  $ilCtrl->redirect($this, "returnToParent");
171  }
172 
173  $this->triggerAssignmentTool();
174 
175  $this->handleTabs();
176 
177  $ilHelp = $this->help;
178  $ilHelp->setScreenIdComponent("exc");
179  $ilHelp->setScreenId("text_submission");
180 
181  if ($a_form === null) {
182  $a_form = $this->initAssignmentTextForm();
183 
184  $files = $this->submission->getFiles();
185  if ($files !== []) {
186  $files = array_shift($files);
187  if (trim($files["atext"]) !== '' && trim($files["atext"]) !== '0') {
188  $text = $a_form->getItemByPostVar("atxt");
189  // mob id to mob src
190  $text->setValue(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1));
191  }
192  }
193  }
194 
195  $this->tpl->setContent($a_form->getHTML());
196  }
197 
198  public function updateAssignmentTextAndReturnObject(): void
199  {
200  $this->updateAssignmentTextObject(true);
201  }
202 
207  public function updateAssignmentTextObject(
208  bool $a_return = false
209  ): void {
210  $ilCtrl = $this->ctrl;
211 
212  if (!$this->submission->canSubmit()) {
213  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exercise_time_over"), true);
214  $ilCtrl->redirect($this, "returnToParent");
215  }
216 
217  $form = $this->initAssignmentTextForm();
218 
219  // we are not using a purifier, so we have to set the valid RTE tags
220  // :TODO:
221  $rte = $form->getItemByPostVar("atxt");
222  $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass"));
223 
224  if ($form->checkInput()) {
225  $text = trim($form->getInput("atxt"));
226 
227  $returned_id = $this->submission->updateTextSubmission(
228  // mob src to mob id
230  );
231 
232  // no empty text
233  if ($returned_id) {
234  // #16532 - always send notifications
235  $this->handleNewUpload();
236 
237  // mob usage
238  $mobs = ilRTE::_getMediaObjects($text, 0);
239  foreach ($mobs as $mob) {
240  if (ilObjMediaObject::_exists($mob)) {
241  ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
242  ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
243  }
244  }
245  } else {
246  $this->handleRemovedUpload();
247  }
248 
249  $this->tpl->setOnScreenMessage('success', $this->lng->txt("exc_text_saved"), true);
250  if ($a_return) {
251  $ilCtrl->redirect($this, "returnToParent");
252  } else {
253  $ilCtrl->redirect($this, "editAssignmentText");
254  }
255  }
256 
257  $form->setValuesByPost();
258  $this->editAssignmentTextObject($form);
259  }
260 
261  public function showAssignmentTextObject(): void
262  {
263  if (!$this->submission->isTutor()) {
264  $this->handleTabs();
265  }
266 
267  $a_form = $this->initAssignmentTextForm(true);
268 
269  $files = $this->submission->getFiles();
270  if ($files !== []) {
271  $files = array_shift($files);
272  if (trim($files["atext"]) !== '' && trim($files["atext"]) !== '0') {
273  if ($files["late"] &&
274  !$this->submission->hasPeerReviewAccess()) {
275  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_late_submission"));
276  }
277 
278  $text = $a_form->getItemByPostVar("atxt");
279  // mob id to mob src
280  $text->setValue(nl2br(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1)));
281  }
282  }
283  $this->tpl->setContent($a_form->getHTML());
284  }
285 }
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.
handleNewUpload(bool $a_no_notifications=false)
updateAssignmentTextObject(bool $a_return=false)
ILIAS Exercise InternalGUIService $gui
Class ilInfoScreenGUI.
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...
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
Help GUI class.
Exercise submission base gui.
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
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.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
global $DIC
Definition: feed.php:28
Class ilObjExercise.
getNextClass($a_gui_class=null)
__construct(VocabulariesInterface $vocabularies)
setScreenIdComponent(string $a_comp)
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
editAssignmentTextObject(ilPropertyFormGUI $a_form=null)
static _exists(int $id, bool $reference=false, ?string $type=null)
setRequired(bool $a_required)
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.
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initAssignmentTextForm(bool $a_read_only=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.