ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 public function __construct(
28 private readonly \ilDBInterface $db,
29 private readonly MarkSchemaFactory $factory
30 ) {
31 }
32
33 public function getMarkSchemaFor(int $test_id): MarkSchema
34 {
35 $result = $this->db->queryF(
36 'SELECT * FROM ' . self::DB_TABLE . ' WHERE test_fi = %s ORDER BY minimum_level',
38 [$test_id],
39 );
40
41 return $this->factory->createMarkSchemaFromDBRow($this->db->fetchAll($result), $test_id);
42 }
43
44 public function getMarkSchemaBySteps(array $step_ids): MarkSchema
45 {
46 $where_part = $this->db->in('mark_id', $step_ids, false, \ilDBConstants::T_INTEGER);
47 $result = $this->db->query('SELECT * FROM ' . self::DB_TABLE . ' WHERE ' . $where_part . ' ORDER BY minimum_level');
48
49 return $this->factory->createMarkSchemaFromDBRow($this->db->fetchAll($result), -1);
50 }
51
52 public function storeMarkSchema(MarkSchema $mark_schema): array
53 {
54 if (!$mark_schema->getTestId()) {
55 return [];
56 }
57
58 if ($mark_schema->getTestId() > 0) {
59 // Delete all entries
60 $this->db->manipulateF(
61 'DELETE FROM ' . self::DB_TABLE . ' WHERE test_fi = %s',
62 ['integer'],
63 [$mark_schema->getTestId()]
64 );
65 }
66
67 if ($mark_schema->getMarkSteps() === []) {
68 return [];
69 }
70
71 // Write new datasets
72 $mark_ids = [];
73 foreach ($mark_schema->getMarkSteps() as $mark) {
74 $mark_id = $this->db->nextId(self::DB_TABLE);
75
76 $mark_array = $mark->toStorage();
77 $mark_array['mark_id'] = ['integer', $mark_id];
78 $mark_array['test_fi'] = ['integer', $mark_schema->getTestId()];
79
80 $this->db->insert(
81 self::DB_TABLE,
82 $mark_array
83 );
84 $mark_ids[] = $mark_id;
85 }
86
87 return $mark_ids;
88 }
89
90 public function deleteSteps(array $step_ids): void
91 {
92 $where_part = $this->db->in('mark_id', $step_ids, false, \ilDBConstants::T_INTEGER);
93 $this->db->manipulate('DELETE FROM ' . self::DB_TABLE . ' WHERE ' . $where_part);
94 }
95}
factory()
A class defining mark schemas for assessment test objects.
Definition: MarkSchema.php:37
__construct(private readonly \ilDBInterface $db, private readonly MarkSchemaFactory $factory)
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...