ILIAS  release_8 Revision v8.24
ASS_MarkSchema Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ASS_MarkSchema:

Public Member Functions

 __construct ()
 
 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. More...
 
 addMarkStep (string $txt_short="", string $txt_official="", $percentage=0, $passed=0)
 Adds a mark step to the mark schema. More...
 
 saveToDb (int $test_id)
 
 loadFromDb (int $test_id)
 
 flush ()
 
 sort ()
 Sorts the mark schema using the minimum level values. More...
 
 deleteMarkStep ($index=0)
 Deletes the mark step with a given index. More...
 
 deleteMarkSteps (array $indexes)
 Deletes multiple mark steps using their index positions. More...
 
 getMatchingMark ($percentage)
 Returns the matching mark for a given percentage. More...
 
 checkMarks ()
 Check the marks for consistency. More...
 
 getMarkSteps ()
 
 setMarkSteps (array $mark_steps)
 

Static Public Member Functions

static _getMatchingMark ($test_id, $percentage)
 Returns the matching mark for a given percentage. More...
 
static _getMatchingMarkFromObjId ($a_obj_id, float $percentage)
 Returns the matching mark for a given percentage. More...
 

Data Fields

array $mark_steps
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning A class defining mark schemas for assessment test objects

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 31 of file class.assMarkSchema.php.

Constructor & Destructor Documentation

◆ __construct()

ASS_MarkSchema::__construct ( )

Definition at line 35 of file class.assMarkSchema.php.

36 {
37 $this->mark_steps = array();
38 }

Member Function Documentation

◆ _getMatchingMark()

static ASS_MarkSchema::_getMatchingMark (   $test_id,
  $percentage 
)
static

Returns the matching mark for a given percentage.

See also
$mark_steps
Parameters
integer$test_idThe database id of the test.
double$percentageA percentage value between 0 and 100.
Returns
false|ASS_Mark The mark object, if a matching mark was found, false otherwise.

@noinspection PhpAssignmentInConditionInspection

Definition at line 312 of file class.assMarkSchema.php.

313 {
314 global $DIC;
315 $ilDB = $DIC['ilDB'];
316 $result = $ilDB->queryF(
317 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
318 array('integer'),
319 array($test_id)
320 );
321
323 while ($row = $ilDB->fetchAssoc($result)) {
324 if ($percentage >= $row["minimum_level"]) {
325 return $row;
326 }
327 }
328 return false;
329 }
global $DIC
Definition: feed.php:28

References $DIC, and $ilDB.

◆ _getMatchingMarkFromObjId()

static ASS_MarkSchema::_getMatchingMarkFromObjId (   $a_obj_id,
float  $percentage 
)
static

Returns the matching mark for a given percentage.

See also
$mark_steps
Parameters
integer$a_obj_idThe database id of the test.
Returns
false|ASS_Mark The mark object, if a matching mark was found, false otherwise.

Definition at line 340 of file class.assMarkSchema.php.

341 {
342 global $DIC;
343 $ilDB = $DIC['ilDB'];
344 $result = $ilDB->queryF(
345 "SELECT tst_mark.* FROM tst_mark, tst_tests WHERE tst_mark.test_fi = tst_tests.test_id AND tst_tests.obj_fi = %s ORDER BY minimum_level DESC",
346 array('integer'),
347 array($a_obj_id)
348 );
349 while ($row = $ilDB->fetchAssoc($result)) {
350 if ($percentage >= $row["minimum_level"]) {
351 return $row;
352 }
353 }
354 return false;
355 }

References $DIC, and $ilDB.

Referenced by ilObjTestAccess\_isPassed(), and ilObjTestAccess\isFailed().

+ Here is the caller graph for this function:

◆ addMarkStep()

ASS_MarkSchema::addMarkStep ( string  $txt_short = "",
string  $txt_official = "",
  $percentage = 0,
  $passed = 0 
)

Adds a mark step to the mark schema.

A new ASS_Mark object will be created and stored in the $mark_steps array.

See also
$mark_steps
Parameters
string$txt_shortThe short text of the mark.
string$txt_officialThe official text of the mark.
float$percentageThe minimum percentage level reaching the mark.
integer$passedThe passed status of the mark (0 = failed, 1 = passed).

Definition at line 81 of file class.assMarkSchema.php.

81 : void
82 {
83 require_once './Modules/Test/classes/class.assMark.php';
84 $mark = new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
85 array_push($this->mark_steps, $mark);
86 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Referenced by createSimpleSchema(), and loadFromDb().

+ Here is the caller graph for this function:

◆ checkMarks()

ASS_MarkSchema::checkMarks ( )

Check the marks for consistency.

See also
$mark_steps
Returns
bool|string true if the check succeeds, als a text string containing a language string for an error message

Definition at line 394 of file class.assMarkSchema.php.

395 {
396 $minimum_percentage = 100;
397 $passed = 0;
398 for ($i = 0; $i < count($this->mark_steps); $i++) {
399 if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage) {
400 $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
401 }
402 if ($this->mark_steps[$i]->getPassed()) {
403 $passed++;
404 }
405 }
406
407 if ($minimum_percentage != 0) {
408 return "min_percentage_ne_0";
409 }
410
411 if ($passed == 0) {
412 return "no_passed_mark";
413 }
414 return true;
415 }
$i
Definition: metadata.php:41

References $i.

◆ createSimpleSchema()

ASS_MarkSchema::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.

See also
$mark_steps
Parameters
string$txt_failed_shortThe short text of the failed mark.
string$txt_failed_officialThe official text of the failed mark.
float | int$percentage_failedThe minimum percentage level reaching the failed mark.
integer$failed_passedIndicates the passed status of the failed mark (0 = failed, 1 = passed).
string$txt_passed_shortThe short text of the passed mark.
string$txt_passed_officialThe official text of the passed mark.
float | int$percentage_passedThe minimum percentage level reaching the passed mark.
integer$passed_passedIndicates the passed status of the passed mark (0 = failed, 1 = passed).

Definition at line 55 of file class.assMarkSchema.php.

64 {
65 $this->flush();
66 $this->addMarkStep($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
67 $this->addMarkStep($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
68 }
addMarkStep(string $txt_short="", string $txt_official="", $percentage=0, $passed=0)
Adds a mark step to the mark schema.

References addMarkStep(), and flush().

+ Here is the call graph for this function:

◆ deleteMarkStep()

ASS_MarkSchema::deleteMarkStep (   $index = 0)

Deletes the mark step with a given index.

See also
$mark_steps
Parameters
integer$indexThe index of the mark step to delete.

Definition at line 251 of file class.assMarkSchema.php.

252 {
253 if ($index < 0) {
254 return;
255 }
256 if (count($this->mark_steps) < 1) {
257 return;
258 }
259 if ($index >= count($this->mark_steps)) {
260 return;
261 }
262 unset($this->mark_steps[$index]);
263 $this->mark_steps = array_values($this->mark_steps);
264 }
$index
Definition: metadata.php:145

References $index.

◆ deleteMarkSteps()

ASS_MarkSchema::deleteMarkSteps ( array  $indexes)

Deletes multiple mark steps using their index positions.

Parameters
array$indexesAn array with all the index positions to delete.

Definition at line 270 of file class.assMarkSchema.php.

270 : void
271 {
272 foreach ($indexes as $key => $index) {
273 if (!(($index < 0) or (count($this->mark_steps) < 1))) {
274 unset($this->mark_steps[$index]);
275 }
276 }
277 $this->mark_steps = array_values($this->mark_steps);
278 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References $index, and ILIAS\LTI\ToolProvider\$key.

◆ flush()

ASS_MarkSchema::flush ( )

Definition at line 217 of file class.assMarkSchema.php.

217 : void
218 {
219 $this->mark_steps = array();
220 }

Referenced by createSimpleSchema().

+ Here is the caller graph for this function:

◆ getMarkSteps()

ASS_MarkSchema::getMarkSteps ( )
Returns
ASS_Mark[]

Definition at line 420 of file class.assMarkSchema.php.

420 : array
421 {
422 return $this->mark_steps;
423 }

References $mark_steps.

◆ getMatchingMark()

ASS_MarkSchema::getMatchingMark (   $percentage)

Returns the matching mark for a given percentage.

See also
$mark_steps
Parameters
double$percentageA percentage value between 0 and 100.
Returns
ASS_Mark|bool The mark object, if a matching mark was found, false otherwise.

Definition at line 289 of file class.assMarkSchema.php.

290 {
291 for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
292 $curMinLevel = $this->mark_steps[$i]->getMinimumLevel();
293 $reached = round($percentage, 2);
294 $level = round($curMinLevel, 2);
295 if ($reached >= $level) {
296 return $this->mark_steps[$i];
297 }
298 }
299 return false;
300 }

References $i.

◆ loadFromDb()

ASS_MarkSchema::loadFromDb ( int  $test_id)

@noinspection PhpAssignmentInConditionInspection

Definition at line 191 of file class.assMarkSchema.php.

191 : void
192 {
193 global $DIC;
194 $ilDB = $DIC['ilDB'];
195
196 if (!$test_id) {
197 return;
198 }
199 $result = $ilDB->queryF(
200 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
201 array('integer'),
202 array($test_id)
203 );
204 if ($result->numRows() > 0) {
206 while ($data = $ilDB->fetchAssoc($result)) {
207 $this->addMarkStep(
208 $data["short_name"] ?? '',
209 $data["official_name"] ?? '',
210 (float) $data["minimum_level"],
211 (int) $data["passed"]
212 );
213 }
214 }
215 }

References $data, $DIC, $ilDB, and addMarkStep().

+ Here is the call graph for this function:

◆ saveToDb()

ASS_MarkSchema::saveToDb ( int  $test_id)

@noinspection PhpAssignmentInConditionInspection

@noinspection PhpAssignmentInConditionInspection

Definition at line 88 of file class.assMarkSchema.php.

88 : void
89 {
90 global $DIC;
91 $lng = $DIC['lng'];
92 $ilDB = $DIC['ilDB'];
93
94 $oldmarks = array();
95 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
97 $result = $ilDB->queryF(
98 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
99 array('integer'),
100 array($test_id)
101 );
102 if ($result->numRows()) {
104 while ($row = $ilDB->fetchAssoc($result)) {
105 $oldmarks[$row["minimum_level"]] = $row;
106 }
107 }
108 }
109
110 if (!$test_id) {
111 return;
112 }
113 // Delete all entries
114 $ilDB->manipulateF(
115 "DELETE FROM tst_mark WHERE test_fi = %s",
116 array('integer'),
117 array($test_id)
118 );
119 if (count($this->mark_steps) == 0) {
120 return;
121 }
122
123 // Write new datasets
124 foreach ($this->mark_steps as $key => $value) {
125 $next_id = $ilDB->nextId('tst_mark');
126 $ilDB->manipulateF(
127 "INSERT INTO tst_mark (mark_id, test_fi, short_name, official_name, minimum_level, passed, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
128 array('integer','integer','text','text','float','text','integer'),
129 array(
130 $next_id,
131 $test_id,
132 substr($value->getShortName(), 0, 15),
133 substr($value->getOfficialName(), 0, 50),
134 $value->getMinimumLevel(),
135 $value->getPassed(),
136 time()
137 )
138 );
139 }
141 $result = $ilDB->queryF(
142 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
143 array('integer'),
144 array($test_id)
145 );
146 $newmarks = array();
147 if ($result->numRows()) {
149 while ($row = $ilDB->fetchAssoc($result)) {
150 $newmarks[$row["minimum_level"]] = $row;
151 }
152 }
153 foreach ($oldmarks as $level => $row) {
154 if (array_key_exists($level, $newmarks)) {
155 $difffields = array();
156 foreach ($row as $key => $value) {
157 if (strcmp($value, $newmarks[$level][$key]) != 0) {
158 switch ($key) {
159 case "mark_id":
160 case "tstamp":
161 break;
162 default:
163 array_push($difffields, "$key: $value => " . $newmarks[$level][$key]);
164 break;
165 }
166 }
167 }
168 if (count($difffields)) {
169 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_changed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . join(", ", $difffields));
170 }
171 } else {
172 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_removed", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
173 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
174 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
175 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
176 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
177 }
178 }
179 foreach ($newmarks as $level => $row) {
180 if (!array_key_exists($level, $oldmarks)) {
181 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_added", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
182 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
183 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
184 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
185 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
186 }
187 }
188 }
189 }
$lng

References $DIC, $ilDB, ILIAS\LTI\ToolProvider\$key, $lng, ilObjAssessmentFolder\_enabledAssessmentLogging(), and ilObjAssessmentFolder\_getLogLanguage().

+ Here is the call graph for this function:

◆ setMarkSteps()

ASS_MarkSchema::setMarkSteps ( array  $mark_steps)
Parameters
ASS_Mark[]$mark_steps

Definition at line 428 of file class.assMarkSchema.php.

428 : void
429 {
430 $this->mark_steps = $mark_steps;
431 }

References $mark_steps.

◆ sort()

ASS_MarkSchema::sort ( )

Sorts the mark schema using the minimum level values.

See also
$mark_steps

Definition at line 227 of file class.assMarkSchema.php.

227 : void
228 {
229 function level_sort($a, $b): int
230 {
231 if ($a->getMinimumLevel() == $b->getMinimumLevel()) {
232 $res = strcmp($a->getShortName(), $b->getShortName());
233 if ($res == 0) {
234 return strcmp($a->getOfficialName(), $b->getOfficialName());
235 } else {
236 return $res;
237 }
238 }
239 return ($a->getMinimumLevel() < $b->getMinimumLevel()) ? -1 : 1;
240 }
241 usort($this->mark_steps, 'level_sort');
242 }
$res
Definition: ltiservices.php:69
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, and $res.

Field Documentation

◆ $mark_steps

array ASS_MarkSchema::$mark_steps

Definition at line 33 of file class.assMarkSchema.php.

Referenced by getMarkSteps(), and setMarkSteps().


The documentation for this class was generated from the following file: