4 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
62 $this->type = (int) $a_type;
63 $this->items = array();
64 $this->shuffle =
true;
83 return $this->type == self::TYPE_TEXT;
88 return $this->type == self::TYPE_SELECT;
93 return $this->type == self::TYPE_NUMERIC;
105 $this->type = $a_type;
114 if ($gap_index === null) {
115 return $shuffler->
shuffle($this->items);
119 for (
$i = -2;
$i < $gap_index;
$i++) {
151 return count($this->items);
165 $order = $a_item->getOrder();
166 if (array_key_exists($order, $this->items)) {
168 for (
$i = 0;
$i < $order;
$i++) {
169 array_push($newitems, $this->items[
$i]);
171 array_push($newitems, $a_item);
172 for (
$i = $order;
$i < count($this->items);
$i++) {
173 array_push($newitems, $this->items[
$i]);
176 foreach ($newitems as $idx => $item) {
177 $newitems[$idx]->setOrder(
$i);
180 $this->items = $newitems;
182 array_push($this->items, $a_item);
198 foreach ($this->items as $key => $item) {
199 if ($item->getOrder() == $order) {
200 $item->setPoints($points);
216 if (array_key_exists($order, $this->items)) {
217 unset($this->items[$order]);
219 foreach ($this->items as $key => $item) {
220 $this->items[$key]->setOrder($order);
236 foreach ($this->items as $key => $item) {
237 if ($item->getOrder() == $order) {
238 $item->setLowerBound($bound);
255 foreach ($this->items as $key => $item) {
256 if ($item->getOrder() == $order) {
257 $item->setUpperBound($bound);
274 if (array_key_exists($a_index, $this->items)) {
275 return $this->items[$a_index];
291 $this->items = array();
303 $this->shuffle = (bool) $a_shuffle;
322 require_once
'Services/Randomization/classes/class.ilArrayElementShuffler.php';
335 if ($this->shuffler == null) {
354 foreach ($this->items as $item) {
355 if (strlen($item->getAnswertext()) > $maxwidth) {
356 $maxwidth = strlen($item->getAnswertext());
373 foreach ($this->items as $key => $item) {
374 if ($item->getPoints() > $maxpoints) {
375 $maxpoints = $item->getPoints();
379 foreach ($this->items as $key => $item) {
380 if ($item->getPoints() == $maxpoints) {
381 array_push(
$keys, $key);
399 $best_solutions = array();
400 if ($combinations !== null && $combinations[
'best_solution'] == 1) {
401 $best_solutions[$combinations[
'points']] = array();
402 array_push($best_solutions[$combinations[
'points']], $combinations[
'answer']);
404 foreach ($this->
getItems($shuffler) as $answer) {
405 if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()])) {
406 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
408 $best_solutions[$answer->getPoints()] = array();
409 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
414 krsort($best_solutions, SORT_NUMERIC);
415 reset($best_solutions);
416 $found = current($best_solutions);
417 return join(
" " .
$lng->txt(
"or") .
" ", $found);
422 foreach ($this->
getItems($shuffler) as $answer) {
423 if ($answer->getPoints() >= $maxpoints) {
424 $maxpoints = $answer->getPoints();
425 $foundvalue = $answer->getAnswertext();
457 require_once
'Services/Math/classes/class.EvalMath.php';
461 $lowerBound = $math->evaluate($item->getLowerBound());
462 $upperBound = $math->evaluate($item->getUpperBound());
463 $preciseValue = $math->evaluate($item->getAnswertext());
465 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
setItemUpperBound($order, $bound)
Sets the upper bound for a given item.
setType($a_type=0)
Sets the cloze gap type.
const CLOZE_TEXT
Cloze question constants.
deleteItem($order)
Deletes an item at a given index.
setItemLowerBound($order, $bound)
Sets the lower bound for a given item.
clearItems()
Removes all gap items.
Class for cloze question gaps.
getItems(ilArrayElementShuffler $shuffler, ?int $gap_index=null)
setItemPoints($order, $points)
Sets the points for a given item.
setShuffler(ilArrayElementShuffler $shuffler=null)
getItemsRaw()
Gets the items of a cloze gap.
addItem($a_item)
Adds a gap item.
getBestSolutionIndexes()
Returns the indexes of the best solutions for the gap.
getMaxWidth()
Returns the maximum width of the gap.
getItemCount()
Gets the item count.
getType()
Gets the cloze gap type.
getBestSolutionOutput(ilArrayElementShuffler $shuffler, $combinations=null)
getShuffle()
Gets the shuffle state of the items.
getItem($a_index)
Gets the item with a given index.
setShuffle($a_shuffle=true)
Sets the shuffle state of the items.
__construct($a_type)
assClozeGap constructor