ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng;
119 
120  if (is_array($_POST[$this->getPostVar()])) {
122  }
123  $foundvalues = $_POST[$this->getPostVar()];
124  if (is_array($foundvalues)) {
125  // check answers
126  if (is_array($foundvalues['term'])) {
127  foreach ($foundvalues['term'] as $val) {
128  if ($this->getRequired() && $val < 1) {
129  $this->setAlert($lng->txt("msg_input_is_required"));
130  return false;
131  }
132  }
133  foreach ($foundvalues['definition'] as $val) {
134  if ($this->getRequired() && $val < 1) {
135  $this->setAlert($lng->txt("msg_input_is_required"));
136  return false;
137  }
138  }
139  $max = 0;
140  foreach ($foundvalues['points'] as $val) {
141  if ($val > 0) {
142  $max += $val;
143  }
144  if ($this->getRequired() && (strlen($val)) == 0) {
145  $this->setAlert($lng->txt("msg_input_is_required"));
146  return false;
147  }
148  }
149  if ($max <= 0) {
150  $this->setAlert($lng->txt("enter_enough_positive_points"));
151  return false;
152  }
153  } else {
154  if ($this->getRequired()) {
155  $this->setAlert($lng->txt("msg_input_is_required"));
156  return false;
157  }
158  }
159  } else {
160  if ($this->getRequired()) {
161  $this->setAlert($lng->txt("msg_input_is_required"));
162  return false;
163  }
164  }
165  return $this->checkSubItemsInput();
166  }
167 
173  public function insert($a_tpl)
174  {
175  global $lng;
176 
177  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
178  $i = 0;
179 
180  foreach ($this->pairs as $pair) {
181  $counter = 1;
182  $tpl->setCurrentBlock("option_term");
183  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
184  $tpl->setVariable("VALUE_OPTION", 0);
185  $tpl->parseCurrentBlock();
186  foreach ($this->terms as $term) {
187  $tpl->setCurrentBlock("option_term");
188  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
189  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
190  if ($pair->term->identifier == $term->identifier) {
191  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
192  }
193  $tpl->parseCurrentBlock();
194  $counter++;
195  }
196  $counter = 1;
197  $tpl->setCurrentBlock("option_definition");
198  $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
199  $tpl->setVariable("VALUE_OPTION", 0);
200  $tpl->parseCurrentBlock();
201  foreach ($this->definitions as $definition) {
202  $tpl->setCurrentBlock("option_definition");
203  $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
204  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
205  if ($pair->definition->identifier == $definition->identifier) {
206  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
207  }
208  $tpl->parseCurrentBlock();
209  $counter++;
210  }
211 
212  if (strlen($pair->points)) {
213  $tpl->setCurrentBlock('points_value');
214  $tpl->setVariable('POINTS_VALUE', $pair->points);
215  $tpl->parseCurrentBlock();
216  }
217  if ($this->getAllowMove()) {
218  $tpl->setCurrentBlock("move");
219  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
220  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
221  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
222  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
223  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
224  $tpl->parseCurrentBlock();
225  }
226 
227  $tpl->setCurrentBlock("row");
228  $tpl->setVariable("ROW_NUMBER", $i);
229 
230  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
231  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
232  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
233  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
234  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
235 
236  $tpl->setVariable("POST_VAR", $this->getPostVar());
237 
238  $tpl->parseCurrentBlock();
239 
240  $i++;
241  }
242 
243  $tpl->setCurrentBlock('term_ids');
244  $ids = array();
245  foreach ($this->terms as $term) {
246  array_push($ids, $term->identifier);
247  }
248  $tpl->setVariable("POST_VAR", $this->getPostVar());
249  $tpl->setVariable("TERM_IDS", join($ids, ","));
250  $tpl->parseCurrentBlock();
251 
252  $tpl->setCurrentBlock('definition_ids');
253  $ids = array();
254  foreach ($this->definitions as $definition) {
255  array_push($ids, $definition->identifier);
256  }
257  $tpl->setVariable("POST_VAR", $this->getPostVar());
258  $tpl->setVariable("DEFINITION_IDS", join($ids, ","));
259  $tpl->parseCurrentBlock();
260 
261  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
262  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
263  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
264  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
265  $tpl->setVariable("TEXT_ACTIONS", $lng->txt('actions'));
266 
267  $a_tpl->setCurrentBlock("prop_generic");
268  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
269  $a_tpl->parseCurrentBlock();
270 
271  global $tpl;
272  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
273  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
274  }
275 }
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.
$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.
$counter
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.
Create styles array
The data for the language used.
$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.