ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SuggestedSolutionFile.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 public const ARRAY_KEY_FILENAME = 'name';
31 public const ARRAY_KEY_TITLE = 'filename';
32 public const ARRAY_KEY_MIME = 'type';
33 public const ARRAY_KEY_SIZE = 'size';
34
35 protected string $filename;
36 protected string $mime;
37 protected int $size = 0;
38 protected string $title;
39
40 public function __construct(
41 int $id,
42 int $question_id,
44 string $import_id,
45 \DateTimeImmutable $last_update,
46 string $type,
47 string $value
48 ) {
50 $v = unserialize($value, []);
51
52 $this->title = $v[self::ARRAY_KEY_TITLE] ?? '';
53 $this->filename = $v[self::ARRAY_KEY_FILENAME] ?? '';
54 $this->size = $v[self::ARRAY_KEY_SIZE] ?? 0;
55 $this->mime = $v[self::ARRAY_KEY_MIME] ?? '';
56 }
57
58 public function getType(): string
59 {
60 return parent::TYPE_FILE;
61 }
62
63 public function getStorableValue(): string
64 {
65 return serialize([
66 self::ARRAY_KEY_FILENAME => $this->getFilename(),
67 self::ARRAY_KEY_MIME => $this->getMime(),
68 self::ARRAY_KEY_SIZE => $this->getSize(),
69 self::ARRAY_KEY_TITLE => $this->getTitle()
70 ]);
71 }
72
73 public function getTitle(): string
74 {
75 if ($this->title) {
76 return $this->title;
77 }
78 return $this->filename;
79 }
80 public function withTitle(string $title): static
81 {
82 $clone = clone $this;
83 $clone->title = $title;
84 return $clone;
85 }
86
87 public function getMime(): string
88 {
89 return $this->mime;
90 }
91 public function withMime(string $mime): static
92 {
93 $clone = clone $this;
94 $clone->mime = $mime;
95 return $clone;
96 }
97
98 public function getSize(): int
99 {
100 return $this->size;
101 }
102 public function withSize(int $size): static
103 {
104 $clone = clone $this;
105 $clone->size = $size;
106 return $clone;
107 }
108
109 public function getFilename(): string
110 {
111 return $this->filename;
112 }
113 public function withFilename(string $filename): static
114 {
115 $clone = clone $this;
116 $clone->filename = $filename;
117 return $clone;
118 }
119}
__construct(int $id, int $question_id, int $subquestion_index, string $import_id, \DateTimeImmutable $last_update, string $type, string $value)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc