ILIAS  release_7 Revision v7.30-3-g800a261c036
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 ()
 Gets the cloze gap type. More...
 
 isTextGap ()
 
 isSelectGap ()
 
 isNumericGap ()
 
 setType ($a_type=0)
 Sets the cloze gap type. More...
 
 getItems (ilArrayElementShuffler $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...
 
 setShuffler (ilArrayElementShuffler $shuffler=null)
 
 getShuffler ()
 
 getMaxWidth ()
 Returns the maximum width of the gap. More...
 
 getBestSolutionIndexes ()
 Returns the indexes of the best solutions for the gap. More...
 
 getBestSolutionOutput (ilArrayElementShuffler $shuffler, $combinations=null)
 
 setGapSize ($gap_size)
 
 getGapSize ()
 
 numericRangeExists ()
 

Data Fields

const TYPE_TEXT = 0
 
const TYPE_SELECT = 1
 
const TYPE_NUMERIC = 2
 
 $type
 Type of gap. More...
 
 $items
 
 $shuffle
 

Private Attributes

 $shuffler
 
 $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 18 of file class.assClozeGap.php.

Constructor & Destructor Documentation

◆ __construct()

assClozeGap::__construct (   $a_type)

assClozeGap constructor

Parameters
int$a_type

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

61 {
62 $this->type = (int) $a_type;
63 $this->items = array();
64 $this->shuffle = true;
65 }

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

164 {
165 $order = $a_item->getOrder();
166 if (array_key_exists($order, $this->items)) {
167 $newitems = array();
168 for ($i = 0; $i < $order; $i++) {
169 array_push($newitems, $this->items[$i]);
170 }
171 array_push($newitems, $a_item);
172 for ($i = $order; $i < count($this->items); $i++) {
173 array_push($newitems, $this->items[$i]);
174 }
175 $i = 0;
176 foreach ($newitems as $idx => $item) {
177 $newitems[$idx]->setOrder($i);
178 $i++;
179 }
180 $this->items = $newitems;
181 } else {
182 array_push($this->items, $a_item);
183 }
184 }
$i
Definition: metadata.php:24

References $i.

◆ clearItems()

assClozeGap::clearItems ( )

Removes all gap items.

Removes all gap items

@access public

See also
$items

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

290 {
291 $this->items = array();
292 }

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

215 {
216 if (array_key_exists($order, $this->items)) {
217 unset($this->items[$order]);
218 $order = 0;
219 foreach ($this->items as $key => $item) {
220 $this->items[$key]->setOrder($order);
221 $order++;
222 }
223 }
224 }

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

371 {
372 $maxpoints = 0;
373 foreach ($this->items as $key => $item) {
374 if ($item->getPoints() > $maxpoints) {
375 $maxpoints = $item->getPoints();
376 }
377 }
378 $keys = array();
379 foreach ($this->items as $key => $item) {
380 if ($item->getPoints() == $maxpoints) {
381 array_push($keys, $key);
382 }
383 }
384 return $keys;
385 }
$keys
Definition: metadata.php:187

References $keys.

◆ getBestSolutionOutput()

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

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

393 {
394 global $DIC;
395 $lng = $DIC['lng'];
396 switch ($this->getType()) {
397 case CLOZE_TEXT:
398 case CLOZE_SELECT:
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']);
403 } else {
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());
407 } else {
408 $best_solutions[$answer->getPoints()] = array();
409 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
410 }
411 }
412 }
413
414 krsort($best_solutions, SORT_NUMERIC);
415 reset($best_solutions);
416 $found = current($best_solutions);
417 return join(" " . $lng->txt("or") . " ", $found);
418 break;
419 case CLOZE_NUMERIC:
420 $maxpoints = 0;
421 $foundvalue = "";
422 foreach ($this->getItems($shuffler) as $answer) {
423 if ($answer->getPoints() >= $maxpoints) {
424 $maxpoints = $answer->getPoints();
425 $foundvalue = $answer->getAnswertext();
426 }
427 }
428 return $foundvalue;
429 break;
430 default:
431 return "";
432 }
433 }
getItems(ilArrayElementShuffler $shuffler, ?int $gap_index=null)
getType()
Gets the cloze gap type.
global $DIC
Definition: goto.php:24
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 446 of file class.assClozeGap.php.

447 {
448 return $this->gap_size;
449 }

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

273 {
274 if (array_key_exists($a_index, $this->items)) {
275 return $this->items[$a_index];
276 } else {
277 return null;
278 }
279 }

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

150 {
151 return count($this->items);
152 }

◆ getItems()

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

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

108 : array
109 {
110 if (!$this->getShuffle()) {
111 return $this->items;
112 }
113
114 if ($gap_index === null) {
115 return $shuffler->shuffle($this->items);
116 }
117
119 for ($i = -2; $i < $gap_index; $i++) {
120 $items = $shuffler->shuffle($items);
121 }
122
123 return $items;
124 }
getShuffle()
Gets the shuffle state of the items.

References $i, $items, $shuffler, and getShuffle().

Referenced by 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 135 of file class.assClozeGap.php.

136 {
137 return $this->items;
138 }

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

352 {
353 $maxwidth = 0;
354 foreach ($this->items as $item) {
355 if (strlen($item->getAnswertext()) > $maxwidth) {
356 $maxwidth = strlen($item->getAnswertext());
357 }
358 }
359 return $maxwidth;
360 }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

312 {
313 return $this->shuffle;
314 }

References $shuffle.

Referenced by getItems().

+ Here is the caller graph for this function:

◆ getShuffler()

assClozeGap::getShuffler ( )
Returns
ilArrayElementShuffler

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

334 {
335 if ($this->shuffler == null) {
336 $this->setShuffler();
337 }
338 return $this->shuffler;
339 }
setShuffler(ilArrayElementShuffler $shuffler=null)

References $shuffler, and setShuffler().

+ Here is the call graph for this function:

◆ getType()

assClozeGap::getType ( )

Gets the cloze gap type.

Gets the cloze gap type

Returns
integer cloze gap type
See also
$type for mapping.

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

77 {
78 return $this->type;
79 }
$type
Type of gap.

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

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

References TYPE_NUMERIC.

◆ isSelectGap()

assClozeGap::isSelectGap ( )

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

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

References TYPE_SELECT.

◆ isTextGap()

assClozeGap::isTextGap ( )

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

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

References TYPE_TEXT.

◆ numericRangeExists()

assClozeGap::numericRangeExists ( )

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

452 {
453 if ($this->getType() != CLOZE_NUMERIC) {
454 return false;
455 }
456
457 require_once 'Services/Math/classes/class.EvalMath.php';
458 $math = new EvalMath();
459
460 $item = $this->getItem(0);
461 $lowerBound = $math->evaluate($item->getLowerBound());
462 $upperBound = $math->evaluate($item->getUpperBound());
463 $preciseValue = $math->evaluate($item->getAnswertext());
464
465 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
466 return true;
467 }
468
469 return false;
470 }
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 (   $gap_size)
Parameters
integer$gap_size

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

439 {
440 $this->gap_size = $gap_size;
441 }

References $gap_size.

◆ setItemLowerBound()

assClozeGap::setItemLowerBound (   $order,
  $bound 
)

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

235 {
236 foreach ($this->items as $key => $item) {
237 if ($item->getOrder() == $order) {
238 $item->setLowerBound($bound);
239 }
240 }
241 }

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

197 {
198 foreach ($this->items as $key => $item) {
199 if ($item->getOrder() == $order) {
200 $item->setPoints($points);
201 }
202 }
203 }

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

254 {
255 foreach ($this->items as $key => $item) {
256 if ($item->getOrder() == $order) {
257 $item->setUpperBound($bound);
258 }
259 }
260 }

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

302 {
303 $this->shuffle = (bool) $a_shuffle;
304 }

◆ setShuffler()

assClozeGap::setShuffler ( ilArrayElementShuffler  $shuffler = null)
Parameters
ilArrayElementShuffler$shuffler

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

320 {
321 if ($shuffler == null) {
322 require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
324 $seed = $shuffler->buildRandomSeed();
325 $shuffler->setSeed($seed);
326 }
327 $this->shuffler = $shuffler;
328 }

References $shuffler.

Referenced by getShuffler().

+ Here is the caller graph for this function:

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

104 {
105 $this->type = $a_type;
106 }

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

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

Referenced by getGapSize(), and setGapSize().

◆ $items

assClozeGap::$items

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

Referenced by getItems(), and getItemsRaw().

◆ $shuffle

assClozeGap::$shuffle

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

Referenced by getShuffle().

◆ $shuffler

assClozeGap::$shuffler
private

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

Referenced by getItems(), getShuffler(), and setShuffler().

◆ $type

int assClozeGap::$type

Type of gap.

An integer value indicating the type of the gap 0 == text gap, 1 == select gap, 2 == numeric gap

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