ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Attempt.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Questions\Persistence\Factory as PersistenceFactory;
28
30{
31 public const string KEY_ADDITONAL_DATA = 'additional_data';
32 public const string KEY_RESPONSES = 'responses';
33
37 private array $responses = [];
38
39 public function __construct(
40 private readonly Uuid $identifier,
41 private readonly int $shuffle_questions_seed,
42 private array $additional_data = []
43 ) {
44 }
45
46 public function getId(): Uuid
47 {
48 return $this->identifier;
49 }
50
52 {
53 return new GivenSeed($this->shuffle_questions_seed);
54 }
55
56 public function getAdditionalDataFor(
57 Uuid $parent_id
58 ): ?string {
59 if (!isset($this->additional_data[$parent_id->toString()])) {
60 return null;
61 }
62 return $this->additional_data[$parent_id->toString()];
63 }
64
65 public function withAdditionalData(
66 Uuid $parent_id,
67 string $data
68 ): self {
69 if (isset($this->additional_data[$parent_id->toString()])) {
71 'This is a storage for data that stays constant accross the test run.'
72 . 'Data cannot be changed one it is set.'
73 );
74 }
75
76 $clone = clone $this;
77 $clone->additional_data[$parent_id->toString()] = $data;
78 return $clone;
79 }
80
81 public function getResponseForQuestion(
82 Uuid $question_id
83 ): ?Response {
84 return $this->responses[$question_id->toString()] ?? null;
85 }
86
87 public function withResponse(
89 ): self {
90 $clone = clone $this;
91 $clone->responses[$response->getQuestionId()->toString()] = $response;
92 return $clone;
93 }
94
95 public function basicDataToStorage(
96 PersistenceFactory $persistence_factory,
97 TableDefinitions $table_definitions,
98 TableNameBuilder $table_names_builder
99 ): Insert {
100 return $persistence_factory->insert(
101 $table_definitions->getColumns(
102 $table_names_builder,
103 TableTypes::AttemptData
104 ),
105 [
106 $persistence_factory->value(
107 \ilDBConstants::T_TEXT,
108 $this->identifier->toString()
109 ),
110 $persistence_factory->value(
111 \ilDBConstants::T_INTEGER,
112 $this->shuffle_questions_seed
113 )
114 ]
115 );
116 }
117
118 public function additionalDataToStorage(
119 PersistenceFactory $persistence_factory,
120 TableDefinitions $table_definitions,
121 TableNameBuilder $table_names_builder
122 ): ?Insert {
123 return array_reduce(
124 array_keys($this->additional_data),
125 fn(?Insert $c, string $v): Insert
126 => $this->buildAdditionalDataInsert(
127 $persistence_factory,
128 $table_definitions,
129 $table_names_builder,
130 $c,
131 $v
132 )
133 );
134 }
135
136 public function toPreviewStorage(): string
137 {
138 return json_encode(
139 [
140 self::KEY_ADDITONAL_DATA => $this->additional_data,
141 self::KEY_RESPONSES => array_map(
142 fn(Response $v): array => $v->toPreviewStorage(),
143 $this->responses
144 )
145 ]
146 );
147 }
148
150 PersistenceFactory $persistence_factory,
151 TableDefinitions $table_definitions,
152 TableNameBuilder $table_names_builder,
153 ?Insert $insert,
154 string $parent_id
155 ): Insert {
156 if ($insert === null) {
157 return $persistence_factory->insert(
158 $table_definitions->getColumns(
159 $table_names_builder,
160 TableTypes::AdditionalAttemptData
161 ),
162 $this->buildAdditionalDataValuesArray(
163 $persistence_factory,
164 $parent_id
165 )
166 );
167 }
168
169 return $insert->withAdditionalValues(
170 $this->buildAdditionalDataValuesArray(
171 $persistence_factory,
172 $parent_id
173 )
174 );
175 }
176
178 PersistenceFactory $persistence_factory,
179 string $parent_id
180 ): array {
181 return [
182 $persistence_factory->value(
183 \ilDBConstants::T_TEXT,
184 $this->identifier->toString()
185 ),
186 $persistence_factory->value(
187 \ilDBConstants::T_TEXT,
188 $parent_id
189 ),
190 $persistence_factory->value(
191 \ilDBConstants::T_TEXT,
192 $this->additional_data[$parent_id]
193 )
194 ];
195 }
196}
Class Exception Thrown if some procedure did not get the arguments it expected.
buildAdditionalDataValuesArray(PersistenceFactory $persistence_factory, string $parent_id)
Definition: Attempt.php:177
withAdditionalData(Uuid $parent_id, string $data)
Definition: Attempt.php:65
basicDataToStorage(PersistenceFactory $persistence_factory, TableDefinitions $table_definitions, TableNameBuilder $table_names_builder)
Definition: Attempt.php:95
getAdditionalDataFor(Uuid $parent_id)
Definition: Attempt.php:56
__construct(private readonly Uuid $identifier, private readonly int $shuffle_questions_seed, private array $additional_data=[])
Definition: Attempt.php:39
getResponseForQuestion(Uuid $question_id)
Definition: Attempt.php:81
const string KEY_ADDITONAL_DATA
Definition: Attempt.php:31
buildAdditionalDataInsert(PersistenceFactory $persistence_factory, TableDefinitions $table_definitions, TableNameBuilder $table_names_builder, ?Insert $insert, string $parent_id)
Definition: Attempt.php:149
withResponse(Response $response)
Definition: Attempt.php:87
additionalDataToStorage(PersistenceFactory $persistence_factory, TableDefinitions $table_definitions, TableNameBuilder $table_names_builder)
Definition: Attempt.php:118
getColumns(TableNameBuilder $table_names_builder, TableTypesInterface $table_type)
Class ilDBConstants.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
$data
Definition: storeScorm.php:45
$response
Definition: xapitoken.php:92