ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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...
 
 setType ($a_type=0)
 Sets the cloze gap type. More...
 
 getItems (ilArrayElementShuffler $shuffler)
 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 (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

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

59 {
60 $this->type = $a_type;
61 $this->items = array();
62 $this->shuffle = true;
63 }
$a_type
Definition: workflow.php:92

References $a_type.

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

144 {
145 $order = $a_item->getOrder();
146 if (array_key_exists($order, $this->items)) {
147 $newitems = array();
148 for ($i = 0; $i < $order; $i++) {
149 array_push($newitems, $this->items[$i]);
150 }
151 array_push($newitems, $a_item);
152 for ($i = $order; $i < count($this->items); $i++) {
153 array_push($newitems, $this->items[$i]);
154 }
155 $i = 0;
156 foreach ($newitems as $idx => $item) {
157 $newitems[$idx]->setOrder($i);
158 $i++;
159 }
160 $this->items = $newitems;
161 } else {
162 array_push($this->items, $a_item);
163 }
164 }
$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 271 of file class.assClozeGap.php.

272 {
273 $this->items = array();
274 }

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

195 {
196 if (array_key_exists($order, $this->items)) {
197 unset($this->items[$order]);
198 $order = 0;
199 foreach ($this->items as $key => $item) {
200 $this->items[$key]->setOrder($order);
201 $order++;
202 }
203 }
204 }

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

326 {
327 $maxpoints = 0;
328 foreach ($this->items as $key => $item) {
329 if ($item->getPoints() > $maxpoints) {
330 $maxpoints = $item->getPoints();
331 }
332 }
333 $keys = array();
334 foreach ($this->items as $key => $item) {
335 if ($item->getPoints() == $maxpoints) {
336 array_push($keys, $key);
337 }
338 }
339 return $keys;
340 }
$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 347 of file class.assClozeGap.php.

348 {
349 global $DIC;
350 $lng = $DIC['lng'];
351 switch ($this->getType()) {
352 case CLOZE_TEXT:
353 case CLOZE_SELECT:
354 $best_solutions = array();
355 if ($combinations !== null && $combinations['best_solution'] == 1) {
356 $best_solutions[$combinations['points']] = array();
357 array_push($best_solutions[$combinations['points']], $combinations['answer']);
358 } else {
359 foreach ($this->getItems($shuffler) as $answer) {
360 if (isset($best_solutions[$answer->getPoints()]) && is_array($best_solutions[$answer->getPoints()])) {
361 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
362 } else {
363 $best_solutions[$answer->getPoints()] = array();
364 array_push($best_solutions[$answer->getPoints()], $answer->getAnswertext());
365 }
366 }
367 }
368
369 krsort($best_solutions, SORT_NUMERIC);
370 reset($best_solutions);
371 $found = current($best_solutions);
372 return join(" " . $lng->txt("or") . " ", $found);
373 break;
374 case CLOZE_NUMERIC:
375 $maxpoints = 0;
376 $foundvalue = "";
377 foreach ($this->getItems($shuffler) as $answer) {
378 if ($answer->getPoints() >= $maxpoints) {
379 $maxpoints = $answer->getPoints();
380 $foundvalue = $answer->getAnswertext();
381 }
382 }
383 return $foundvalue;
384 break;
385 default:
386 return "";
387 }
388 }
getItems(ilArrayElementShuffler $shuffler)
Gets the items of a cloze gap.
getType()
Gets the cloze gap type.
const CLOZE_NUMERIC
const CLOZE_SELECT
const CLOZE_TEXT
Cloze question constants.
$lng
$DIC
Definition: xapitoken.php:46

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

402 {
403 return $this->gap_size;
404 }

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

255 {
256 if (array_key_exists($a_index, $this->items)) {
257 return $this->items[$a_index];
258 } else {
259 return null;
260 }
261 }

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

130 {
131 return count($this->items);
132 }

◆ getItems()

assClozeGap::getItems ( ilArrayElementShuffler  $shuffler)

Gets the items of a cloze gap.

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

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

98 {
99 if ($this->getShuffle()) {
100 return $shuffler->shuffle($this->items);
101 }
102
103 return $this->items;
104 }
getShuffle()
Gets the shuffle state of the items.

References $items, getShuffle(), and ilArrayElementShuffler\shuffle().

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

116 {
117 return $this->items;
118 }

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

307 {
308 $maxwidth = 0;
309 foreach ($this->items as $item) {
310 if (strlen($item->getAnswertext()) > $maxwidth) {
311 $maxwidth = strlen($item->getAnswertext());
312 }
313 }
314 return $maxwidth;
315 }

◆ getShuffle()

assClozeGap::getShuffle ( )

Gets the shuffle state of the items.

Returns
boolean Shuffle state

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

294 {
295 return $this->shuffle;
296 }

References $shuffle.

Referenced by getItems().

+ Here is the caller 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 74 of file class.assClozeGap.php.

75 {
76 return $this->type;
77 }
$type
Type of gap.

References $type.

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

+ Here is the caller graph for this function:

◆ numericRangeExists()

assClozeGap::numericRangeExists ( )

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

407 {
408 if ($this->getType() != CLOZE_NUMERIC) {
409 return false;
410 }
411
412 require_once 'Services/Math/classes/class.EvalMath.php';
413 $math = new EvalMath();
414
415 $item = $this->getItem(0);
416 $lowerBound = $math->evaluate($item->getLowerBound());
417 $upperBound = $math->evaluate($item->getUpperBound());
418 $preciseValue = $math->evaluate($item->getAnswertext());
419
420 if ($lowerBound < $preciseValue || $upperBound > $preciseValue) {
421 return true;
422 }
423
424 return false;
425 }
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 393 of file class.assClozeGap.php.

394 {
395 $this->gap_size = $gap_size;
396 }

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

217 {
218 foreach ($this->items as $key => $item) {
219 if ($item->getOrder() == $order) {
220 $item->setLowerBound($bound);
221 }
222 }
223 }

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

177 {
178 foreach ($this->items as $key => $item) {
179 if ($item->getOrder() == $order) {
180 $item->setPoints($points);
181 }
182 }
183 }

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

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

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

284 {
285 $this->shuffle = (bool) $a_shuffle;
286 }

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

87 {
88 $this->type = $a_type;
89 }

References $a_type.

Field Documentation

◆ $gap_size

assClozeGap::$gap_size = 0
private

Definition at line 50 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().

◆ $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: