ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
12 {
13  protected $pairs = array();
14  protected $allowMove = false;
15  protected $terms = array();
16  protected $definitions = array();
17 
24  function __construct($a_title = "", $a_postvar = "")
25  {
26  parent::__construct($a_title, $a_postvar);
27  }
28 
34  function setValue($a_value)
35  {
36  $this->pairs = array();
37  $this->terms = array();
38  $this->definitions = array();
39  if (is_array($a_value))
40  {
41  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
42  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
43  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
44  if (is_array($a_value['term']))
45  {
46  foreach ($a_value['term'] as $idx => $term)
47  {
48  array_push($this->pairs, new assAnswerMatchingPair(new assAnswerMatchingTerm('', '', $term), new assAnswerMatchingDefinition('', '', $a_value['definition'][$idx]), $a_value['points'][$idx]));
49  }
50  }
51  $term_ids = split(",", $a_value['term_id']);
52  foreach ($term_ids as $id)
53  {
54  array_push($this->terms, new assAnswerMatchingTerm('', '', $id));
55  }
56  $definition_ids = split(",", $a_value['definition_id']);
57  foreach ($definition_ids as $id)
58  {
59  array_push($this->definitions, new assAnswerMatchingDefinition('', '', $id));
60  }
61  }
62  }
63 
69  function setTerms($a_terms)
70  {
71  $this->terms = $a_terms;
72  }
73 
79  function setDefinitions($a_definitions)
80  {
81  $this->definitions = $a_definitions;
82  }
83 
89  function setPairs($a_pairs)
90  {
91  $this->pairs = $a_pairs;
92  }
93 
99  function setAllowMove($a_allow_move)
100  {
101  $this->allowMove = $a_allow_move;
102  }
103 
109  function getAllowMove()
110  {
111  return $this->allowMove;
112  }
113 
119  function checkInput()
120  {
121  global $lng;
122 
123  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
124  $foundvalues = $_POST[$this->getPostVar()];
125  if (is_array($foundvalues))
126  {
127  // check answers
128  if (is_array($foundvalues['term']))
129  {
130  foreach ($foundvalues['term'] as $val)
131  {
132  if ($this->getRequired() && $val < 1)
133  {
134  $this->setAlert($lng->txt("msg_input_is_required"));
135  return FALSE;
136  }
137  }
138  foreach ($foundvalues['definition'] as $val)
139  {
140  if ($this->getRequired() && $val < 1)
141  {
142  $this->setAlert($lng->txt("msg_input_is_required"));
143  return FALSE;
144  }
145  }
146  $max = 0;
147  foreach ($foundvalues['points'] as $val)
148  {
149  if ($val > 0) $max += $val;
150  if ($this->getRequired() && (strlen($val)) == 0)
151  {
152  $this->setAlert($lng->txt("msg_input_is_required"));
153  return FALSE;
154  }
155  }
156  if ($max <= 0)
157  {
158  $this->setAlert($lng->txt("enter_enough_positive_points"));
159  return FALSE;
160  }
161  }
162  else
163  {
164  if ($this->getRequired())
165  {
166  $this->setAlert($lng->txt("msg_input_is_required"));
167  return FALSE;
168  }
169  }
170  }
171  else
172  {
173  if ($this->getRequired())
174  {
175  $this->setAlert($lng->txt("msg_input_is_required"));
176  return FALSE;
177  }
178  }
179  return $this->checkSubItemsInput();
180  }
181 
187  function insert(&$a_tpl)
188  {
189  global $lng;
190 
191  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
192  $i = 0;
193 
194  foreach ($this->pairs as $pair)
195  {
196  $counter = 1;
197  $tpl->setCurrentBlock("option_term");
198  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
199  $tpl->setVariable("VALUE_OPTION", 0);
200  $tpl->parseCurrentBlock();
201  foreach ($this->terms as $term)
202  {
203  $tpl->setCurrentBlock("option_term");
204  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
205  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
206  if ($pair->term->identifier == $term->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
207  $tpl->parseCurrentBlock();
208  $counter++;
209  }
210  $counter = 1;
211  $tpl->setCurrentBlock("option_definition");
212  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
213  $tpl->setVariable("VALUE_OPTION", 0);
214  $tpl->parseCurrentBlock();
215  foreach ($this->definitions as $definition)
216  {
217  $tpl->setCurrentBlock("option_definition");
218  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
219  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
220  if ($pair->definition->identifier == $definition->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
221  $tpl->parseCurrentBlock();
222  $counter++;
223  }
224 
225  if (strlen($pair->points))
226  {
227  $tpl->setCurrentBlock('points_value');
228  $tpl->setVariable('POINTS_VALUE', $pair->points);
229  $tpl->parseCurrentBlock();
230  }
231  if ($this->getAllowMove())
232  {
233  $tpl->setCurrentBlock("move");
234  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
235  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
236  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
237  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
238  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
239  $tpl->parseCurrentBlock();
240  }
241 
242  $tpl->setCurrentBlock("row");
243  $class = ($i % 2 == 0) ? "even" : "odd";
244  if ($i == 0) $class .= " first";
245  if ($i == count($this->values)-1) $class .= " last";
246  $tpl->setVariable("ROW_CLASS", $class);
247  $tpl->setVariable("ROW_NUMBER", $i);
248 
249  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
250  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
251  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
252  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
253  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
254 
255  $tpl->setVariable("POST_VAR", $this->getPostVar());
256 
257  $tpl->parseCurrentBlock();
258 
259  $i++;
260  }
261 
262  $tpl->setCurrentBlock('term_ids');
263  $ids = array();
264  foreach ($this->terms as $term)
265  {
266  array_push($ids, $term->identifier);
267  }
268  $tpl->setVariable("POST_VAR", $this->getPostVar());
269  $tpl->setVariable("TERM_IDS", join($ids, ","));
270  $tpl->parseCurrentBlock();
271 
272  $tpl->setCurrentBlock('definition_ids');
273  $ids = array();
274  foreach ($this->definitions as $definition)
275  {
276  array_push($ids, $definition->identifier);
277  }
278  $tpl->setVariable("POST_VAR", $this->getPostVar());
279  $tpl->setVariable("DEFINITION_IDS", join($ids, ","));
280  $tpl->parseCurrentBlock();
281 
282  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
283  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
284  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
285  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
286 
287  $a_tpl->setCurrentBlock("prop_generic");
288  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
289  $a_tpl->parseCurrentBlock();
290 
291  global $tpl;
292  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
294  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
295  }
296 }