ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
assSuggestedSolutionFile.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
20 namespace ILIAS\TA\Questions;
21 
28 {
29  public const ARRAY_KEY_FILENAME = 'name';
30  public const ARRAY_KEY_TITLE = 'filename';
31  public const ARRAY_KEY_MIME = 'type';
32  public const ARRAY_KEY_SIZE = 'size';
33 
34  protected string $filename;
35  protected string $mime;
36  protected int $size = 0;
37  protected string $title;
38 
39  public function __construct(
40  int $id,
41  int $question_id,
43  string $import_id,
45  string $type,
46  string $value
47  ) {
48  parent::__construct($id, $question_id, $subquestion_index, $import_id, $last_update);
49  $v = unserialize($value, []);
50 
51  $this->title = $v[self::ARRAY_KEY_TITLE] ?? '';
52  $this->filename = $v[self::ARRAY_KEY_FILENAME] ?? '';
53  $this->size = $v[self::ARRAY_KEY_SIZE] ?? 0;
54  $this->mime = $v[self::ARRAY_KEY_MIME] ?? '';
55  }
56 
57  public function getType(): string
58  {
59  return parent::TYPE_FILE;
60  }
61 
62  public function getStorableValue(): string
63  {
64  return serialize([
65  self::ARRAY_KEY_FILENAME => $this->getFilename(),
66  self::ARRAY_KEY_MIME => $this->getMime(),
67  self::ARRAY_KEY_SIZE => $this->getSize(),
68  self::ARRAY_KEY_TITLE => $this->getTitle()
69  ]);
70  }
71 
72  public function getTitle(): string
73  {
74  if ($this->title) {
75  return $this->title;
76  }
77  return $this->filename;
78  }
79  public function withTitle(string $title): static
80  {
81  $clone = clone $this;
82  $clone->title = $title;
83  return $clone;
84  }
85 
86  public function getMime(): string
87  {
88  return $this->mime;
89  }
90  public function withMime(string $mime): static
91  {
92  $clone = clone $this;
93  $clone->mime = $mime;
94  return $clone;
95  }
96 
97  public function getSize(): int
98  {
99  return $this->size;
100  }
101  public function withSize(int $size): static
102  {
103  $clone = clone $this;
104  $clone->size = $size;
105  return $clone;
106  }
107 
108  public function getFilename(): string
109  {
110  return $this->filename;
111  }
112  public function withFilename(string $filename): static
113  {
114  $clone = clone $this;
115  $clone->filename = $filename;
116  return $clone;
117  }
118 }
__construct(int $id, int $question_id, int $subquestion_index, string $import_id, \DateTimeImmutable $last_update, string $type, string $value)
__construct(VocabulariesInterface $vocabularies)
a suggested solution for file-contents
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...