ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MarksDatabaseRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 private const DB_TABLE = 'tst_mark';
26
27
28 public function __construct(
29 private readonly \ilDBInterface $db
30 ) {
31 }
32
33 public function getMarkSchemaFor(int $test_id): MarkSchema
34 {
35 $schema = new MarkSchema($test_id);
36
37 $result = $this->db->queryF(
38 'SELECT * FROM ' . self::DB_TABLE . ' WHERE test_fi = %s ORDER BY minimum_level',
39 ['integer'],
40 [$test_id]
41 );
42 if ($this->db->numRows($result) > 0) {
43 $mark_steps = [];
44 while ($data = $this->db->fetchAssoc($result)) {
45 $mark_steps[] = new Mark(
46 $data['short_name'],
47 $data['official_name'],
48 (float) $data['minimum_level'],
49 (bool) $data['passed']
50 );
51 }
52 return $schema->withMarkSteps($mark_steps);
53 }
54
55 return $schema->createSimpleSchema();
56 }
57
58 public function storeMarkSchema(MarkSchema $mark_schema): void
59 {
60 if (!$mark_schema->getTestId()) {
61 return;
62 }
63 // Delete all entries
64 $this->db->manipulateF(
65 'DELETE FROM ' . self::DB_TABLE . ' WHERE test_fi = %s',
66 ['integer'],
67 [$mark_schema->getTestId()]
68 );
69 if ($mark_schema->getMarkSteps() === []) {
70 return;
71 }
72
73 // Write new datasets
74 foreach ($mark_schema->getMarkSteps() as $mark) {
75 $mark_array = $mark->toStorage();
76 $mark_array['mark_id'] = ['integer', $this->db->nextId(self::DB_TABLE)];
77 $mark_array['test_fi'] = ['integer', $mark_schema->getTestId()];
78 $this->db->insert(
79 self::DB_TABLE,
80 $mark_array
81 );
82 }
83 }
84}
A class defining mark schemas for assessment test objects.
Definition: MarkSchema.php:36
A class defining marks for assessment test objects.
Definition: Mark.php:36
__construct(private readonly \ilDBInterface $db)
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...