ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
14 public function executeCommand()
15 {
16 global $ilCtrl;
17
18 if(!$this->assignment ||
19 $this->assignment->getType() != ilExAssignment::TYPE_TEXT ||
20 !$this->submission->canView())
21 {
22 return;
23 }
24
25 $class = $ilCtrl->getNextClass($this);
26 $cmd = $ilCtrl->getCmd("showassignmenttext");
27
28 switch($class)
29 {
30 default:
31 $this->{$cmd."Object"}();
32 break;
33 }
34 }
35
36 public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
37 {
38 global $lng, $ilCtrl;
39
40 if($a_submission->canSubmit())
41 {
42 $button = ilLinkButton::getInstance();
43 $button->setPrimary(true);
44 $button->setCaption("exc_text_assignment_edit");
45 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "editAssignmentText"));
46 $files_str = $button->render();
47 }
48 else
49 {
50 $button = ilLinkButton::getInstance();
51 $button->setCaption("exc_text_assignment_show");
52 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTextGUI"), "showAssignmentText"));
53 $files_str = $button->render();
54 }
55
56 $a_info->addProperty($lng->txt("exc_files_returned_text"), $files_str);
57 }
58
59
60 //
61 // TEXT ASSIGNMENT (EDIT)
62 //
63
64 protected function initAssignmentTextForm($a_read_only = false)
65 {
66 global $ilCtrl;
67
68 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
69 $form = new ilPropertyFormGUI();
70 $form->setTitle($this->lng->txt("exc_assignment")." \"".$this->assignment->getTitle()."\"");
71
72 if(!$a_read_only)
73 {
74 $text = new ilTextAreaInputGUI($this->lng->txt("exc_your_text"), "atxt");
75 $text->setRequired((bool)$this->submission->getAssignment()->getMandatory());
76 $text->setRows(40);
77 $form->addItem($text);
78
79 // custom rte tags
80 $text->setUseRte(true);
81 $text->setRTESupport($this->submission->getUserId(), "exca~", "exc_ass");
82
83 // see ilObjForumGUI
84 $text->disableButtons(array(
85 'charmap',
86 'undo',
87 'redo',
88 'justifyleft',
89 'justifycenter',
90 'justifyright',
91 'justifyfull',
92 'anchor',
93 'fullscreen',
94 'cut',
95 'copy',
96 'paste',
97 'pastetext',
98 // 'formatselect' #13234
99 ));
100
101 $form->setFormAction($ilCtrl->getFormAction($this, "updateAssignmentText"));
102 $form->addCommandButton("updateAssignmentTextAndReturn", $this->lng->txt("save_return"));
103 $form->addCommandButton("updateAssignmentText", $this->lng->txt("save"));
104 }
105 else
106 {
107 $form->setFormAction($ilCtrl->getFormAction($this, "returnToParent"));
108 $text = new ilNonEditableValueGUI($this->lng->txt("exc_files_returned_text"), "atxt", true);
109 $form->addItem($text);
110 }
111 $form->addCommandButton("returnToParent", $this->lng->txt("cancel"));
112
113 return $form;
114 }
115
117 {
118 global $ilCtrl, $ilUser;
119
120 if(!$this->submission->canSubmit())
121 {
122 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
123 $ilCtrl->redirect($this, "returnToParent");
124 }
125
126 $deadline = max($this->assignment->getDeadline(), $this->assignment->getExtendedDeadline());
127 if($deadline)
128 {
129 $deadline = $this->assignment->getPersonalDeadline($ilUser->getId());
130
131 // extended deadline date should not be presented anywhere
132 // see ilExAssignmentGUI::addSchedule()
133 $dl_info = ilDatePresentation::formatDate(new ilDateTime($deadline, IL_CAL_UNIX));
134
135 // #16151 - extended deadline warning (only after deadline passed)
136 if($deadline < time())
137 {
139 $dl = '<br /><span class="warning">'.sprintf($this->lng->txt("exc_late_submission_warning"), $dl).'</span>';
140 $dl_info .= $dl;
141 }
142
143 ilUtil::sendInfo($this->lng->txt("exc_edit_until").": ".$dl_info);
144 }
145
146 $this->handleTabs();
147
148 global $ilHelp;
149 $ilHelp->setScreenIdComponent("exc");
150 $ilHelp->setScreenId("text_submission");
151
152 if(!$a_form)
153 {
154 $a_form = $this->initAssignmentTextForm();
155
156 $files = $this->submission->getFiles();
157 if($files)
158 {
159 $files = array_shift($files);
160 if(trim($files["atext"]))
161 {
162 $text = $a_form->getItemByPostVar("atxt");
163 // mob id to mob src
164 $text->setValue(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1));
165 }
166 }
167 }
168
169 $this->tpl->setContent($a_form->getHTML());
170 }
171
173 {
174 $this->updateAssignmentTextObject(true);
175 }
176
177 function updateAssignmentTextObject($a_return = false)
178 {
179 global $ilCtrl;
180
181 if(!$this->submission->canSubmit())
182 {
183 ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
184 $ilCtrl->redirect($this, "returnToParent");
185 }
186
187 $form = $this->initAssignmentTextForm();
188
189 // we are not using a purifier, so we have to set the valid RTE tags
190 // :TODO:
191 include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
192 $rte = $form->getItemByPostVar("atxt");
193 $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass"));
194
195 if($form->checkInput())
196 {
197 $text = trim($form->getInput("atxt"));
198
199 $existing = $this->submission->getFiles();
200
201 $returned_id = $this->submission->updateTextSubmission(
202 // mob src to mob id
204
205 // no empty text
206 if($returned_id)
207 {
208 // #16532 - always send notifications
209 $this->handleNewUpload();
210
211 // mob usage
212 include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
214 foreach($mobs as $mob)
215 {
217 {
218 ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
219 ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
220 }
221 }
222 }
223 else
224 {
225 $this->handleRemovedUpload();
226 }
227
228 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
229 if($a_return)
230 {
231 $ilCtrl->redirect($this, "returnToParent");
232 }
233 else
234 {
235 $ilCtrl->redirect($this, "editAssignmentText");
236 }
237 }
238
239 $form->setValuesByPost();
240 $this->editAssignmentTextObject($form);
241 }
242
244 {
245 if(!$this->submission->isTutor())
246 {
247 $this->handleTabs();
248 }
249
250 $a_form = $this->initAssignmentTextForm(true);
251
252 $files = $this->submission->getFiles();
253 if($files)
254 {
255 $files = array_shift($files);
256 if(trim($files["atext"]))
257 {
258 if($files["late"] &&
259 !$this->submission->hasPeerReviewAccess())
260 {
261 ilUtil::sendFailure($this->lng->txt("exc_late_submission"));
262 }
263
264 $text = $a_form->getItemByPostVar("atxt");
265 // mob id to mob src
266 $text->setValue(nl2br(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1)));
267 }
268 }
269
270 $this->tpl->setContent($a_form->getHTML());
271 }
272}
$files
Definition: add-vimline.php:18
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static formatDate(ilDateTime $date)
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)
editAssignmentTextObject(ilPropertyFormGUI $a_form=null)
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initAssignmentTextForm($a_read_only=false)
Exercise submission.
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.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$text
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$mobs
$ilUser
Definition: imgupload.php:18