ILIAS  release_7 Revision v7.30-3-g800a261c036
ASS_MarkSchema Class Reference

A class defining mark schemas for assessment test objects. More...

+ Collaboration diagram for ASS_MarkSchema:

Public Member Functions

 __construct ()
 ASS_MarkSchema constructor. More...
 
 createSimpleSchema ( $txt_failed_short="failed", $txt_failed_official="failed", $percentage_failed=0, $failed_passed=0, $txt_passed_short="passed", $txt_passed_official="passed", $percentage_passed=50, $passed_passed=1)
 Creates a simple mark schema for two mark steps: failed and passed. More...
 
 addMarkStep ($txt_short="", $txt_official="", $percentage=0, $passed=0)
 Adds a mark step to the mark schema. More...
 
 saveToDb ($test_id)
 Saves an ASS_MarkSchema object to a database. More...
 
 loadFromDb ($test_id)
 Loads an ASS_MarkSchema object from a database. More...
 
 flush ()
 Empties the mark schema and removes all mark steps. More...
 
 sort ()
 Sorts the mark schema using the minimum level values. More...
 
 deleteMarkStep ($index=0)
 Deletes the mark step with a given index. More...
 
 deleteMarkSteps ($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 ($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, $percentage)
 Returns the matching mark for a given percentage. More...
 

Data Fields

 $mark_steps
 

Detailed Description

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 16 of file class.assMarkSchema.php.

Constructor & Destructor Documentation

◆ __construct()

ASS_MarkSchema::__construct ( )

ASS_MarkSchema constructor.

The constructor takes possible arguments an creates an instance of the ASS_MarkSchema object.

Returns
ASS_MarkSchema

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

29 {
30 $this->mark_steps = array();
31 }

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
mixed The mark object, if a matching mark was found, false otherwise.

@noinspection PhpAssignmentInConditionInspection

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

319 {
320 global $DIC;
321 $ilDB = $DIC['ilDB'];
322 $result = $ilDB->queryF(
323 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
324 array('integer'),
325 array($test_id)
326 );
327
329 while ($row = $ilDB->fetchAssoc($result)) {
330 if ($percentage >= $row["minimum_level"]) {
331 return $row;
332 }
333 }
334 return false;
335 }
$result
global $DIC
Definition: goto.php:24
global $ilDB

References $DIC, $ilDB, and $result.

◆ _getMatchingMarkFromObjId()

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

Returns the matching mark for a given percentage.

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

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

348 {
349 global $DIC;
350 $ilDB = $DIC['ilDB'];
351 $result = $ilDB->queryF(
352 "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",
353 array('integer'),
354 array($a_obj_id)
355 );
356 while ($row = $ilDB->fetchAssoc($result)) {
357 if ($percentage >= $row["minimum_level"]) {
358 return $row;
359 }
360 }
361 return false;
362 }

References $DIC, $ilDB, and $result.

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

+ Here is the caller graph for this function:

◆ addMarkStep()

ASS_MarkSchema::addMarkStep (   $txt_short = "",
  $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 | integer$percentageThe minimum percentage level reaching the mark.
integer$passedThe passed status of the mark (0 = failed, 1 = passed).

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

75 {
76 require_once './Modules/Test/classes/class.assMark.php';
77 $mark = new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
78 array_push($this->mark_steps, $mark);
79 }
A class defining marks for assessment test objects.

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 401 of file class.assMarkSchema.php.

402 {
403 $minimum_percentage = 100;
404 $passed = 0;
405 for ($i = 0; $i < count($this->mark_steps); $i++) {
406 if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage) {
407 $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
408 }
409 if ($this->mark_steps[$i]->getPassed()) {
410 $passed++;
411 }
412 }
413
414 if ($minimum_percentage != 0) {
415 return "min_percentage_ne_0";
416 }
417
418 if ($passed == 0) {
419 return "no_passed_mark";
420 }
421 return true;
422 }
$i
Definition: metadata.php:24

References $i.

◆ createSimpleSchema()

ASS_MarkSchema::createSimpleSchema (   $txt_failed_short = "failed",
  $txt_failed_official = "failed",
  $percentage_failed = 0,
  $failed_passed = 0,
  $txt_passed_short = "passed",
  $txt_passed_official = "passed",
  $percentage_passed = 50,
  $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 48 of file class.assMarkSchema.php.

57 {
58 $this->flush();
59 $this->addMarkStep($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
60 $this->addMarkStep($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
61 }
addMarkStep($txt_short="", $txt_official="", $percentage=0, $passed=0)
Adds a mark step to the mark schema.
flush()
Empties the mark schema and removes all mark steps.

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 254 of file class.assMarkSchema.php.

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

References $index.

◆ deleteMarkSteps()

ASS_MarkSchema::deleteMarkSteps (   $indexes)

Deletes multiple mark steps using their index positions.

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

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

277 {
278 foreach ($indexes as $key => $index) {
279 if (!(($index < 0) or (count($this->mark_steps) < 1))) {
280 unset($this->mark_steps[$index]);
281 }
282 }
283 $this->mark_steps = array_values($this->mark_steps);
284 }

References $index.

◆ flush()

ASS_MarkSchema::flush ( )

Empties the mark schema and removes all mark steps.

See also
$mark_steps

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

221 {
222 $this->mark_steps = array();
223 }

Referenced by createSimpleSchema().

+ Here is the caller graph for this function:

◆ getMarkSteps()

ASS_MarkSchema::getMarkSteps ( )
Returns
ASS_Mark[]

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

428 {
429 return $this->mark_steps;
430 }

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 295 of file class.assMarkSchema.php.

296 {
297 for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
298 $curMinLevel = $this->mark_steps[$i]->getMinimumLevel();
299 $reached = round($percentage, 2);
300 $level = round($curMinLevel, 2);
301 if ($reached >= $level) {
302 return $this->mark_steps[$i];
303 }
304 }
305 return false;
306 }

References $i.

◆ loadFromDb()

ASS_MarkSchema::loadFromDb (   $test_id)

Loads an ASS_MarkSchema object from a database.

Parameters
integer$test_idA unique key which defines the test in the database.

@noinspection PhpAssignmentInConditionInspection

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

195 {
196 global $DIC;
197 $ilDB = $DIC['ilDB'];
198
199 if (!$test_id) {
200 return;
201 }
202 $result = $ilDB->queryF(
203 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
204 array('integer'),
205 array($test_id)
206 );
207 if ($result->numRows() > 0) {
209 while ($data = $ilDB->fetchAssoc($result)) {
210 $this->addMarkStep($data["short_name"], $data["official_name"], $data["minimum_level"], $data["passed"]);
211 }
212 }
213 }
$data
Definition: storeScorm.php:23

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

+ Here is the call graph for this function:

◆ saveToDb()

ASS_MarkSchema::saveToDb (   $test_id)

Saves an ASS_MarkSchema object to a database.

Parameters
integer$test_idThe database id of the related test.

@noinspection PhpAssignmentInConditionInspection

@noinspection PhpAssignmentInConditionInspection

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

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

References $DIC, $ilDB, $lng, $result, ilObjAssessmentFolder\_enabledAssessmentLogging(), and ilObjAssessmentFolder\_getLogLanguage().

+ Here is the call graph for this function:

◆ setMarkSteps()

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

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

436 {
437 $this->mark_steps = $mark_steps;
438 }

References $mark_steps.

◆ sort()

ASS_MarkSchema::sort ( )

Sorts the mark schema using the minimum level values.

See also
$mark_steps

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

231 {
232 function level_sort($a, $b)
233 {
234 if ($a->getMinimumLevel() == $b->getMinimumLevel()) {
235 $res = strcmp($a->getShortName(), $b->getShortName());
236 if ($res == 0) {
237 return strcmp($a->getOfficialName(), $b->getOfficialName());
238 } else {
239 return $res;
240 }
241 }
242 return ($a->getMinimumLevel() < $b->getMinimumLevel()) ? -1 : 1;
243 }
244 usort($this->mark_steps, 'level_sort');
245 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
foreach($_POST as $key=> $value) $res

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

Field Documentation

◆ $mark_steps

ASS_MarkSchema::$mark_steps

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

Referenced by getMarkSteps(), and setMarkSteps().


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