ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilKprimChoiceCorrectionsInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
15  public function setValue($a_value)
16  {
17  if (is_array($a_value) && is_array($a_value['correctness'])) {
18  foreach ($this->values as $index => $value) {
19  if (isset($a_value['correctness'][$index])) {
20  $this->values[$index]->setCorrectness((bool) $a_value['correctness'][$index]);
21  } else {
22  $this->values[$index]->setCorrectness(null);
23  }
24  }
25  }
26  }
27 
28  public function checkInput()
29  {
30  global $DIC;
31  $lng = $DIC['lng'];
32 
33  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
34  if (is_array($_POST[$this->getPostVar()])) {
36  $_POST[$this->getPostVar()],
37  false,
39  );
40  }
41 
42  $foundvalues = $_POST[$this->getPostVar()];
43 
44  if (is_array($foundvalues)) {
45  // check correctness
46  if (!isset($foundvalues['correctness']) || count($foundvalues['correctness']) < count($this->values)) {
47  $this->setAlert($lng->txt("msg_input_is_required"));
48  return false;
49  }
50  } else {
51  $this->setAlert($lng->txt("msg_input_is_required"));
52  return false;
53  }
54 
55  return $this->checkSubItemsInput();
56  }
57 
58  public function insert($a_tpl)
59  {
60  $tpl = new ilTemplate("tpl.prop_kprimchoicecorrection_input.html", true, true, "Modules/TestQuestionPool");
61 
62  foreach ($this->values as $value) {
67  if (strlen($value->getImageFile())) {
68  $imagename = $value->getImageWebPath();
69 
70  if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
71  if (@file_exists($value->getThumbFsPath())) {
72  $imagename = $value->getThumbWebPath();
73  }
74  }
75 
76  $tpl->setCurrentBlock('image');
77  $tpl->setVariable('SRC_IMAGE', $imagename);
78  $tpl->setVariable('IMAGE_NAME', $value->getImageFile());
79  $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->getAnswertext()));
80  $tpl->parseCurrentBlock();
81  }
82 
83  $tpl->setCurrentBlock("row");
84 
85  $tpl->setVariable("ANSWER", $value->getAnswertext());
86 
87  $tpl->setVariable("POST_VAR", $this->getPostVar());
88  $tpl->setVariable("ROW_NUMBER", $value->getPosition());
89  $tpl->setVariable("ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
90 
91  $tpl->setVariable(
92  "CORRECTNESS_TRUE_ID",
93  $this->getPostVar() . "[correctness][{$value->getPosition()}][true]"
94  );
95  $tpl->setVariable(
96  "CORRECTNESS_FALSE_ID",
97  $this->getPostVar() . "[correctness][{$value->getPosition()}][false]"
98  );
99  $tpl->setVariable("CORRECTNESS_TRUE_VALUE", 1);
100  $tpl->setVariable("CORRECTNESS_FALSE_VALUE", 0);
101 
102  if ($value->getCorrectness() !== null) {
103  if ($value->getCorrectness()) {
104  $tpl->setVariable('CORRECTNESS_TRUE_SELECTED', ' checked="checked"');
105  } else {
106  $tpl->setVariable('CORRECTNESS_FALSE_SELECTED', ' checked="checked"');
107  }
108  }
109 
110  if ($this->getDisabled()) {
111  $tpl->setVariable("DISABLED_CORRECTNESS", " disabled=\"disabled\"");
112  }
113 
114  $tpl->parseCurrentBlock();
115  }
116 
117  $tpl->setVariable("TRUE_TEXT", $this->qstObject->getTrueOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
118  $tpl->setVariable("FALSE_TEXT", $this->qstObject->getFalseOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
119 
120  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
121  $tpl->setVariable("DELETE_IMAGE_HEADER", $this->lng->txt('delete_image_header'));
122  $tpl->setVariable("DELETE_IMAGE_QUESTION", $this->lng->txt('delete_image_question'));
123  $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer'));
124 
125  $tpl->setVariable("OPTIONS_TEXT", $this->lng->txt('options'));
126 
127  $a_tpl->setCurrentBlock("prop_generic");
128  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
129  $a_tpl->parseCurrentBlock();
130  }
131 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
global $DIC
Definition: saml.php:7
getPostVar()
Get Post Variable.
$index
Definition: metadata.php:60
setAlert($a_alert)
Set Alert Text.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
$_POST["username"]