ILIAS  release_8 Revision v8.24
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)
 Gets the items of a cloze gap. More...
 
 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
 
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 35 of file class.assClozeGap.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeGap::__construct (   $a_type)

assClozeGap constructor

Parameters
int$a_type

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

69 {
70 $this->type = (int) $a_type;
71 $this->items = [];
72 $this->shuffle = true;
73 }

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

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

References $i.

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

@access public

See also
$items

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

299 : void
300 {
301 $this->items = [];
302 }

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

222 : void
223 {
224 if (array_key_exists($order, $this->items)) {
225 unset($this->items[$order]);
226 $order = 0;
227 foreach ($this->items as $key => $item) {
228 $this->items[$key]->setOrder($order);
229 $order++;
230 }
231 }
232 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

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

353 : array
354 {
355 $maxpoints = 0;
356 foreach ($this->items as $key => $item) {
357 if ($item->getPoints() > $maxpoints) {
358 $maxpoints = $item->getPoints();
359 }
360 }
361 $keys = [];
362 foreach ($this->items as $key => $item) {
363 if ($item->getPoints() == $maxpoints) {
364 array_push($keys, $key);
365 }
366 }
367 return $keys;
368 }
$keys
Definition: metadata.php:204

References ILIAS\LTI\ToolProvider\$key, and $keys.

◆ getBestSolutionOutput()

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

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

375 : string
376 {
377 global $DIC;
378 $lng = $DIC['lng'];
379 switch ($this->getType()) {
380 case CLOZE_TEXT:
381 case CLOZE_SELECT:
382 $best_solutions = [];
383 if ($combinations !== null && $combinations['best_solution'] == 1) {
384 $best_solutions[$combinations['points']] = [];
385 array_push($best_solutions[$combinations['points']], $combinations['answer']);
386 } else {
387 foreach ($this->getItems($shuffler) as $answer) {
388 $points_string_for_key = (string) $answer->getPoints();
389 if (isset($best_solutions[$points_string_for_key]) && is_array($best_solutions[$points_string_for_key])) {
390 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
391 } else {
392 $best_solutions[$points_string_for_key] = [];
393 array_push($best_solutions[$points_string_for_key], $answer->getAnswertext());
394 }
395 }
396 }
397
398 krsort($best_solutions, SORT_NUMERIC);
399 reset($best_solutions);
400 $found = current($best_solutions);
401 return join(" " . $lng->txt("or") . " ", $found);
402 break;
403 case CLOZE_NUMERIC:
404 $maxpoints = 0;
405 $foundvalue = "";
406 foreach ($this->getItems($shuffler) as $answer) {
407 if ($answer->getPoints() >= $maxpoints) {
408 $maxpoints = $answer->getPoints();
409 $foundvalue = $answer->getAnswertext();
410 }
411 }
412 return $foundvalue;
413 break;
414 default:
415 return "";
416 }
417 }
getItems(Transformation $shuffler, ?int $gap_index=null)
Gets the items of a cloze gap.
global $DIC
Definition: feed.php:28
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
$lng

References $DIC, $lng, CLOZE_NUMERIC, CLOZE_SELECT, CLOZE_TEXT, getItems(), and getType().

+ Here is the call graph for this function:

◆ getGapSize()

assClozeGap::getGapSize ( )
Returns
int

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

427 : int
428 {
429 return (int)$this->gap_size;
430 }

References $gap_size.

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

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

Referenced by ilAssClozeTestFeedback\determineAnswerIndexForAnswerValue(), and numericRangeExists().

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

157 : int
158 {
159 return count($this->items);
160 }

◆ getItems()

assClozeGap::getItems ( Transformation  $shuffler,
?int  $gap_index = null 
)

Gets the items of a cloze gap.

Parameters
Transformation$shuffler
Returns
assAnswerCloze[] The list of items

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

116 : array
117 {
118 if (!$this->getShuffle()) {
119 return $this->items;
120 }
121
122 if ($gap_index === null) {
123 return $shuffler->transform($this->items);
124 }
125
127 for ($i = -2; $i < $gap_index; $i++) {
129 }
130
131 return $items;
132 }
getShuffle()
Gets the shuffle state of the items.
Transformation $shuffler
transform($from)
Perform the transformation.

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

Referenced by ilAssClozeTestFeedback\buildGapFeedbackLabel(), ilAssClozeTestFeedback\completeFbPropsForSelectGap(), ilAssClozeTestFeedback\completeFbPropsForTextGap(), ilAssClozeTestFeedback\determineAnswerIndexForAnswerValue(), getBestSolutionOutput(), ilAssClozeTestFeedback\initFbPropsForSelectGap(), ilAssClozeTestFeedback\initFbPropsForTextGap(), ilAssClozeTestFeedback\saveFbPropsForSelectGap(), and ilAssClozeTestFeedback\saveFbPropsForTextGap().

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

143 : array
144 {
145 return $this->items;
146 }

References $items.

Referenced by assClozeTestGUI\saveGapCorrectionFormProperty(), and assClozeTestGUI\saveTextOrSelectGapCorrectionFormProperty().

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

334 : int
335 {
336 $maxwidth = 0;
337 foreach ($this->items as $item) {
338 if (strlen($item->getAnswertext()) > $maxwidth) {
339 $maxwidth = strlen($item->getAnswertext());
340 }
341 }
342 return $maxwidth;
343 }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

321 : bool
322 {
323 return $this->shuffle;
324 }

References $shuffle.

Referenced by getItems().

+ Here is the caller graph for this function:

◆ getType()

assClozeGap::getType ( )
See also
$type for mapping.

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

78 : int
79 {
80 return $this->type;
81 }

References $type.

Referenced by ilAssClozeTestFeedback\determineAnswerIndexForAnswerValue(), getBestSolutionOutput(), numericRangeExists(), and assClozeTestGUI\saveGapCorrectionFormProperty().

+ Here is the caller graph for this function:

◆ isNumericGap()

assClozeGap::isNumericGap ( )

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

93 : bool
94 {
95 return $this->type === self::TYPE_NUMERIC;
96 }

References TYPE_NUMERIC.

◆ isSelectGap()

assClozeGap::isSelectGap ( )

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

88 : bool
89 {
90 return $this->type === self::TYPE_SELECT;
91 }

References TYPE_SELECT.

◆ isTextGap()

assClozeGap::isTextGap ( )

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

83 : bool
84 {
85 return $this->type === self::TYPE_TEXT;
86 }

References TYPE_TEXT.

◆ numericRangeExists()

assClozeGap::numericRangeExists ( )

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

432 : bool
433 {
434 if ($this->getType() != CLOZE_NUMERIC) {
435 return false;
436 }
437
438 require_once 'Services/Math/classes/class.EvalMath.php';
439 $math = new EvalMath();
440
441 $item = $this->getItem(0);
442 $lowerBound = $math->evaluate($item->getLowerBound());
443 $upperBound = $math->evaluate($item->getUpperBound());
444 $preciseValue = $math->evaluate($item->getAnswertext());
445
446 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
447 return true;
448 }
449
450 return false;
451 }
getItem($a_index)
Gets the item with a given index.

References CLOZE_NUMERIC, 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 419 of file class.assClozeGap.php.

419 : void
420 {
421 $this->gap_size = $gap_size;
422 }

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

244 : void
245 {
246 foreach ($this->items as $key => $item) {
247 if ($item->getOrder() == $order) {
248 $item->setLowerBound($bound);
249 }
250 }
251 }

References ILIAS\LTI\ToolProvider\$key.

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

204 : void
205 {
206 foreach ($this->items as $key => $item) {
207 if ($item->getOrder() == $order) {
208 $item->setPoints($points);
209 }
210 }
211 }

References ILIAS\LTI\ToolProvider\$key.

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

263 : void
264 {
265 foreach ($this->items as $key => $item) {
266 if ($item->getOrder() == $order) {
267 $item->setUpperBound($bound);
268 }
269 }
270 }

References ILIAS\LTI\ToolProvider\$key.

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

311 : void
312 {
313 $this->shuffle = (bool) $a_shuffle;
314 }

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

105 : void
106 {
107 $this->type = $a_type;
108 }

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

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

Referenced by getGapSize(), and setGapSize().

◆ $items

assClozeGap::$items

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

Referenced by getItems(), and getItemsRaw().

◆ $shuffle

assClozeGap::$shuffle

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

Referenced by getShuffle().

◆ $shuffler

Transformation assClozeGap::$shuffler = null
private

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

Referenced by getItems().

◆ $type

int assClozeGap::$type

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

Referenced by getType().

◆ TYPE_NUMERIC

◆ TYPE_SELECT

◆ TYPE_TEXT


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