ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assClozeGap Class Reference

Class for cloze question gaps. More...

+ Inheritance diagram for assClozeGap:
+ Collaboration diagram for assClozeGap:

Public Member Functions

 __construct ($a_type)
 assClozeGap constructor More...
 
 getType ()
 
 isTextGap ()
 
 isSelectGap ()
 
 isNumericGap ()
 
 setType ($a_type=0)
 Sets the cloze gap type. More...
 
 getItems (Transformation $shuffler, ?int $gap_index=null)
 
 getItemsRaw ()
 Gets the items of a cloze gap. More...
 
 getItemCount ()
 Gets the item count. More...
 
 addItem ($a_item)
 Adds a gap item. More...
 
 setItemPoints ($order, $points)
 Sets the points for a given item. More...
 
 deleteItem ($order)
 Deletes an item at a given index. More...
 
 setItemLowerBound ($order, $bound)
 Sets the lower bound for a given item. More...
 
 setItemUpperBound ($order, $bound)
 Sets the upper bound for a given item. More...
 
 getItem ($a_index)
 Gets the item with a given index. More...
 
 clearItems ()
 Removes all gap items. More...
 
 setShuffle ($a_shuffle=true)
 Sets the shuffle state of the items. More...
 
 getShuffle ()
 Gets the shuffle state of the items. More...
 
 getMaxWidth ()
 Returns the maximum width of the gap. More...
 
 getBestSolutionIndexes ()
 Returns the indexes of the best solutions for the gap. More...
 
 getBestSolutionOutput (Transformation $shuffler, $combinations=null)
 
 setGapSize (int $gap_size)
 
 getGapSize ()
 
 numericRangeExists ()
 

Data Fields

const TYPE_TEXT = 0
 
const TYPE_SELECT = 1
 
const TYPE_NUMERIC = 2
 
const TEXTGAP_RATING_CASEINSENSITIVE = "ci"
 
const TEXTGAP_RATING_CASESENSITIVE = "cs"
 
const TEXTGAP_RATING_LEVENSHTEIN1 = "l1"
 
const TEXTGAP_RATING_LEVENSHTEIN2 = "l2"
 
const TEXTGAP_RATING_LEVENSHTEIN3 = "l3"
 
const TEXTGAP_RATING_LEVENSHTEIN4 = "l4"
 
const TEXTGAP_RATING_LEVENSHTEIN5 = "l5"
 
int $type
 
 $items
 
 $shuffle
 

Private Attributes

Transformation $shuffler = null
 
 $gap_size = 0
 

Detailed Description

Class for cloze question gaps.

assClozeGap is a class for the abstraction of cloze gaps. It represents a text gap.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

\

Definition at line 33 of file class.assClozeGap.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeGap::__construct (   $a_type)

assClozeGap constructor

Parameters
int$a_type

Definition at line 75 of file class.assClozeGap.php.

76 {
77 $this->type = (int) $a_type;
78 $this->items = [];
79 $this->shuffle = true;
80 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

assClozeGap::addItem (   $a_item)

Adds a gap item.

Adds a gap item

Parameters
object$a_itemCloze gap item @access public
See also
$items

Definition at line 175 of file class.assClozeGap.php.

175 : void
176 {
177 $order = $a_item->getOrder();
178 if (array_key_exists($order, $this->items)) {
179 $newitems = [];
180 for ($i = 0; $i < $order; $i++) {
181 array_push($newitems, $this->items[$i]);
182 }
183 array_push($newitems, $a_item);
184 for ($i = $order, $iMax = count($this->items); $i < $iMax; $i++) {
185 array_push($newitems, $this->items[$i]);
186 }
187 $i = 0;
188 foreach ($newitems as $idx => $item) {
189 $newitems[$idx]->setOrder($i);
190 $i++;
191 }
192 $this->items = $newitems;
193 } else {
194 array_push($this->items, $a_item);
195 }
196 }

Referenced by assClozeTest\addAnswerOptionValue(), and assClozeTest\createGapsFromQuestiontext().

+ Here is the caller graph for this function:

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

@access public

See also
$items

Definition at line 303 of file class.assClozeGap.php.

303 : void
304 {
305 $this->items = [];
306 }

◆ deleteItem()

assClozeGap::deleteItem (   $order)

Deletes an item at a given index.

Deletes an item at a given index

Parameters
integer$0order Order of the item @access public
See also
$items

Definition at line 226 of file class.assClozeGap.php.

226 : void
227 {
228 if (array_key_exists($order, $this->items)) {
229 unset($this->items[$order]);
230 $order = 0;
231 foreach ($this->items as $key => $item) {
232 $this->items[$key]->setOrder($order);
233 $order++;
234 }
235 }
236 }

◆ getBestSolutionIndexes()

assClozeGap::getBestSolutionIndexes ( )

Returns the indexes of the best solutions for the gap.

Returns the indexes of the best solutions for the gap

Returns
array The indexs of the best solutions @access public

Definition at line 357 of file class.assClozeGap.php.

357 : array
358 {
359 $maxpoints = 0;
360 foreach ($this->items as $key => $item) {
361 if ($item->getPoints() > $maxpoints) {
362 $maxpoints = $item->getPoints();
363 }
364 }
365 $keys = [];
366 foreach ($this->items as $key => $item) {
367 if ($item->getPoints() == $maxpoints) {
368 array_push($keys, $key);
369 }
370 }
371 return $keys;
372 }

Referenced by assClozeTest\getCorrectSolutionForTextOutput().

+ Here is the caller graph for this function:

◆ getBestSolutionOutput()

assClozeGap::getBestSolutionOutput ( Transformation  $shuffler,
  $combinations = null 
)
Parameters
Transformation$shuffler
null  |  array$combinations
Returns
string

Definition at line 379 of file class.assClozeGap.php.

379 : string
380 {
381 global $DIC;
382 $lng = $DIC['lng'];
383 switch ($this->getType()) {
384 case self::TYPE_TEXT:
386 $best_solutions = [];
387 if ($combinations !== null && $combinations['best_solution'] === 1) {
388 $points_string_for_key = (string) $combinations['points'];
389 $best_solutions[$points_string_for_key] = [];
390 array_push($best_solutions[$points_string_for_key], $combinations['answer']);
391 } else {
392 foreach ($this->getItems($shuffler) as $answer) {
393 $points_string_for_key = (string) $answer->getPoints();
394 if (isset($best_solutions[$points_string_for_key]) && is_array($best_solutions[$points_string_for_key])) {
395 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
396 } else {
397 $best_solutions[$points_string_for_key] = [];
398 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
399 }
400 }
401 }
402
403 krsort($best_solutions, SORT_NUMERIC);
404 reset($best_solutions);
405 $found = current($best_solutions);
406 return join(" " . $lng->txt("or") . " ", $found);
407 break;
409 $maxpoints = 0;
410 $foundvalue = "";
411 foreach ($this->getItems($shuffler) as $answer) {
412 if ($answer->getPoints() >= $maxpoints) {
413 $maxpoints = $answer->getPoints();
414 $foundvalue = $answer->getAnswertext();
415 }
416 }
417 return $foundvalue;
418 break;
419 default:
420 return "";
421 }
422 }
getItems(Transformation $shuffler, ?int $gap_index=null)
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26

References $DIC, $lng, getItems(), getType(), TYPE_NUMERIC, TYPE_SELECT, and TYPE_TEXT.

+ Here is the call graph for this function:

◆ getGapSize()

assClozeGap::getGapSize ( )
Returns
int

Definition at line 432 of file class.assClozeGap.php.

432 : int
433 {
434 return (int) $this->gap_size;
435 }

References $gap_size.

Referenced by assClozeTest\toJSON(), and assClozeTest\toLog().

+ Here is the caller graph for this function:

◆ getItem()

assClozeGap::getItem (   $a_index)

Gets the item with a given index.

Gets the item with a given index

Parameters
integer$a_indexItem index @access public
See also
$items
Returns
assAnswerCloze|null

Definition at line 286 of file class.assClozeGap.php.

287 {
288 if (array_key_exists($a_index, $this->items)) {
289 return $this->items[$a_index];
290 } else {
291 return null;
292 }
293 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by ilAssClozeTestFeedback\determineAnswerIndexForAnswerValue(), assClozeTest\getCorrectSolutionForTextOutput(), numericRangeExists(), assClozeTest\solutionValuesToLog(), and assClozeTest\solutionValuesToText().

+ Here is the caller graph for this function:

◆ getItemCount()

assClozeGap::getItemCount ( )

Gets the item count.

Gets the item count

Returns
integer The item count @access public
See also
$items

Definition at line 161 of file class.assClozeGap.php.

161 : int
162 {
163 return count($this->items);
164 }

Referenced by assClozeTest\addAnswerOptionValue().

+ Here is the caller graph for this function:

◆ getItems()

assClozeGap::getItems ( Transformation  $shuffler,
?int  $gap_index = null 
)
Returns
array<assAnswerCloze>

Definition at line 120 of file class.assClozeGap.php.

120 : array
121 {
122 if (!$this->getShuffle()) {
123 return $this->items;
124 }
125
126 if ($gap_index === null) {
127 return $shuffler->transform($this->items);
128 }
129
131 for ($i = -2; $i < $gap_index; $i++) {
133 }
134
135 return $items;
136 }
getShuffle()
Gets the shuffle state of the items.
Transformation $shuffler
transform($from)
Perform the transformation.

References $items, $shuffler, getShuffle(), and ILIAS\Refinery\Transformation\transform().

Referenced by ilAssClozeTestFeedback\buildGapFeedbackLabel(), ilAssClozeTestFeedback\completeFbPropsForSelectGap(), ilAssClozeTestFeedback\completeFbPropsForTextGap(), ilAssClozeTestFeedback\determineAnswerIndexForAnswerValue(), getBestSolutionOutput(), assClozeTest\getMaximumGapPoints(), assClozeTest\getMaximumPoints(), ilAssClozeTestFeedback\initFbPropsForSelectGap(), ilAssClozeTestFeedback\initFbPropsForTextGap(), assClozeTest\isAddableAnswerOptionValue(), ilAssClozeTestFeedback\saveFbPropsForSelectGap(), ilAssClozeTestFeedback\saveFbPropsForTextGap(), assClozeTest\toJSON(), and assClozeTest\toLog().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemsRaw()

assClozeGap::getItemsRaw ( )

Gets the items of a cloze gap.

Gets the items of a cloze gap

Returns
array The list of items @access public
See also
$items

Definition at line 147 of file class.assClozeGap.php.

147 : array
148 {
149 return $this->items;
150 }

References $items.

Referenced by assClozeTest\deleteGap(), assClozeTestGUI\saveGapCorrectionFormProperty(), assClozeTestGUI\saveTextOrSelectGapCorrectionFormProperty(), and assClozeTest\updateClozeTextFromGaps().

+ Here is the caller graph for this function:

◆ getMaxWidth()

assClozeGap::getMaxWidth ( )

Returns the maximum width of the gap.

Returns the maximum width of the gap

Returns
integer The maximum width of the gap defined by the longest answer @access public

Definition at line 338 of file class.assClozeGap.php.

338 : int
339 {
340 $maxwidth = 0;
341 foreach ($this->items as $item) {
342 if (strlen($item->getAnswertext()) > $maxwidth) {
343 $maxwidth = strlen($item->getAnswertext());
344 }
345 }
346 return $maxwidth;
347 }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

Definition at line 325 of file class.assClozeGap.php.

325 : bool
326 {
327 return $this->shuffle;
328 }

References $shuffle.

Referenced by getItems(), assClozeTest\toJSON(), and assClozeTest\toLog().

+ Here is the caller graph for this function:

◆ getType()

◆ isNumericGap()

assClozeGap::isNumericGap ( )

Definition at line 100 of file class.assClozeGap.php.

100 : bool
101 {
102 return $this->type === self::TYPE_NUMERIC;
103 }

References TYPE_NUMERIC.

◆ isSelectGap()

assClozeGap::isSelectGap ( )

Definition at line 95 of file class.assClozeGap.php.

95 : bool
96 {
97 return $this->type === self::TYPE_SELECT;
98 }

References TYPE_SELECT.

◆ isTextGap()

assClozeGap::isTextGap ( )

Definition at line 90 of file class.assClozeGap.php.

90 : bool
91 {
92 return $this->type === self::TYPE_TEXT;
93 }

References TYPE_TEXT.

◆ numericRangeExists()

assClozeGap::numericRangeExists ( )

Definition at line 437 of file class.assClozeGap.php.

437 : bool
438 {
439 if ($this->getType() != self::TYPE_NUMERIC) {
440 return false;
441 }
442
443 $math = new EvalMath();
444
445 $item = $this->getItem(0);
446 $lowerBound = $math->evaluate($item->getLowerBound());
447 $upperBound = $math->evaluate($item->getUpperBound());
448 $preciseValue = $math->evaluate($item->getAnswertext());
449
450 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
451 return true;
452 }
453
454 return false;
455 }
getItem($a_index)
Gets the item with a given index.

References getItem(), and getType().

Referenced by ilAssClozeTestFeedback\completeFbPropsForNumericGap(), ilAssClozeTestFeedback\initFbPropsForNumericGap(), and ilAssClozeTestFeedback\saveFbPropsForNumericGap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setGapSize()

assClozeGap::setGapSize ( int  $gap_size)

Definition at line 424 of file class.assClozeGap.php.

424 : void
425 {
426 $this->gap_size = $gap_size;
427 }

References $gap_size.

◆ setItemLowerBound()

assClozeGap::setItemLowerBound (   $order,
  $bound 
)

Sets the lower bound for a given item.

Sets the lower bound for a given item

Parameters
integer$orderOrder of the item
double$boundLower bounds of the item @access public
See also
$items

Definition at line 248 of file class.assClozeGap.php.

248 : void
249 {
250 foreach ($this->items as $key => $item) {
251 if ($item->getOrder() == $order) {
252 $item->setLowerBound($bound);
253 }
254 }
255 }

◆ setItemPoints()

assClozeGap::setItemPoints (   $order,
  $points 
)

Sets the points for a given item.

Sets the points for a given item

Parameters
integer$orderOrder of the item
double$pointsPoints of the item @access public
See also
$items

Definition at line 208 of file class.assClozeGap.php.

208 : void
209 {
210 foreach ($this->items as $key => $item) {
211 if ($item->getOrder() == $order) {
212 $item->setPoints($points);
213 }
214 }
215 }

◆ setItemUpperBound()

assClozeGap::setItemUpperBound (   $order,
  $bound 
)

Sets the upper bound for a given item.

Sets the upper bound for a given item

Parameters
integer$orderOrder of the item
double$boundUpper bound of the item @access public
See also
$items

Definition at line 267 of file class.assClozeGap.php.

267 : void
268 {
269 foreach ($this->items as $key => $item) {
270 if ($item->getOrder() == $order) {
271 $item->setUpperBound($bound);
272 }
273 }
274 }

◆ setShuffle()

assClozeGap::setShuffle (   $a_shuffle = true)

Sets the shuffle state of the items.

Sets the shuffle state of the items

Parameters
boolean$a_shuffleShuffle state

Definition at line 315 of file class.assClozeGap.php.

315 : void
316 {
317 $this->shuffle = (bool) $a_shuffle;
318 }

◆ setType()

assClozeGap::setType (   $a_type = 0)

Sets the cloze gap type.

Parameters
integer$a_typecloze gap type
See also
$type for mapping.

Definition at line 112 of file class.assClozeGap.php.

112 : void
113 {
114 $this->type = $a_type;
115 }

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

Definition at line 67 of file class.assClozeGap.php.

Referenced by getGapSize(), and setGapSize().

◆ $items

assClozeGap::$items

Definition at line 58 of file class.assClozeGap.php.

Referenced by getItems(), and getItemsRaw().

◆ $shuffle

assClozeGap::$shuffle

Definition at line 65 of file class.assClozeGap.php.

Referenced by getShuffle().

◆ $shuffler

Transformation assClozeGap::$shuffler = null
private

Definition at line 47 of file class.assClozeGap.php.

Referenced by getItems().

◆ $type

int assClozeGap::$type

Definition at line 49 of file class.assClozeGap.php.

Referenced by getType().

◆ TEXTGAP_RATING_CASEINSENSITIVE

◆ TEXTGAP_RATING_CASESENSITIVE

◆ TEXTGAP_RATING_LEVENSHTEIN1

◆ TEXTGAP_RATING_LEVENSHTEIN2

◆ TEXTGAP_RATING_LEVENSHTEIN3

◆ TEXTGAP_RATING_LEVENSHTEIN4

◆ TEXTGAP_RATING_LEVENSHTEIN5

◆ TYPE_NUMERIC

◆ TYPE_SELECT

◆ TYPE_TEXT


The documentation for this class was generated from the following file: