ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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;
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  // extended deadline date should not be presented anywhere
130  // see ilExAssignmentGUI::addSchedule()
131  $dl_info = ilDatePresentation::formatDate(new ilDateTime($this->assignment->getDeadline(), IL_CAL_UNIX));
132 
133  // #16151 - extended deadline warning (only after deadline passed)
134  if($this->assignment->getDeadline() < time())
135  {
136  $dl = ilDatePresentation::formatDate(new ilDateTime($this->assignment->getDeadline(),IL_CAL_UNIX));
137  $dl = '<br /><span class="warning">'.sprintf($this->lng->txt("exc_late_submission_warning"), $dl).'</span>';
138  $dl_info .= $dl;
139  }
140 
141  ilUtil::sendInfo($this->lng->txt("exc_edit_until").": ".$dl_info);
142  }
143 
144  $this->handleTabs();
145 
146  global $ilHelp;
147  $ilHelp->setScreenIdComponent("exc");
148  $ilHelp->setScreenId("text_submission");
149 
150  if(!$a_form)
151  {
152  $a_form = $this->initAssignmentTextForm();
153 
154  $files = $this->submission->getFiles();
155  if($files)
156  {
157  $files = array_shift($files);
158  if(trim($files["atext"]))
159  {
160  $text = $a_form->getItemByPostVar("atxt");
161  // mob id to mob src
162  $text->setValue(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1));
163  }
164  }
165  }
166 
167  $this->tpl->setContent($a_form->getHTML());
168  }
169 
171  {
172  $this->updateAssignmentTextObject(true);
173  }
174 
175  function updateAssignmentTextObject($a_return = false)
176  {
177  global $ilCtrl;
178 
179  if(!$this->submission->canSubmit())
180  {
181  ilUtil::sendFailure($this->lng->txt("exercise_time_over"), true);
182  $ilCtrl->redirect($this, "returnToParent");
183  }
184 
185  $form = $this->initAssignmentTextForm();
186 
187  // we are not using a purifier, so we have to set the valid RTE tags
188  // :TODO:
189  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
190  $rte = $form->getItemByPostVar("atxt");
191  $rte->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("exc_ass"));
192 
193  if($form->checkInput())
194  {
195  $text = trim($form->getInput("atxt"));
196 
197  $existing = $this->submission->getFiles();
198 
199  $returned_id = $this->submission->updateTextSubmission(
200  // mob src to mob id
202 
203  // no empty text
204  if($returned_id)
205  {
206  // #16532 - always send notifications
207  $this->handleNewUpload();
208 
209  // mob usage
210  include_once "Services/MediaObjects/classes/class.ilObjMediaObject.php";
212  foreach($mobs as $mob)
213  {
214  if(ilObjMediaObject::_exists($mob))
215  {
216  ilObjMediaObject::_removeUsage($mob, 'exca~:html', $this->submission->getUserId());
217  ilObjMediaObject::_saveUsage($mob, 'exca:html', $returned_id);
218  }
219  }
220  }
221  else
222  {
223  $this->handleRemovedUpload();
224  }
225 
226  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
227  if($a_return)
228  {
229  $ilCtrl->redirect($this, "returnToParent");
230  }
231  else
232  {
233  $ilCtrl->redirect($this, "editAssignmentText");
234  }
235  }
236 
237  $form->setValuesByPost();
238  $this->editAssignmentTextObject($form);
239  }
240 
242  {
243  if(!$this->submission->isTutor())
244  {
245  $this->handleTabs();
246  }
247 
248  $a_form = $this->initAssignmentTextForm(true);
249 
250  $files = $this->submission->getFiles();
251  if($files)
252  {
253  $files = array_shift($files);
254  if(trim($files["atext"]))
255  {
256  if($files["late"] &&
257  !$this->submission->hasPeerReviewAccess())
258  {
259  ilUtil::sendFailure($this->lng->txt("exc_late_submission"));
260  }
261 
262  $text = $a_form->getItemByPostVar("atxt");
263  // mob id to mob src
264  $text->setValue(nl2br(ilRTE::_replaceMediaObjectImageSrc($files["atext"], 1)));
265  }
266  }
267 
268  $this->tpl->setContent($a_form->getHTML());
269  }
270 }
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilInfoScreenGUI.
This class represents a property form user interface.
Exercise submission base gui.
$cmd
Definition: sahs_server.php:35
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
initAssignmentTextForm($a_read_only=false)
const IL_CAL_UNIX
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...
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
handleNewUpload($a_no_notifications=false)
$mobs
static _exists($a_id)
checks wether a lm content object with specified id exists or not
editAssignmentTextObject(ilPropertyFormGUI $a_form=null)
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a non editable value in a property form.
& _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
addProperty($a_name, $a_value, $a_link="")
add a property to current section
global $lng
Definition: privfeed.php:40
This class represents a text area property in a property form.
$text
Exercise submission.
Object-based submissions (ends up as static file)