ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assAnswerBinaryStateImage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
40{
41 protected ?string $image = null;
42
53 public function __construct(
54 string $answertext = '',
55 float $points = 0.0,
56 int $order = 0,
57 bool $state = false,
58 ?string $a_image = null,
59 int $id = -1
60 ) {
62 $this->setImage($a_image);
63 }
64
65 public function getImage(): ?string
66 {
67 return $this->image;
68 }
69
70 public function setImage(?string $image = null): void
71 {
72 if ($image === '') {
73 throw new \Exception('imagename must not be empty');
74 }
75 $this->image = $image;
76 }
77
78 public function hasImage(): bool
79 {
80 return $this->image !== null;
81 }
82
83 #[\Override]
84 public function toNormalized(
85 Transformations $transformations,
86 array $context = []
87 ): array|float|bool|int|string|null
88 {
89 return [
90 ...$transformations->normalize(parent::toNormalized($transformations, $context)),
91 'image' => $this->image ?
92 $transformations->normalize(new QuestionImage($this->image, $context['question_id'] ?? null))
93 : null,
94 ];
95 }
96
97 #[\Override]
98 public function fromNormalized(
99 array $normalized,
100 Transformations $transformations
101 ): static
102 {
103 $clone = parent::fromNormalized($normalized, $transformations);
104 $clone->setImage($transformations->denormalize($normalized['image'], QuestionImage::class)?->getFilename());
105 return $clone;
106 }
107}
Class for answers with a binary state indicator.
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 $answertext='', float $points=0.0, int $order=0, bool $state=false, ?string $a_image=null, int $id=-1)
ASS_AnswerBinaryStateImage constructor The constructor takes possible arguments an creates an instanc...
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