ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMatchingPairWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $pairs = array();
34  protected $allowMove = false;
35  protected $terms = array();
36  protected $definitions = array();
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  }
48 
54  function setValue($a_value)
55  {
56  $this->pairs = array();
57  $this->terms = array();
58  $this->definitions = array();
59  if (is_array($a_value))
60  {
61  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
62  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
63  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
64  if (is_array($a_value['term']))
65  {
66  foreach ($a_value['term'] as $idx => $term)
67  {
68  array_push($this->pairs, new assAnswerMatchingPair(new assAnswerMatchingTerm('', '', $term), new assAnswerMatchingDefinition('', '', $a_value['definition'][$idx]), $a_value['points'][$idx]));
69  }
70  }
71  $term_ids = split(",", $a_value['term_id']);
72  foreach ($term_ids as $id)
73  {
74  array_push($this->terms, new assAnswerMatchingTerm('', '', $id));
75  }
76  $definition_ids = split(",", $a_value['definition_id']);
77  foreach ($definition_ids as $id)
78  {
79  array_push($this->definitions, new assAnswerMatchingDefinition('', '', $id));
80  }
81  }
82  }
83 
89  function setTerms($a_terms)
90  {
91  $this->terms = $a_terms;
92  }
93 
99  function setDefinitions($a_definitions)
100  {
101  $this->definitions = $a_definitions;
102  }
103 
109  function setPairs($a_pairs)
110  {
111  $this->pairs = $a_pairs;
112  }
113 
119  function setAllowMove($a_allow_move)
120  {
121  $this->allowMove = $a_allow_move;
122  }
123 
129  function getAllowMove()
130  {
131  return $this->allowMove;
132  }
133 
139  function checkInput()
140  {
141  global $lng;
142 
143  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
144  $foundvalues = $_POST[$this->getPostVar()];
145  if (is_array($foundvalues))
146  {
147  // check answers
148  if (is_array($foundvalues['term']))
149  {
150  foreach ($foundvalues['term'] as $val)
151  {
152  if ($this->getRequired() && $val < 1)
153  {
154  $this->setAlert($lng->txt("msg_input_is_required"));
155  return FALSE;
156  }
157  }
158  foreach ($foundvalues['definition'] as $val)
159  {
160  if ($this->getRequired() && $val < 1)
161  {
162  $this->setAlert($lng->txt("msg_input_is_required"));
163  return FALSE;
164  }
165  }
166  $max = 0;
167  foreach ($foundvalues['points'] as $val)
168  {
169  if ($val > 0) $max += $val;
170  if ($this->getRequired() && (strlen($val)) == 0)
171  {
172  $this->setAlert($lng->txt("msg_input_is_required"));
173  return FALSE;
174  }
175  }
176  if ($max <= 0)
177  {
178  $this->setAlert($lng->txt("enter_enough_positive_points"));
179  return FALSE;
180  }
181  }
182  else
183  {
184  if ($this->getRequired())
185  {
186  $this->setAlert($lng->txt("msg_input_is_required"));
187  return FALSE;
188  }
189  }
190  }
191  else
192  {
193  if ($this->getRequired())
194  {
195  $this->setAlert($lng->txt("msg_input_is_required"));
196  return FALSE;
197  }
198  }
199  return $this->checkSubItemsInput();
200  }
201 
207  function insert(&$a_tpl)
208  {
209  global $lng;
210 
211  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
212  $i = 0;
213 
214  foreach ($this->pairs as $pair)
215  {
216  $counter = 1;
217  $tpl->setCurrentBlock("option_term");
218  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
219  $tpl->setVariable("VALUE_OPTION", 0);
220  $tpl->parseCurrentBlock();
221  foreach ($this->terms as $term)
222  {
223  $tpl->setCurrentBlock("option_term");
224  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
225  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
226  if ($pair->term->identifier == $term->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
227  $tpl->parseCurrentBlock();
228  $counter++;
229  }
230  $counter = 1;
231  $tpl->setCurrentBlock("option_definition");
232  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
233  $tpl->setVariable("VALUE_OPTION", 0);
234  $tpl->parseCurrentBlock();
235  foreach ($this->definitions as $definition)
236  {
237  $tpl->setCurrentBlock("option_definition");
238  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
239  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
240  if ($pair->definition->identifier == $definition->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
241  $tpl->parseCurrentBlock();
242  $counter++;
243  }
244 
245  if (strlen($pair->points))
246  {
247  $tpl->setCurrentBlock('points_value');
248  $tpl->setVariable('POINTS_VALUE', $pair->points);
249  $tpl->parseCurrentBlock();
250  }
251  if ($this->getAllowMove())
252  {
253  $tpl->setCurrentBlock("move");
254  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
255  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
256  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
257  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
258  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
259  $tpl->parseCurrentBlock();
260  }
261 
262  $tpl->setCurrentBlock("row");
263  $class = ($i % 2 == 0) ? "even" : "odd";
264  if ($i == 0) $class .= " first";
265  if ($i == count($this->values)-1) $class .= " last";
266  $tpl->setVariable("ROW_CLASS", $class);
267  $tpl->setVariable("ROW_NUMBER", $i);
268 
269  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
270  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
271  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
272  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
273  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
274 
275  $tpl->setVariable("POST_VAR", $this->getPostVar());
276 
277  $tpl->parseCurrentBlock();
278 
279  $i++;
280  }
281 
282  $tpl->setCurrentBlock('term_ids');
283  $ids = array();
284  foreach ($this->terms as $term)
285  {
286  array_push($ids, $term->identifier);
287  }
288  $tpl->setVariable("POST_VAR", $this->getPostVar());
289  $tpl->setVariable("TERM_IDS", join($ids, ","));
290  $tpl->parseCurrentBlock();
291 
292  $tpl->setCurrentBlock('definition_ids');
293  $ids = array();
294  foreach ($this->definitions as $definition)
295  {
296  array_push($ids, $definition->identifier);
297  }
298  $tpl->setVariable("POST_VAR", $this->getPostVar());
299  $tpl->setVariable("DEFINITION_IDS", join($ids, ","));
300  $tpl->parseCurrentBlock();
301 
302  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
303  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
304  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
305  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
306 
307  $a_tpl->setCurrentBlock("prop_generic");
308  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
309  $a_tpl->parseCurrentBlock();
310 
311  global $tpl;
312  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
314  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
315  }
316 }