ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerMultipleResponseImage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
37{
38 public ?string $image = null;
39
53 public function __construct(
54 string $answertext = '',
55 float $points = 0.0,
56 int $order = 0,
57 int $id = -1,
58 int $state = 0
59 ) {
61 }
62
63 public function getImage(): ?string
64 {
65 return $this->image;
66 }
67
68 public function setImage(?string $image = null): void
69 {
70 if ($image === '') {
71 throw new \Exception('imagename must not be empty');
72 }
73 $this->image = $image;
74 }
75
76 public function hasImage(): bool
77 {
78 return $this->image !== null;
79 }
80
81 #[\Override]
82 public function toNormalized(
83 Transformations $transformations,
84 array $context = []
85 ): array|float|bool|int|string|null
86 {
87 return [
88 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
89 'image' => $this->image
90 ? $transformations->normalize(new QuestionImage($this->image, $context['question_id'] ?? null))
91 : null,
92 ];
93 }
94
95 #[\Override]
96 public function fromNormalized(
97 array $normalized,
98 Transformations $transformations
99 ): static
100 {
101 $clone = parent::fromNormalized($normalized, $transformations);
102 $clone->setImage($transformations->denormalize($normalized['image'], QuestionImage::class)?->getFilename());
103 return $clone;
104 }
105}
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked,...
fromNormalized(array $normalized, Transformations $transformations)
Restore the object from its normalized representation.
__construct(string $answertext='', float $points=0.0, int $order=0, int $id=-1, int $state=0)
ASS_AnswerMultipleResponse constructor.
toNormalized(Transformations $transformations, array $context=[])
Convert the internal state of the implementing object into a language-neutral array structure.
Class for true/false or yes/no answers.
Provides a set of transformations for normalizing and denormalizing values.
denormalize(array|float|bool|int|string|null $normalized, string|object $expected)
Wrapper object for an image file within a question (e.g.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc