ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assAnswerCloze Class Reference

Class for cloze question numeric answers. More...

+ Inheritance diagram for assAnswerCloze:
+ Collaboration diagram for assAnswerCloze:

Public Member Functions

 __construct (string $answertext="", float $points=0.0, int $order=0, int $id=-1, int $state=0)
 assAnswerCloze constructor More...
 
 setLowerBound (string $bound)
 Sets the lower boind. More...
 
 setUpperBound (string $bound)
 Sets the upper bound. More...
 
 getLowerBound ()
 Returns the lower bound. More...
 
 getUpperBound ()
 Returns the upper bound. More...
 
 setGapSize (int $gap_size)
 
 getGapSize ()
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 
- Public Member Functions inherited from ASS_AnswerSimple
 __construct ($answertext="", $points=0.0, $order=0, $id=-1)
 ASS_AnswerSimple constructor. More...
 
 getId ()
 Gets the answer id. More...
 
 getAnswertext ()
 Gets the answer text. More...
 
 getPoints ()
 Gets the points. More...
 
 checkPoints ($a_points)
 Checks, if the point value is numeric. More...
 
 getOrder ()
 Gets the sort/display order. More...
 
 setOrder ($order=0)
 Sets the order. More...
 
 setId ($id=-1)
 Sets the answer id. More...
 
 setAnswertext ($answertext="")
 Sets the answer text. More...
 
 setPoints ($points=0.0)
 Sets the points. More...
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 
 toNormalized (Transformations $transformations, array $context=[])
 Convert the internal state of the implementing object into a language-neutral array structure. More...
 
 fromNormalized (array $normalized, Transformations $transformations)
 Restore the object from its normalized representation. More...
 

Protected Member Functions

 getNumericValueFromAnswerText ()
 
 getNumericValueFromText ($text)
 

Protected Attributes

string $lowerBound
 
string $upperBound
 
int $gap_size
 
- Protected Attributes inherited from ASS_AnswerSimple
string $answertext
 
 $points
 
 $order
 
 $id
 

Detailed Description

Class for cloze question numeric answers.

assAnswerCloze is a class for cloze questions numeric answers.

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$

\

See also
ASS_AnswerBinaryState

@TODO Rework class to represent bounds as numerics instead of strings.

Definition at line 37 of file class.assAnswerCloze.php.

Constructor & Destructor Documentation

◆ __construct()

assAnswerCloze::__construct ( string  $answertext = "",
float  $points = 0.0,
int  $order = 0,
int  $id = -1,
int  $state = 0 
)

assAnswerCloze constructor

The constructor takes possible arguments an creates an instance of the assAnswerCloze object.

Parameters
string$answertextA string defining the answer text
double$pointsThe number of points given for the selected answer
integer$orderA nonnegative value representing a possible display or sort order @TODO See if the initialization of the bounds to null can be avoided to have them string/numeric at all times.

Definition at line 64 of file class.assAnswerCloze.php.

65 {
67 $this->lowerBound = null;
68 $this->upperBound = null;
69 $this->gap_size = 0;
70 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ASS_AnswerSimple\$answertext, ASS_AnswerSimple\$id, ASS_AnswerSimple\$order, ASS_AnswerSimple\$points, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ fromNormalized()

assAnswerCloze::fromNormalized ( array  $normalized,
Transformations  $transformations 
)

Restore the object from its normalized representation.

Parameters
array<array-key,mixed>$normalized

Reimplemented from ASS_AnswerSimple.

Definition at line 171 of file class.assAnswerCloze.php.

174 : static
175 {
176 $clone = parent::fromNormalized($normalized, $transformations);
177 $clone->lowerBound = $transformations->nullableString($normalized['lower_bound']);
178 $clone->upperBound = $transformations->nullableString($normalized['upper_bound']);
179 $clone->gap_size = $transformations->int($normalized['gap_size']);
180 return $clone;
181 }

References ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\int(), and ILIAS\TestQuestionPool\ExportImport\Foundation\Normalize\Transformations\nullableString().

+ Here is the call graph for this function:

◆ getGapSize()

assAnswerCloze::getGapSize ( )
Returns
int

Definition at line 151 of file class.assAnswerCloze.php.

151 : int
152 {
153 return $this->gap_size;
154 }

References $gap_size.

◆ getLowerBound()

assAnswerCloze::getLowerBound ( )

Returns the lower bound.

Returns
null|string

Definition at line 125 of file class.assAnswerCloze.php.

125 : ?string
126 {
127 return $this->lowerBound;
128 }

References $lowerBound.

◆ getNumericValueFromAnswerText()

assAnswerCloze::getNumericValueFromAnswerText ( )
protected

Definition at line 107 of file class.assAnswerCloze.php.

108 {
109 return $this->getNumericValueFromText($this->getAnswertext());
110 }
getAnswertext()
Gets the answer text.

References ASS_AnswerSimple\getAnswertext(), and getNumericValueFromText().

Referenced by setLowerBound(), and setUpperBound().

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

◆ getNumericValueFromText()

assAnswerCloze::getNumericValueFromText (   $text)
protected

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

113 {
114 $eval = new EvalMath();
115 $eval->suppress_errors = true;
116 return $eval->e(str_replace(",", ".", ilUtil::stripSlashes($text, false)));
117 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$text
Definition: xapiexit.php:21

References $text, and ilUtil\stripSlashes().

Referenced by getNumericValueFromAnswerText(), setLowerBound(), and setUpperBound().

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

◆ getUpperBound()

assAnswerCloze::getUpperBound ( )

Returns the upper bound.

Returns
null|string

Definition at line 135 of file class.assAnswerCloze.php.

135 : ?string
136 {
137 return $this->upperBound;
138 }

References $upperBound.

◆ setGapSize()

assAnswerCloze::setGapSize ( int  $gap_size)
Parameters
int$gap_size

Definition at line 143 of file class.assAnswerCloze.php.

143 : void
144 {
145 $this->gap_size = $gap_size;
146 }

References $gap_size.

◆ setLowerBound()

assAnswerCloze::setLowerBound ( string  $bound)

Sets the lower boind.

Parameters
$boundstring A string defining the lower bound of an answer for numeric gaps. @TODO: Refactor method to get rid of "locale magic".

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

78 : void
79 {
80 $boundvalue = $this->getNumericValueFromText($bound);
81 $value = $this->getNumericValueFromAnswerText();
82
83 if ($boundvalue === false || $boundvalue > $value) {
84 $this->lowerBound = $this->getAnswertext();
85 } else {
86 $this->lowerBound = $bound;
87 }
88 }

References ASS_AnswerSimple\getAnswertext(), getNumericValueFromAnswerText(), and getNumericValueFromText().

Referenced by assClozeTestGUI\saveNumericGapCorrectionFormProperty().

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

◆ setUpperBound()

assAnswerCloze::setUpperBound ( string  $bound)

Sets the upper bound.

Parameters
$boundstring A string defining the upper bound of an answer for numeric gaps. @TODO: Refactor method to get rid of "locale magic".

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

95 : void
96 {
97 $boundvalue = $this->getNumericValueFromText($bound);
98 $value = $this->getNumericValueFromAnswerText();
99
100 if ($boundvalue === false || $boundvalue < $value) {
101 $this->upperBound = $this->getAnswertext();
102 } else {
103 $this->upperBound = $bound;
104 }
105 }

References ASS_AnswerSimple\getAnswertext(), getNumericValueFromAnswerText(), and getNumericValueFromText().

Referenced by assClozeTestGUI\saveNumericGapCorrectionFormProperty().

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

◆ toNormalized()

assAnswerCloze::toNormalized ( Transformations  $transformations,
array  $context = [] 
)

Convert the internal state of the implementing object into a language-neutral array structure.

The resulting array must contain only null, scalar values (string, int, float, bool) and nested arrays following the same rules.

Parameters
array<string,mixed>$context
Returns
array<array-key, mixed>|float|bool|int|string|null

Reimplemented from ASS_AnswerSimple.

Definition at line 157 of file class.assAnswerCloze.php.

160 : array|float|bool|int|string|null
161 {
162 return [
163 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
164 'lower_bound' => $this->lowerBound,
165 'upper_bound' => $this->upperBound,
166 'gap_size' => $this->gap_size,
167 ];
168 }

References $gap_size, $lowerBound, and $upperBound.

Field Documentation

◆ $gap_size

int assAnswerCloze::$gap_size
protected

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

Referenced by getGapSize(), setGapSize(), and toNormalized().

◆ $lowerBound

string assAnswerCloze::$lowerBound
protected

Definition at line 39 of file class.assAnswerCloze.php.

Referenced by getLowerBound(), and toNormalized().

◆ $upperBound

string assAnswerCloze::$upperBound
protected

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

Referenced by getUpperBound(), and toNormalized().


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