ILIAS  release_8 Revision v8.24
class.ilObjTestScoreSettingsDatabaseRepository.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22{
23 public const TABLE_NAME = 'tst_tests';
24 public const STORAGE_DATE_FORMAT = 'YmdHis';
25
26 protected ilDBInterface $db;
27
28 public function __construct(ilDBInterface $db)
29 {
30 $this->db = $db;
31 }
32
33 public function getForObjFi(int $obj_fi): ilObjTestScoreSettings
34 {
35 $where_part = 'WHERE obj_fi = ' . $this->db->quote($obj_fi, 'integer');
36 return $this->doSelect($where_part);
37 }
38
39 public function getFor(int $test_id): ilObjTestScoreSettings
40 {
41 $where_part = 'WHERE test_id = ' . $this->db->quote($test_id, 'integer');
42 return $this->doSelect($where_part);
43 }
44
45 protected function doSelect(string $where_part): ilObjTestScoreSettings
46 {
47 $query = 'SELECT ' . PHP_EOL
48 . 'test_id,' . PHP_EOL
49 . 'count_system, score_cutting, pass_scoring,' . PHP_EOL
50 . 'score_reporting, reporting_date,' . PHP_EOL
51 . 'show_grading_status, show_grading_mark, pass_deletion_allowed,' . PHP_EOL
52 . 'print_bs_with_res,' . PHP_EOL //print_bs_with_res_sp
53 . 'examid_in_test_res,' . PHP_EOL
54 . 'results_presentation,' . PHP_EOL
55 . 'exportsettings,' . PHP_EOL
56 . 'highscore_enabled, highscore_anon, highscore_achieved_ts, highscore_score, highscore_percentage, highscore_hints, highscore_wtime, highscore_own_table, highscore_top_table, highscore_top_num,' . PHP_EOL
57 . 'result_tax_filters' . PHP_EOL
58 . 'FROM ' . self::TABLE_NAME . PHP_EOL
59 . $where_part;
60
61 $res = $this->db->query($query);
62
63 if ($this->db->numRows($res) == 0) {
64 throw new \Exception('no score settings: ' . $where_part);
65 }
66
67 $row = $this->db->fetchAssoc($res);
68
69 $reporting_date = $row['reporting_date'];
70 if ($reporting_date) {
71 $reporting_date = \DateTimeImmutable::createFromFormat(
72 self::STORAGE_DATE_FORMAT,
73 $reporting_date,
74 new DateTimeZone('UTC')
75 );
76 } else {
77 $reporting_date = null;
78 }
79
80 $test_id = (int) $row['test_id'];
81 $tax_filter_ids = unserialize((string) ($row['result_tax_filters']));
82 if ($tax_filter_ids === false) {
83 $tax_filter_ids = [];
84 }
85
87 $test_id,
88 (new ilObjTestSettingsScoring($test_id))
89 ->withCountSystem((int) $row['count_system'])
90 ->withScoreCutting((int) $row['score_cutting'])
91 ->withPassScoring((int) $row['pass_scoring']),
92 (new ilObjTestSettingsResultSummary($test_id))
93 ->withScoreReporting((int) $row['score_reporting'])
94 ->withReportingDate($reporting_date)
95 ->withShowGradingStatusEnabled((bool) $row['show_grading_status'])
96 ->withShowGradingMarkEnabled((bool) $row['show_grading_mark'])
97 ->withPassDeletionAllowed((bool) $row['pass_deletion_allowed']),
98 //->withShowPassDetails derived from results_presentation with bit RESULTPRES_BIT_PASS_DETAILS
99 (new ilObjTestSettingsResultDetails($test_id))
100 ->withResultsPresentation((int)$row['results_presentation'])
101 ->withPrintBestSolutionWithResult((bool) $row['print_bs_with_res'])
102 ->withShowExamIdInTestResults((bool) $row['examid_in_test_res'])
103 ->withExportSettings((int) $row['exportsettings'])
104 ->withTaxonomyFilterIds($tax_filter_ids),
105 (new ilObjTestSettingsGamification($test_id))
106 ->withHighscoreEnabled((bool) $row['highscore_enabled'])
107 ->withHighscoreAnon((bool) $row['highscore_anon'])
108 ->withHighscoreAchievedTS((bool) $row['highscore_achieved_ts'])
109 ->withHighscoreScore((bool) $row['highscore_score'])
110 ->withHighscorePercentage((bool) $row['highscore_percentage'])
111 ->withHighscoreHints((bool) $row['highscore_hints'])
112 ->withHighscoreWTime((bool) $row['highscore_wtime'])
113 ->withHighscoreOwnTable((bool) $row['highscore_own_table'])
114 ->withHighscoreTopTable((bool) $row['highscore_top_table'])
115 ->withHighscoreTopNum((int) $row['highscore_top_num'])
116 );
117
118 return $settings;
119 }
120
122 {
123 $values = array_merge(
124 $settings->getScoringSettings()->toStorage(),
125 $settings->getResultSummarySettings()->toStorage(),
126 $settings->getResultDetailsSettings()
127 ->withShowPassDetails($settings->getResultSummarySettings()->getShowPassDetails())
128 ->toStorage(),
129 $settings->getGamificationSettings()->toStorage()
130 );
131
132 $this->db->update(
133 self::TABLE_NAME,
134 $values,
135 ['test_id' => ['integer', $settings->getTestId()]]
136 );
137 }
138}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$query