ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerMatchingPair.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
32{
35 protected float $points;
36
37 public function __construct(
40 float $points = 0.0
41 ) {
42 $this->term = $term;
43 $this->definition = $definition;
44 $this->points = $points;
45 }
46
47 public function getTerm(): assAnswerMatchingTerm
48 {
49 return $this->term;
50 }
51 public function withTerm(assAnswerMatchingTerm $term): self
52 {
53 $clone = clone $this;
54 $clone->term = $term;
55 return $clone;
56 }
57
59 {
60 return $this->definition;
61 }
63 {
64 $clone = clone $this;
65 $clone->definition = $definition;
66 return $clone;
67 }
68
69 public function getPoints(): float
70 {
71 return $this->points;
72 }
73 public function withPoints(float $points): self
74 {
75 $clone = clone $this;
76 $clone->points = $points;
77 return $clone;
78 }
79
80 #[\Override]
81 public function toNormalized(
82 Transformations $transformations,
83 array $context = []
84 ): array|float|bool|int|string|null
85 {
86 return [
87 'points' => $this->points,
88 'term' => $transformations->normalize($this->term, $context),
89 'definition' => $transformations->normalize($this->definition, $context),
90 ];
91 }
92
93 #[\Override]
94 public function fromNormalized(
95 array $normalized,
96 Transformations $transformations
97 ): self
98 {
99 return $this->withPoints($transformations->float($normalized['points']))
100 ->withTerm($transformations->denormalize($normalized['term'], $this->term))
101 ->withDefinition($transformations->denormalize($normalized['definition'], $this->definition));
102 }
103}
Provides a set of transformations for normalizing and denormalizing values.
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)
Class for matching question definitions.
Class for matching question pairs.
assAnswerMatchingDefinition $definition
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
withTerm(assAnswerMatchingTerm $term)
withDefinition(assAnswerMatchingDefinition $definition)
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
__construct(assAnswerMatchingTerm $term, assAnswerMatchingDefinition $definition, float $points=0.0)
Class for matching question terms.