19declare(strict_types=1);
48 $this->mark_steps = [];
54 $clone->test_id = $test_id;
60 return $this->test_id;
65 return $this->nr_of_passed_marks === 1;
70 return $this->nr_of_zero_percentage_marks === 1;
76 $reached = round($percentage, 2);
77 foreach (array_reverse($this->mark_steps) as $step) {
78 $level = round($step->getMinimumLevel(), 2);
79 if ($reached >= $level) {
88 return $this->nr_of_zero_percentage_marks === 0;
93 return $this->nr_of_passed_marks === 0;
98 $has_to_be_passed =
false;
99 foreach ($this->mark_steps as $step) {
100 if ($has_to_be_passed && !$step->getPassed()) {
103 if ($step->getPassed() ===
true) {
104 $has_to_be_passed =
true;
115 return $this->mark_steps;
123 $clone = clone $this;
124 $clone->mark_steps = $this->
sort($mark_steps);
125 [$clone->nr_of_passed_marks, $clone->nr_of_zero_percentage_marks] = array_reduce(
127 function (array
$c,
Mark $v): array {
141 private function sort(array $mark_steps): array
145 function (
$a,
$b):
int {
146 if (
$a->getMinimumLevel() ===
$b->getMinimumLevel()) {
147 $res = strcmp($a->getShortName(), $b->getShortName());
149 return strcmp($a->getOfficialName(), $b->getOfficialName());
154 return (
$a->getMinimumLevel() <
$b->getMinimumLevel()) ? -1 : 1;
164 foreach ($this->getMarkSteps() as $mark) {
165 $log_array[$mark->getShortName()] = [
166 AdditionalInformationGenerator::KEY_MARK_SHORT_NAME => $mark->getShortName(),
167 AdditionalInformationGenerator::KEY_MARK_OFFICIAL_NAME => $mark->getOfficialName(),
168 AdditionalInformationGenerator::KEY_MARK_MINIMUM_LEVEL => $mark->getMinimumLevel(),
169 AdditionalInformationGenerator::KEY_MARK_IS_PASSING => $additional_info
178 return [
'mark_steps' => array_map(
static fn(
Mark $mark): array => $mark->
toExport(), $this->mark_steps)];
183 return (
new self(
$data[
'test_id'] ?? -1))
184 ->withMarkSteps(array_map(
static fn(array $mark):
Mark => Mark::fromExport($mark),
$data[
'mark_steps']));
A class defining mark schemas for assessment test objects.
__construct(private int $test_id)
int $nr_of_zero_percentage_marks
toLog(AdditionalInformationGenerator $additional_info)
checkForMissingZeroPercentage()
getMatchingMark(float $percentage)
checkForFailedAfterPassed()
withMarkSteps(array $mark_steps)
toExport()
Transform the object into a simple, associative array.
hasSingleZeroPercentageMark()
static fromExport(array $data)
Creates an instance of the object from an array.
A class defining marks for assessment test objects.
toExport()
Transform the object into a simple, associative array.
This interface allows an object to define its own transformation into a language-neutral,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(!file_exists('../ilias.ini.php'))