ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMatchingPairWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5 
14 {
15  protected $pairs = array();
16  protected $allowMove = false;
17  protected $terms = array();
18  protected $definitions = array();
19 
26  public function __construct($a_title = "", $a_postvar = "")
27  {
28  parent::__construct($a_title, $a_postvar);
29  }
30 
36  public function setValue($a_value)
37  {
38  $this->pairs = array();
39  $this->terms = array();
40  $this->definitions = array();
41  if (is_array($a_value)) {
42  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
43  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
44  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
45  if (is_array($a_value['term'])) {
46  foreach ($a_value['term'] as $idx => $term) {
47  array_push($this->pairs, new assAnswerMatchingPair(new assAnswerMatchingTerm('', '', $term), new assAnswerMatchingDefinition('', '', $a_value['definition'][$idx]), $a_value['points'][$idx]));
48  }
49  }
50  $term_ids = explode(",", $a_value['term_id']);
51  foreach ($term_ids as $id) {
52  array_push($this->terms, new assAnswerMatchingTerm('', '', $id));
53  }
54  $definition_ids = explode(",", $a_value['definition_id']);
55  foreach ($definition_ids as $id) {
56  array_push($this->definitions, new assAnswerMatchingDefinition('', '', $id));
57  }
58  }
59  }
60 
66  public function setTerms($a_terms)
67  {
68  $this->terms = $a_terms;
69  }
70 
76  public function setDefinitions($a_definitions)
77  {
78  $this->definitions = $a_definitions;
79  }
80 
86  public function setPairs($a_pairs)
87  {
88  $this->pairs = $a_pairs;
89  }
90 
96  public function setAllowMove($a_allow_move)
97  {
98  $this->allowMove = $a_allow_move;
99  }
100 
106  public function getAllowMove()
107  {
108  return $this->allowMove;
109  }
110 
116  public function checkInput()
117  {
118  global $DIC;
119  $lng = $DIC['lng'];
120 
121  if (is_array($_POST[$this->getPostVar()])) {
123  }
124  $foundvalues = $_POST[$this->getPostVar()];
125  if (is_array($foundvalues)) {
126  // check answers
127  if (is_array($foundvalues['term'])) {
128  foreach ($foundvalues['term'] as $val) {
129  if ($this->getRequired() && $val < 1) {
130  $this->setAlert($lng->txt("msg_input_is_required"));
131  return false;
132  }
133  }
134  foreach ($foundvalues['definition'] as $val) {
135  if ($this->getRequired() && $val < 1) {
136  $this->setAlert($lng->txt("msg_input_is_required"));
137  return false;
138  }
139  }
140  $max = 0;
141  foreach ($foundvalues['points'] as $val) {
142  if ($val > 0) {
143  $max += $val;
144  }
145  if ($this->getRequired() && (strlen($val)) == 0) {
146  $this->setAlert($lng->txt("msg_input_is_required"));
147  return false;
148  }
149  }
150  if ($max <= 0) {
151  $this->setAlert($lng->txt("enter_enough_positive_points"));
152  return false;
153  }
154  } else {
155  if ($this->getRequired()) {
156  $this->setAlert($lng->txt("msg_input_is_required"));
157  return false;
158  }
159  }
160  } else {
161  if ($this->getRequired()) {
162  $this->setAlert($lng->txt("msg_input_is_required"));
163  return false;
164  }
165  }
166  return $this->checkSubItemsInput();
167  }
168 
174  public function insert($a_tpl)
175  {
176  global $DIC;
177  $lng = $DIC['lng'];
178 
179  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
180  $i = 0;
181 
182  foreach ($this->pairs as $pair) {
183  $counter = 1;
184  $tpl->setCurrentBlock("option_term");
185  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
186  $tpl->setVariable("VALUE_OPTION", 0);
187  $tpl->parseCurrentBlock();
188  foreach ($this->terms as $term) {
189  $tpl->setCurrentBlock("option_term");
190  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
191  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
192  if ($pair->term->identifier == $term->identifier) {
193  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
194  }
195  $tpl->parseCurrentBlock();
196  $counter++;
197  }
198  $counter = 1;
199  $tpl->setCurrentBlock("option_definition");
200  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
201  $tpl->setVariable("VALUE_OPTION", 0);
202  $tpl->parseCurrentBlock();
203  foreach ($this->definitions as $definition) {
204  $tpl->setCurrentBlock("option_definition");
205  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
206  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
207  if ($pair->definition->identifier == $definition->identifier) {
208  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
209  }
210  $tpl->parseCurrentBlock();
211  $counter++;
212  }
213 
214  if (strlen($pair->points)) {
215  $tpl->setCurrentBlock('points_value');
216  $tpl->setVariable('POINTS_VALUE', $pair->points);
217  $tpl->parseCurrentBlock();
218  }
219  if ($this->getAllowMove()) {
220  $tpl->setCurrentBlock("move");
221  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
222  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
223  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
224  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
225  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
226  $tpl->parseCurrentBlock();
227  }
228 
229  $tpl->setCurrentBlock("row");
230  $tpl->setVariable("ROW_NUMBER", $i);
231 
232  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
233  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
234  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
235  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
236  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
237 
238  $tpl->setVariable("POST_VAR", $this->getPostVar());
239 
240  $tpl->parseCurrentBlock();
241 
242  $i++;
243  }
244 
245  $tpl->setCurrentBlock('term_ids');
246  $ids = array();
247  foreach ($this->terms as $term) {
248  array_push($ids, $term->identifier);
249  }
250  $tpl->setVariable("POST_VAR", $this->getPostVar());
251  $tpl->setVariable("TERM_IDS", join(",", $ids));
252  $tpl->parseCurrentBlock();
253 
254  $tpl->setCurrentBlock('definition_ids');
255  $ids = array();
256  foreach ($this->definitions as $definition) {
257  array_push($ids, $definition->identifier);
258  }
259  $tpl->setVariable("POST_VAR", $this->getPostVar());
260  $tpl->setVariable("DEFINITION_IDS", join(",", $ids));
261  $tpl->parseCurrentBlock();
262 
263  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
264  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
265  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
266  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
267  $tpl->setVariable("TEXT_ACTIONS", $lng->txt('actions'));
268 
269  $a_tpl->setCurrentBlock("prop_generic");
270  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
271  $a_tpl->parseCurrentBlock();
272 
273  global $DIC;
274  $tpl = $DIC['tpl'];
275  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
276  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
277  }
278 }
Class for matching question terms.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
setDefinitions($a_definitions)
Set definitions.
Class for matching question pairs.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
setAllowMove($a_allow_move)
Set allow move.
if(!array_key_exists('StateId', $_REQUEST)) $id
static get($a_glyph, $a_text="")
Get glyph html.
setAlert($a_alert)
Set Alert Text.
checkInput()
Check input, strip slashes etc.
getFieldId()
Get Post Variable.
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.
This class represents a text property in a property form.
$i
Definition: disco.tpl.php:19
Class for matching question definitions.
$_POST["username"]
This class represents a key value pair wizard property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.