19 declare(strict_types=1);
21 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
40 protected int $current_user_id
42 $this->mark_steps = [];
61 string $txt_failed_short =
"failed",
62 string $txt_failed_official =
"failed",
63 float $percentage_failed = 0,
64 int $failed_passed = 0,
65 string $txt_passed_short =
"passed",
66 string $txt_passed_official =
"passed",
67 float $percentage_passed = 50,
68 int $passed_passed = 1
71 $this->
addMarkStep($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
72 $this->
addMarkStep($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
86 public function addMarkStep(
string $txt_short =
"",
string $txt_official =
"",
float $percentage = 0,
int $passed = 0): void
88 $mark =
new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
89 array_push($this->mark_steps, $mark);
96 $result = $this->db->queryF(
97 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
101 if ($result->numRows()) {
103 while ($row = $this->db->fetchAssoc($result)) {
104 $oldmarks[$row[
"minimum_level"]] = $row;
113 $this->db->manipulateF(
114 "DELETE FROM tst_mark WHERE test_fi = %s",
118 if (count($this->mark_steps) == 0) {
123 foreach ($this->mark_steps as
$key => $value) {
124 $next_id = $this->db->nextId(
'tst_mark');
125 $this->db->manipulateF(
126 "INSERT INTO tst_mark (mark_id, test_fi, short_name, official_name, minimum_level, passed, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
127 array(
'integer',
'integer',
'text',
'text',
'float',
'text',
'integer'),
131 substr($value->getShortName(), 0, 15),
132 substr($value->getOfficialName(), 0, 50),
133 $value->getMinimumLevel(),
140 $result = $this->db->queryF(
141 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
146 if ($result->numRows()) {
148 while ($row = $this->db->fetchAssoc($result)) {
149 $newmarks[$row[
"minimum_level"]] = $row;
152 foreach ($oldmarks as $level => $row) {
153 if (array_key_exists($level, $newmarks)) {
154 $difffields = array();
155 foreach ($row as
$key => $value) {
156 if ($value !== $newmarks[$level][
$key]) {
162 array_push($difffields,
"$key: $value => " . $newmarks[$level][$key]);
167 if (count($difffields)) {
178 foreach ($newmarks as $level => $row) {
179 if (!array_key_exists($level, $oldmarks)) {
195 $result = $this->db->queryF(
196 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
200 if ($result->numRows() > 0) {
202 while (
$data = $this->db->fetchAssoc($result)) {
204 $data[
"short_name"] ??
'',
205 $data[
"official_name"] ??
'',
206 (
float)
$data[
"minimum_level"],
207 (
int) $data[
"passed"]
215 $this->mark_steps = array();
225 function level_sort(
$a,
$b):
int 227 if (
$a->getMinimumLevel() ==
$b->getMinimumLevel()) {
228 $res = strcmp(
$a->getShortName(),
$b->getShortName());
230 return strcmp(
$a->getOfficialName(),
$b->getOfficialName());
235 return (
$a->getMinimumLevel() <
$b->getMinimumLevel()) ? -1 : 1;
237 usort($this->mark_steps,
'level_sort');
252 if (count($this->mark_steps) < 1) {
255 if ($index >= count($this->mark_steps)) {
258 unset($this->mark_steps[$index]);
259 $this->mark_steps = array_values($this->mark_steps);
268 foreach ($indexes as
$key => $index) {
269 if (!(($index < 0) or (count($this->mark_steps) < 1))) {
270 unset($this->mark_steps[$index]);
273 $this->mark_steps = array_values($this->mark_steps);
287 for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
288 $curMinLevel = $this->mark_steps[$i]->getMinimumLevel();
289 $reached = round($percentage, 2);
290 $level = round($curMinLevel, 2);
291 if ($reached >= $level) {
292 return $this->mark_steps[$i];
307 $minimum_percentage = 100;
309 for ($i = 0; $i < count($this->mark_steps); $i++) {
310 if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage) {
311 $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
313 if ($this->mark_steps[$i]->getPassed()) {
318 if ($minimum_percentage != 0) {
319 return "min_percentage_ne_0";
323 return "no_passed_mark";
347 public function logAction($test_id,
string $logtext =
""): void
createSimpleSchema(string $txt_failed_short="failed", string $txt_failed_official="failed", float $percentage_failed=0, int $failed_passed=0, string $txt_passed_short="passed", string $txt_passed_official="passed", float $percentage_passed=50, int $passed_passed=1)
Creates a simple mark schema for two mark steps: failed and passed.
static _addLog( $user_id, $object_id, $logtext, $question_id=0, $original_id=0, $test_only=false, $test_ref_id=0)
Add an assessment log entry.
static _getObjectIDFromTestID($test_id)
Returns the ILIAS test object id for a given test id.
sort()
Sorts the mark schema using the minimum level values.
A class defining marks for assessment test objects.
logAction($test_id, string $logtext="")
Logs an action into the Test&Assessment log.
static _enabledAssessmentLogging()
__construct(protected ilDBInterface $db, protected ilLanguage $lng, protected int $current_user_id)
deleteMarkSteps(array $indexes)
Deletes multiple mark steps using their index positions.
checkMarks()
Check the marks for consistency.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
A class defining mark schemas for assessment test objects.
addMarkStep(string $txt_short="", string $txt_official="", float $percentage=0, int $passed=0)
Adds a mark step to the mark schema.
deleteMarkStep($index=0)
Deletes the mark step with a given index.
getMatchingMark($percentage)
Returns the matching mark for a given percentage.
setMarkSteps(array $mark_steps)