78 $this->type = (
int) $a_type;
80 $this->shuffle =
true;
115 $this->type = $a_type;
127 if ($gap_index ===
null) {
132 for ($i = -2; $i < $gap_index; $i++) {
164 return count($this->items);
178 $order = $a_item->getOrder();
179 if (array_key_exists($order, $this->items)) {
181 for ($i = 0; $i < $order; $i++) {
182 array_push($newitems, $this->items[$i]);
184 array_push($newitems, $a_item);
185 for ($i = $order, $iMax = count($this->items); $i < $iMax; $i++) {
186 array_push($newitems, $this->items[$i]);
189 foreach ($newitems as $idx => $item) {
190 $newitems[$idx]->setOrder($i);
193 $this->items = $newitems;
195 array_push($this->items, $a_item);
211 foreach ($this->items as $key => $item) {
212 if ($item->getOrder() == $order) {
213 $item->setPoints($points);
229 if (array_key_exists($order, $this->items)) {
230 unset($this->items[$order]);
232 foreach ($this->items as $key => $item) {
233 $this->items[$key]->setOrder($order);
251 foreach ($this->items as $key => $item) {
252 if ($item->getOrder() == $order) {
253 $item->setLowerBound($bound);
270 foreach ($this->items as $key => $item) {
271 if ($item->getOrder() == $order) {
272 $item->setUpperBound($bound);
289 if (array_key_exists($a_index, $this->items)) {
290 return $this->items[$a_index];
318 $this->shuffle = (bool) $a_shuffle;
342 foreach ($this->items as $item) {
343 if (strlen($item->getAnswertext()) > $maxwidth) {
344 $maxwidth = strlen($item->getAnswertext());
361 foreach ($this->items as $key => $item) {
362 if ($item->getPoints() > $maxpoints) {
363 $maxpoints = $item->getPoints();
367 foreach ($this->items as $key => $item) {
368 if ($item->getPoints() == $maxpoints) {
369 array_push($keys, $key);
387 $best_solutions = [];
388 if ($combinations !==
null && $combinations[
'best_solution'] === 1) {
389 $points_string_for_key = (string) $combinations[
'points'];
390 $best_solutions[$points_string_for_key] = [];
391 array_push($best_solutions[$points_string_for_key], $combinations[
'answer']);
393 foreach ($this->
getItems($shuffler) as $answer) {
394 $points_string_for_key = (string) $answer->getPoints();
395 if (isset($best_solutions[$points_string_for_key]) && is_array($best_solutions[$points_string_for_key])) {
396 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
398 $best_solutions[$points_string_for_key] = [];
399 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
404 krsort($best_solutions, SORT_NUMERIC);
405 reset($best_solutions);
406 $found = current($best_solutions);
407 return join(
" " .
$lng->txt(
"or") .
" ", $found);
412 foreach ($this->
getItems($shuffler) as $answer) {
413 if ($answer->getPoints() >= $maxpoints) {
414 $maxpoints = $answer->getPoints();
415 $foundvalue = $answer->getAnswertext();
440 if ($this->
getType() != self::TYPE_NUMERIC) {
447 $lowerBound = $math->evaluate($item->getLowerBound());
448 $upperBound = $math->evaluate($item->getUpperBound());
449 $preciseValue = $math->evaluate($item->getAnswertext());
451 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for cloze question gaps.
const TEXTGAP_RATING_CASESENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN1
const TEXTGAP_RATING_LEVENSHTEIN5
getBestSolutionOutput(Transformation $shuffler, $combinations=null)
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.
const TEXTGAP_RATING_CASEINSENSITIVE
const TEXTGAP_RATING_LEVENSHTEIN4
getItemCount()
Gets the item count.
setItemPoints($order, $points)
Sets the points for a given item.
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.
const TEXTGAP_RATING_LEVENSHTEIN2
const TEXTGAP_RATING_LEVENSHTEIN3
setGapSize(int $gap_size)
getItem($a_index)
Gets the item with a given index.
__construct($a_type)
assClozeGap constructor
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.
getItems(Transformation $shuffler, ?int $gap_index=null)
setType($a_type=0)
Sets the cloze gap type.