ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4require_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 function __construct($a_title = "", $a_postvar = "")
27 {
28 parent::__construct($a_title, $a_postvar);
29 }
30
36 function setValue($a_value)
37 {
38 $this->pairs = array();
39 $this->terms = array();
40 $this->definitions = array();
41 if (is_array($a_value))
42 {
43 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
44 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
45 include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
46 if (is_array($a_value['term']))
47 {
48 foreach ($a_value['term'] as $idx => $term)
49 {
50 array_push($this->pairs, new assAnswerMatchingPair(new assAnswerMatchingTerm('', '', $term), new assAnswerMatchingDefinition('', '', $a_value['definition'][$idx]), $a_value['points'][$idx]));
51 }
52 }
53 $term_ids = split(",", $a_value['term_id']);
54 foreach ($term_ids as $id)
55 {
56 array_push($this->terms, new assAnswerMatchingTerm('', '', $id));
57 }
58 $definition_ids = split(",", $a_value['definition_id']);
59 foreach ($definition_ids as $id)
60 {
61 array_push($this->definitions, new assAnswerMatchingDefinition('', '', $id));
62 }
63 }
64 }
65
71 function setTerms($a_terms)
72 {
73 $this->terms = $a_terms;
74 }
75
81 function setDefinitions($a_definitions)
82 {
83 $this->definitions = $a_definitions;
84 }
85
91 function setPairs($a_pairs)
92 {
93 $this->pairs = $a_pairs;
94 }
95
101 function setAllowMove($a_allow_move)
102 {
103 $this->allowMove = $a_allow_move;
104 }
105
111 function getAllowMove()
112 {
113 return $this->allowMove;
114 }
115
121 function checkInput()
122 {
123 global $lng;
124
125 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
126 $foundvalues = $_POST[$this->getPostVar()];
127 if (is_array($foundvalues))
128 {
129 // check answers
130 if (is_array($foundvalues['term']))
131 {
132 foreach ($foundvalues['term'] as $val)
133 {
134 if ($this->getRequired() && $val < 1)
135 {
136 $this->setAlert($lng->txt("msg_input_is_required"));
137 return FALSE;
138 }
139 }
140 foreach ($foundvalues['definition'] as $val)
141 {
142 if ($this->getRequired() && $val < 1)
143 {
144 $this->setAlert($lng->txt("msg_input_is_required"));
145 return FALSE;
146 }
147 }
148 $max = 0;
149 foreach ($foundvalues['points'] as $val)
150 {
151 if ($val > 0) $max += $val;
152 if ($this->getRequired() && (strlen($val)) == 0)
153 {
154 $this->setAlert($lng->txt("msg_input_is_required"));
155 return FALSE;
156 }
157 }
158 if ($max <= 0)
159 {
160 $this->setAlert($lng->txt("enter_enough_positive_points"));
161 return FALSE;
162 }
163 }
164 else
165 {
166 if ($this->getRequired())
167 {
168 $this->setAlert($lng->txt("msg_input_is_required"));
169 return FALSE;
170 }
171 }
172 }
173 else
174 {
175 if ($this->getRequired())
176 {
177 $this->setAlert($lng->txt("msg_input_is_required"));
178 return FALSE;
179 }
180 }
181 return $this->checkSubItemsInput();
182 }
183
189 function insert(&$a_tpl)
190 {
191 global $lng;
192
193 $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
194 $i = 0;
195
196 foreach ($this->pairs as $pair)
197 {
198 $counter = 1;
199 $tpl->setCurrentBlock("option_term");
200 $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
201 $tpl->setVariable("VALUE_OPTION", 0);
202 $tpl->parseCurrentBlock();
203 foreach ($this->terms as $term)
204 {
205 $tpl->setCurrentBlock("option_term");
206 $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($term->identifier));
207 $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
208 if ($pair->term->identifier == $term->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
209 $tpl->parseCurrentBlock();
210 $counter++;
211 }
212 $counter = 1;
213 $tpl->setCurrentBlock("option_definition");
214 $tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($lng->txt('please_select')));
215 $tpl->setVariable("VALUE_OPTION", 0);
216 $tpl->parseCurrentBlock();
217 foreach ($this->definitions as $definition)
218 {
219 $tpl->setCurrentBlock("option_definition");
220 $tpl->setVariable("VALUE_OPTION", ilUtil::prepareFormOutput($definition->identifier));
221 $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
222 if ($pair->definition->identifier == $definition->identifier) $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
223 $tpl->parseCurrentBlock();
224 $counter++;
225 }
226
227 if (strlen($pair->points))
228 {
229 $tpl->setCurrentBlock('points_value');
230 $tpl->setVariable('POINTS_VALUE', $pair->points);
231 $tpl->parseCurrentBlock();
232 }
233 if ($this->getAllowMove())
234 {
235 $tpl->setCurrentBlock("move");
236 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
237 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
238 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
239 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
240 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
241 $tpl->parseCurrentBlock();
242 }
243
244 $tpl->setCurrentBlock("row");
245 $tpl->setVariable("ROW_NUMBER", $i);
246
247 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
248 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
249 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
250 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
251 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
252
253 $tpl->setVariable("POST_VAR", $this->getPostVar());
254
255 $tpl->parseCurrentBlock();
256
257 $i++;
258 }
259
260 $tpl->setCurrentBlock('term_ids');
261 $ids = array();
262 foreach ($this->terms as $term)
263 {
264 array_push($ids, $term->identifier);
265 }
266 $tpl->setVariable("POST_VAR", $this->getPostVar());
267 $tpl->setVariable("TERM_IDS", join($ids, ","));
268 $tpl->parseCurrentBlock();
269
270 $tpl->setCurrentBlock('definition_ids');
271 $ids = array();
272 foreach ($this->definitions as $definition)
273 {
274 array_push($ids, $definition->identifier);
275 }
276 $tpl->setVariable("POST_VAR", $this->getPostVar());
277 $tpl->setVariable("DEFINITION_IDS", join($ids, ","));
278 $tpl->parseCurrentBlock();
279
280 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
281 $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
282 $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
283 $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
284 $tpl->setVariable("TEXT_ACTIONS", $lng->txt('actions'));
285
286 $a_tpl->setCurrentBlock("prop_generic");
287 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
288 $a_tpl->parseCurrentBlock();
289
290 global $tpl;
291 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
292 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
293 }
294}
global $tpl
Definition: ilias.php:8
Class for matching question definitions.
Class for matching question pairs.
Class for matching question terms.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a key value pair wizard property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setDefinitions($a_definitions)
Set definitions.
checkInput()
Check input, strip slashes etc.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40