ILIAS  Release_4_0_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 /*
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  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
144  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
145  $foundvalues = $_POST[$this->getPostVar()];
146  if (is_array($foundvalues))
147  {
148  // check answers
149  if (is_array($foundvalues['term']))
150  {
151  foreach ($foundvalues['term'] as $val)
152  {
153  if ($this->getRequired() && $val < 1)
154  {
155  $this->setAlert($lng->txt("msg_input_is_required"));
156  return FALSE;
157  }
158  }
159  foreach ($foundvalues['definition'] as $val)
160  {
161  if ($this->getRequired() && $val < 1)
162  {
163  $this->setAlert($lng->txt("msg_input_is_required"));
164  return FALSE;
165  }
166  }
167  $max = 0;
168  foreach ($foundvalues['points'] as $val)
169  {
170  if ($val > 0) $max += $val;
171  if ($this->getRequired() && (strlen($val)) == 0)
172  {
173  $this->setAlert($lng->txt("msg_input_is_required"));
174  return FALSE;
175  }
176  }
177  if ($max <= 0)
178  {
179  $this->setAlert($lng->txt("enter_enough_positive_points"));
180  return FALSE;
181  }
182  }
183  else
184  {
185  if ($this->getRequired())
186  {
187  $this->setAlert($lng->txt("msg_input_is_required"));
188  return FALSE;
189  }
190  }
191  }
192  else
193  {
194  if ($this->getRequired())
195  {
196  $this->setAlert($lng->txt("msg_input_is_required"));
197  return FALSE;
198  }
199  }
200  return $this->checkSubItemsInput();
201  }
202 
208  function insert(&$a_tpl)
209  {
210  global $lng;
211 
212  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
213  $i = 0;
214 
215  foreach ($this->pairs as $pair)
216  {
217  $counter = 1;
218  $tpl->setCurrentBlock("option_term");
219  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
220  $tpl->setVariable("VALUE_OPTION", 0);
221  $tpl->parseCurrentBlock();
222  foreach ($this->terms as $term)
223  {
224  $tpl->setCurrentBlock("option_term");
225  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
226  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
227  if ($pair->term->identifier == $term->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
228  $tpl->parseCurrentBlock();
229  $counter++;
230  }
231  $counter = 1;
232  $tpl->setCurrentBlock("option_definition");
233  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
234  $tpl->setVariable("VALUE_OPTION", 0);
235  $tpl->parseCurrentBlock();
236  foreach ($this->definitions as $definition)
237  {
238  $tpl->setCurrentBlock("option_definition");
239  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
240  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
241  if ($pair->definition->identifier == $definition->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
242  $tpl->parseCurrentBlock();
243  $counter++;
244  }
245 
246  if (strlen($pair->points))
247  {
248  $tpl->setCurrentBlock('points_value');
249  $tpl->setVariable('POINTS_VALUE', $pair->points);
250  $tpl->parseCurrentBlock();
251  }
252  if ($this->getAllowMove())
253  {
254  $tpl->setCurrentBlock("move");
255  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
256  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
257  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
258  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
259  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
260  $tpl->parseCurrentBlock();
261  }
262 
263  $tpl->setCurrentBlock("row");
264  $class = ($i % 2 == 0) ? "even" : "odd";
265  if ($i == 0) $class .= " first";
266  if ($i == count($this->values)-1) $class .= " last";
267  $tpl->setVariable("ROW_CLASS", $class);
268  $tpl->setVariable("ROW_NUMBER", $i);
269 
270  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
271  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
272  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
273  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
274  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
275 
276  $tpl->setVariable("POST_VAR", $this->getPostVar());
277 
278  $tpl->parseCurrentBlock();
279 
280  $i++;
281  }
282 
283  $tpl->setCurrentBlock('term_ids');
284  $ids = array();
285  foreach ($this->terms as $term)
286  {
287  array_push($ids, $term->identifier);
288  }
289  $tpl->setVariable("POST_VAR", $this->getPostVar());
290  $tpl->setVariable("TERM_IDS", join($ids, ","));
291  $tpl->parseCurrentBlock();
292 
293  $tpl->setCurrentBlock('definition_ids');
294  $ids = array();
295  foreach ($this->definitions as $definition)
296  {
297  array_push($ids, $definition->identifier);
298  }
299  $tpl->setVariable("POST_VAR", $this->getPostVar());
300  $tpl->setVariable("DEFINITION_IDS", join($ids, ","));
301  $tpl->parseCurrentBlock();
302 
303  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
304  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
305  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
306  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
307 
308  $a_tpl->setCurrentBlock("prop_generic");
309  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
310  $a_tpl->parseCurrentBlock();
311 
312  global $tpl;
313  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
315  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
316  }
317 }