ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExSubmissionTextGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 protected $user;
18
22 protected $help;
23
24
28 public function __construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
29 {
30 global $DIC;
31
32 parent::__construct($a_exercise, $a_submission);
33 $this->user = $DIC->user();
34 $this->help = $DIC["ilHelp"];
35 }
36
37 public function executeCommand()
38 {
40
41 if (!$this->assignment ||
42 $this->assignment->getType() != ilExAssignment::TYPE_TEXT ||
43 !$this->submission->canView()) {
44 return;
45 }
46
47 $class = $ilCtrl->getNextClass($this);
48 $cmd = $ilCtrl->getCmd("showassignmenttext");
49
50 switch ($class) {
51 default:
52 $this->{$cmd . "Object"}();
53 break;
54 }
55 }
56
57 public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
58 {
59 global $DIC;
60
61 $lng = $DIC->language();
62 $ilCtrl = $DIC->ctrl();
63
64 if ($a_submission->canSubmit()) {
65 $button = ilLinkButton::getInstance();
66 $button->setPrimary(true);
67 $button->setCaption("exc_text_assignment_edit");
68 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "editAssignmentText"));
69 $files_str = $button->render();
70 } else {
71 $button = ilLinkButton::getInstance();
72 $button->setCaption("exc_text_assignment_show");
73 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "showAssignmentText"));
74 $files_str = $button->render();
75 }
76
77 $a_info->addProperty($lng->txt("exc_files_returned_text"), $files_str);
78 }
79
80
81 //
82 // TEXT ASSIGNMENT (EDIT)
83 //
84
85 protected function initAssignmentTextForm($a_read_only = false)
86 {
89
90 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
92 $form->setTitle($this->lng->txt("exc_assignment") . " \"" . $this->assignment->getTitle() . "\"");
93
94 if (!$a_read_only) {
95 $text = new ilTextAreaInputGUI($this->lng->txt("exc_your_text"), "atxt");
96 $text->setRequired((bool) $this->submission->getAssignment()->getMandatory());
97 $text->setRows(40);
98 $text->setMaxNumOfChars($this->assignment->getMaxCharLimit());
99 $text->setMinNumOfChars($this->assignment->getMinCharLimit());
100
101 if ($text->isCharLimited()) {
102 $char_msg = "";
103 if ($this->assignment->getMinCharLimit()) {
104 $char_msg .= $lng->txt("exc_min_char_limit") . ": " . $this->assignment->getMinCharLimit();
105 }
106 if ($this->assignment->getMaxCharLimit()) {
107 $char_msg .= " " . $lng->txt("exc_max_char_limit") . ": " . $this->assignment->getMaxCharLimit();
108 }
109 $text->setInfo($char_msg);
110 }
111
112 $form->addItem($text);
113
114 // custom rte tags
115 $text->setUseRte(true);
116 $text->setRTESupport($this->submission->getUserId(), "exca~", "exc_ass");
117
118 // see ilObjForumGUI
119 $text->disableButtons(array(
120 'charmap',
121 'undo',
122 'redo',
123 'justifyleft',
124 'justifycenter',
125 'justifyright',
126 'justifyfull',
127 'anchor',
128 'fullscreen',
129 'cut',
130 'copy',
131 'paste',
132 'pastetext',
133 'code',
134 // 'formatselect' #13234
135 ));
136
137 $form->setFormAction($ilCtrl->getFormAction($this, "updateAssignmentText"));
138 $form->addCommandButton("updateAssignmentTextAndReturn", $this->lng->txt("save_return"));
139 $form->addCommandButton("updateAssignmentText", $this->lng->txt("save"));
140 $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
141 } else {
142 $form->setFormAction($ilCtrl->getFormAction($this, "returnToParent"));
143 $text = new ilNonEditableValueGUI($this->lng->txt("exc_files_returned_text"), "atxt", true);
144 $form->addItem($text);
145 }
146
147 return $form;
148 }
149
150 public function editAssignmentTextObject(ilPropertyFormGUI $a_form = null)
151 {
154
155 if (!$this->submission->canSubmit()) {
156 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
157 $ilCtrl->redirect($this, "returnToParent");
158 }
159
160 $deadline = max($this->assignment->getDeadline(), $this->assignment->getExtendedDeadline());
161 if ($deadline) {
162 $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
163
164 // extended deadline date should not be presented anywhere
165 // see ilExAssignmentGUI::addSchedule()
166 $dl_info = ilDatePresentation::formatDate(new ilDateTime($deadline, IL_CAL_UNIX));
167
168 // #16151 - extended deadline warning (only after deadline passed)
169 if ($deadline < time()) {
171 $dl = '<br /><span class="warning">' . sprintf($this->lng->txt("exc_late_submission_warning"), $dl) . '</span>';
172 $dl_info .= $dl;
173 }
174
175 ilUtil::sendInfo($this->lng->txt("exc_edit_until") . ": " . $dl_info);
176 }
177
178 $this->handleTabs();
179
180 $ilHelp = $this->help;
181 $ilHelp->setScreenIdComponent("exc");
182 $ilHelp->setScreenId("text_submission");
183
184 if (!$a_form) {
185 $a_form = $this->initAssignmentTextForm();
186
187 $files = $this->submission->getFiles();
188 if ($files) {
189 $files = array_shift($files);
190 if (trim($files["atext"])) {
191 $text = $a_form->getItemByPostVar("atxt");
192 // mob id to mob src
193 $text->setValue(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1));
194 }
195 }
196 }
197
198 $this->tpl->setContent($a_form->getHTML());
199 }
200
202 {
203 $this->updateAssignmentTextObject(true);
204 }
205
206 public function updateAssignmentTextObject($a_return = false)
207 {
209
210 if (!$this->submission->canSubmit()) {
211 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
212 $ilCtrl->redirect($this, "returnToParent");
213 }
214
215 $form = $this->initAssignmentTextForm();
216
217 // we are not using a purifier, so we have to set the valid RTE tags
218 // :TODO:
219 include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
220 $rte = $form->getItemByPostVar("atxt");
221 $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass"));
222
223 if ($form->checkInput()) {
224 $text = trim($form->getInput("atxt"));
225
226 $existing = $this->submission->getFiles();
227
228 $returned_id = $this->submission->updateTextSubmission(
229 // mob src to mob id
231 );
232
233 // no empty text
234 if ($returned_id) {
235 // #16532 - always send notifications
236 $this->handleNewUpload();
237
238 // mob usage
239 include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
241 foreach ($mobs as $mob) {
242 if (ilObjMediaObject::_exists($mob)) {
243 ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
244 ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
245 }
246 }
247 } else {
248 $this->handleRemovedUpload();
249 }
250
251 ilUtil::sendSuccess($this->lng->txt("exc_text_saved"), true);
252 if ($a_return) {
253 $ilCtrl->redirect($this, "returnToParent");
254 } else {
255 $ilCtrl->redirect($this, "editAssignmentText");
256 }
257 }
258
259 $form->setValuesByPost();
261 }
262
263 public function showAssignmentTextObject()
264 {
265 if (!$this->submission->isTutor()) {
266 $this->handleTabs();
267 }
268
269 $a_form = $this->initAssignmentTextForm(true);
270
271 $files = $this->submission->getFiles();
272 if ($files) {
273 $files = array_shift($files);
274 if (trim($files["atext"])) {
275 if ($files["late"] &&
276 !$this->submission->hasPeerReviewAccess()) {
277 ilUtil::sendFailure($this->lng->txt("exc_late_submission"));
278 }
279
280 $text = $a_form->getItemByPostVar("atxt");
281 // mob id to mob src
282 $text->setValue(nl2br(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1)));
283 }
284 }
285
286 $this->tpl->setContent($a_form->getHTML());
287 }
288}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Exercise submission base gui.
handleNewUpload($a_no_notifications=false)
Object-based submissions (ends up as static file)
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
Constructor.
editAssignmentTextObject(ilPropertyFormGUI $a_form=null)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initAssignmentTextForm($a_read_only=false)
Exercise submission //TODO: This class has to much static methods related to delivered "files".
Class ilInfoScreenGUI.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
static getInstance()
Factory.
This class represents a non editable value in a property form.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
Class ilObjExercise.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
This class represents a property form user interface.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
This class represents a text area property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$files
Definition: metarefresh.php:49
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$mobs
$ilUser
Definition: imgupload.php:18
$text
Definition: errorreport.php:18