ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assClozeGap.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
5
19{
20
29 var $type;
30
38 var $items;
39
46
47 private $gap_size = 0;
48
55 public function assClozeGap($a_type)
56 {
57 $this->type = $a_type;
58 $this->items = array();
59 $this->shuffle = true;
60 }
61
71 public function getType()
72 {
73 return $this->type;
74 }
75
83 public function setType($a_type = 0)
84 {
85 $this->type = $a_type;
86 }
87
94 public function getItems(ilArrayElementShuffler $shuffler)
95 {
96 if ($this->getShuffle())
97 {
98 return $shuffler->shuffle($this->items);
99 }
100
101 return $this->items;
102 }
103
113 function getItemsRaw()
114 {
115 return $this->items;
116 }
117
127 function getItemCount()
128 {
129 return count($this->items);
130 }
131
141 function addItem($a_item)
142 {
143 $order = $a_item->getOrder();
144 if (array_key_exists($order, $this->items))
145 {
146 $newitems = array();
147 for ($i = 0; $i < $order; $i++)
148 {
149 array_push($newitems, $this->items[$i]);
150 }
151 array_push($newitems, $a_item);
152 for ($i = $order; $i < count($this->items); $i++)
153 {
154 array_push($newitems, $this->items[$i]);
155 }
156 $i = 0;
157 foreach ($newitems as $idx => $item)
158 {
159 $newitems[$idx]->setOrder($i);
160 $i++;
161 }
162 $this->items = $newitems;
163 }
164 else
165 {
166 array_push($this->items, $a_item);
167 }
168 }
169
180 function setItemPoints($order, $points)
181 {
182 foreach ($this->items as $key => $item)
183 {
184 if ($item->getOrder() == $order)
185 {
186 $item->setPoints($points);
187 }
188 }
189 }
190
200 function deleteItem($order)
201 {
202 if (array_key_exists($order, $this->items))
203 {
204 unset($this->items[$order]);
205 $order = 0;
206 foreach ($this->items as $key => $item)
207 {
208 $this->items[$key]->setOrder($order);
209 $order++;
210 }
211 }
212 }
213
224 function setItemLowerBound($order, $bound)
225 {
226 foreach ($this->items as $key => $item)
227 {
228 if ($item->getOrder() == $order)
229 {
230 $item->setLowerBound($bound);
231 }
232 }
233 }
234
245 function setItemUpperBound($order, $bound)
246 {
247 foreach ($this->items as $key => $item)
248 {
249 if ($item->getOrder() == $order)
250 {
251 $item->setUpperBound($bound);
252 }
253 }
254 }
255
265 function getItem($a_index)
266 {
267 if (array_key_exists($a_index, $this->items))
268 {
269 return $this->items[$a_index];
270 }
271 else
272 {
273 return NULL;
274 }
275 }
276
285 function clearItems()
286 {
287 $this->items = array();
288 }
289
297 public function setShuffle($a_shuffle = true)
298 {
299 $this->shuffle = (bool) $a_shuffle;
300 }
301
307 public function getShuffle()
308 {
309 return $this->shuffle;
310 }
311
320 function getMaxWidth()
321 {
322 $maxwidth = 0;
323 foreach ($this->items as $item)
324 {
325 if (strlen($item->getAnswertext()) > $maxwidth)
326 {
327 $maxwidth = strlen($item->getAnswertext());
328 }
329 }
330 return $maxwidth;
331 }
332
342 {
343 $maxpoints = 0;
344 foreach ($this->items as $key => $item)
345 {
346 if ($item->getPoints() > $maxpoints)
347 {
348 $maxpoints = $item->getPoints();
349 }
350 }
351 $keys = array();
352 foreach ($this->items as $key => $item)
353 {
354 if ($item->getPoints() == $maxpoints)
355 {
356 array_push($keys, $key);
357 }
358 }
359 return $keys;
360 }
361
363 {
364 global $lng;
365 switch ($this->getType())
366 {
367 case CLOZE_TEXT:
368 case CLOZE_SELECT:
369 $best_solutions = array();
370 foreach ($this->getItems($shuffler) as $answer)
371 {
372 if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()]))
373 {
374 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
375 }
376 else
377 {
378 $best_solutions[$answer->getPoints()] = array();
379 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
380 }
381 }
382 krsort($best_solutions, SORT_NUMERIC);
383 reset($best_solutions);
384 $found = current($best_solutions);
385 return join(" " . $lng->txt("or") . " ", $found);
386 break;
387 case CLOZE_NUMERIC:
388 $maxpoints = 0;
389 $foundvalue = "";
390 foreach ($this->getItems($shuffler) as $answer)
391 {
392 if ($answer->getPoints() >= $maxpoints)
393 {
394 $maxpoints = $answer->getPoints();
395 $foundvalue = $answer->getAnswertext();
396 }
397 }
398 return $foundvalue;
399 break;
400 default:
401 return "";
402 }
403 }
404
408 public function setGapSize( $gap_size)
409 {
410 $this->gap_size = $gap_size;
411 }
412
416 public function getGapSize()
417 {
418 return $this->gap_size;
419 }
420}
Class for cloze question gaps.
setGapSize( $gap_size)
setItemLowerBound($order, $bound)
Sets the lower bound for a given item.
deleteItem($order)
Deletes an item at a given index.
getBestSolutionIndexes()
Returns the indexes of the best solutions for the gap.
$type
Type of gap.
assClozeGap($a_type)
assClozeGap constructor
getBestSolutionOutput(ilArrayElementShuffler $shuffler)
getItemCount()
Gets the item count.
setItemPoints($order, $points)
Sets the points for a given item.
getItems(ilArrayElementShuffler $shuffler)
Gets the items of a cloze gap.
getShuffle()
Gets the shuffle state of the items.
clearItems()
Removes all gap items.
getMaxWidth()
Returns the maximum width of the gap.
setShuffle($a_shuffle=true)
Sets the shuffle state of the items.
getType()
Gets the cloze gap type.
getItem($a_index)
Gets the item with a given index.
getItemsRaw()
Gets the items of a cloze gap.
addItem($a_item)
Adds a gap item.
setItemUpperBound($order, $bound)
Sets the upper bound for a given item.
setType($a_type=0)
Sets the cloze gap type.
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
global $lng
Definition: privfeed.php:40