ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
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 34 of file class.assClozeGap.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeGap::__construct (   $a_type)

assClozeGap constructor

Parameters
int$a_type

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

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

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 176 of file class.assClozeGap.php.

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

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 304 of file class.assClozeGap.php.

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

◆ 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 227 of file class.assClozeGap.php.

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

◆ 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 358 of file class.assClozeGap.php.

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

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 380 of file class.assClozeGap.php.

380 : string
381 {
382 global $DIC;
383 $lng = $DIC['lng'];
384 switch ($this->getType()) {
385 case self::TYPE_TEXT:
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']);
392 } else {
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());
397 } else {
398 $best_solutions[$points_string_for_key] = [];
399 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
400 }
401 }
402 }
403
404 krsort($best_solutions, SORT_NUMERIC);
405 reset($best_solutions);
406 $found = current($best_solutions);
407 return join(" " . $lng->txt("or") . " ", $found);
408 break;
410 $maxpoints = 0;
411 $foundvalue = "";
412 foreach ($this->getItems($shuffler) as $answer) {
413 if ($answer->getPoints() >= $maxpoints) {
414 $maxpoints = $answer->getPoints();
415 $foundvalue = $answer->getAnswertext();
416 }
417 }
418 return $foundvalue;
419 break;
420 default:
421 return "";
422 }
423 }
getItems(Transformation $shuffler, ?int $gap_index=null)
global $lng
Definition: privfeed.php:26
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 433 of file class.assClozeGap.php.

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

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 287 of file class.assClozeGap.php.

288 {
289 if (array_key_exists($a_index, $this->items)) {
290 return $this->items[$a_index];
291 } else {
292 return null;
293 }
294 }
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 162 of file class.assClozeGap.php.

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

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 121 of file class.assClozeGap.php.

121 : array
122 {
123 if (!$this->getShuffle()) {
124 return $this->items;
125 }
126
127 if ($gap_index === null) {
128 return $shuffler->transform($this->items);
129 }
130
132 for ($i = -2; $i < $gap_index; $i++) {
134 }
135
136 return $items;
137 }
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 148 of file class.assClozeGap.php.

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

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 339 of file class.assClozeGap.php.

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

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

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

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 101 of file class.assClozeGap.php.

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

References TYPE_NUMERIC.

◆ isSelectGap()

assClozeGap::isSelectGap ( )

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

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

References TYPE_SELECT.

◆ isTextGap()

assClozeGap::isTextGap ( )

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

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

References TYPE_TEXT.

◆ numericRangeExists()

assClozeGap::numericRangeExists ( )

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

438 : bool
439 {
440 if ($this->getType() != self::TYPE_NUMERIC) {
441 return false;
442 }
443
444 $math = new EvalMath();
445
446 $item = $this->getItem(0);
447 $lowerBound = $math->evaluate($item->getLowerBound());
448 $upperBound = $math->evaluate($item->getUpperBound());
449 $preciseValue = $math->evaluate($item->getAnswertext());
450
451 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
452 return true;
453 }
454
455 return false;
456 }
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 425 of file class.assClozeGap.php.

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

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 249 of file class.assClozeGap.php.

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

◆ 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 209 of file class.assClozeGap.php.

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

◆ 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 268 of file class.assClozeGap.php.

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

◆ 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 316 of file class.assClozeGap.php.

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

◆ 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 113 of file class.assClozeGap.php.

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

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

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

Referenced by getGapSize(), and setGapSize().

◆ $items

assClozeGap::$items

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

Referenced by getItems(), and getItemsRaw().

◆ $shuffle

assClozeGap::$shuffle

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

Referenced by getShuffle().

◆ $shuffler

Transformation assClozeGap::$shuffler = null
private

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

Referenced by getItems().

◆ $type

int assClozeGap::$type

Definition at line 50 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: