ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerErrorText.php
Go to the documentation of this file.
1<?php
2
22
32{
33 protected string $text_wrong;
34 protected string $text_correct;
35 protected float $points;
36 protected ?int $position;
37 protected int $length;
38
45 public function __construct(
46 string $text_wrong = "",
47 string $text_correct = "",
48 float $points = 0.0,
49 ?int $position = null
50 ) {
51 $this->text_wrong = $text_wrong;
52 $this->text_correct = $text_correct;
53 $this->points = $points;
54 $this->position = $position;
55
56 $word_array = preg_split("/\s+/", $text_wrong);
57
58 if ($word_array) {
59 $this->length = count($word_array);
60 }
61 }
62
63 public function getTextWrong(): string
64 {
65 return $this->text_wrong;
66 }
67
68 public function getTextCorrect(): string
69 {
71 }
72
73 public function getPoints(): float
74 {
75 return $this->points;
76 }
77
78 public function withPoints(float $points): self
79 {
80 $clone = clone $this;
81 $clone->points = $points;
82 return $clone;
83 }
84
85 public function getPosition(): ?int
86 {
87 return $this->position;
88 }
89
90 public function withPosition(int $position): self
91 {
92 $clone = clone $this;
93 $clone->position = $position;
94 return $clone;
95 }
96
97 public function getLength(): int
98 {
99 return $this->length;
100 }
101
102 #[\Override]
103 public function toNormalized(
104 Transformations $transformations,
105 array $context = []
106 ): array|float|bool|int|string|null
107 {
108 return [
109 'text_wrong' => $this->text_wrong,
110 'text_correct' => $this->text_correct,
111 'points' => $this->points,
112 'position' => $this->position,
113 ];
114 }
115
116 #[\Override]
117 public function fromNormalized(
118 array $normalized,
119 Transformations $transformations
120 ): self
121 {
122 return new self(
123 $transformations->string($normalized['text_wrong']),
124 $transformations->string($normalized['text_correct']),
125 $transformations->float($normalized['points']),
126 $transformations->int($normalized['position'])
127 );
128 }
129}
Provides a set of transformations for normalizing and denormalizing values.
Class for error text answers.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
__construct(string $text_wrong="", string $text_correct="", float $points=0.0, ?int $position=null)
assAnswerErrorText constructor