ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.assMarkSchema.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/Test/classes/inc.AssessmentConstants.php';
5
17{
20
28 public function __construct()
29 {
30 $this->mark_steps = array();
31 }
32
48 public function createSimpleSchema(
49 $txt_failed_short = "failed",
50 $txt_failed_official = "failed",
51 $percentage_failed = 0,
52 $failed_passed = 0,
53 $txt_passed_short = "passed",
54 $txt_passed_official = "passed",
55 $percentage_passed = 50,
56 $passed_passed = 1
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 }
62
74 public function addMarkStep($txt_short = "", $txt_official = "", $percentage = 0, $passed = 0)
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 }
80
86 public function saveToDb($test_id)
87 {
88 global $lng;
89 global $ilDB;
90
91 $oldmarks = array();
92 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
94 $result = $ilDB->queryF(
95 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
96 array('integer'),
97 array($test_id)
98 );
99 if ($result->numRows()) {
101 while ($row = $ilDB->fetchAssoc($result)) {
102 $oldmarks[$row["minimum_level"]] = $row;
103 }
104 }
105 }
106
107 if (!$test_id) {
108 return;
109 }
110 // Delete all entries
111 $ilDB->manipulateF(
112 "DELETE FROM tst_mark WHERE test_fi = %s",
113 array('integer'),
114 array($test_id)
115 );
116 if (count($this->mark_steps) == 0) {
117 return;
118 }
119
120 // Write new datasets
121 foreach ($this->mark_steps as $key => $value) {
122 $next_id = $ilDB->nextId('tst_mark');
123 $ilDB->manipulateF(
124 "INSERT INTO tst_mark (mark_id, test_fi, short_name, official_name, minimum_level, passed, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
125 array('integer','integer','text','text','float','text','integer'),
126 array(
127 $next_id,
128 $test_id,
129 $value->getShortName(),
130 $value->getOfficialName(),
131 $value->getMinimumLevel(),
132 $value->getPassed(),
133 time()
134 )
135 );
136 }
138 $result = $ilDB->queryF(
139 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
140 array('integer'),
141 array($test_id)
142 );
143 $newmarks = array();
144 if ($result->numRows()) {
146 while ($row = $ilDB->fetchAssoc($result)) {
147 $newmarks[$row["minimum_level"]] = $row;
148 }
149 }
150 foreach ($oldmarks as $level => $row) {
151 if (array_key_exists($level, $newmarks)) {
152 $difffields = array();
153 foreach ($row as $key => $value) {
154 if (strcmp($value, $newmarks[$level][$key]) != 0) {
155 switch ($key) {
156 case "mark_id":
157 case "tstamp":
158 break;
159 default:
160 array_push($difffields, "$key: $value => " . $newmarks[$level][$key]);
161 break;
162 }
163 }
164 }
165 if (count($difffields)) {
166 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_changed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . join($difffields, ", "));
167 }
168 } else {
169 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_removed", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
170 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
171 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
172 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
173 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
174 }
175 }
176 foreach ($newmarks as $level => $row) {
177 if (!array_key_exists($level, $oldmarks)) {
178 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_added", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
179 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
180 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
181 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
182 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
183 }
184 }
185 }
186 }
187
193 public function loadFromDb($test_id)
194 {
195 global $ilDB;
196
197 if (!$test_id) {
198 return;
199 }
200 $result = $ilDB->queryF(
201 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
202 array('integer'),
203 array($test_id)
204 );
205 if ($result->numRows() > 0) {
207 while ($data = $ilDB->fetchAssoc($result)) {
208 $this->addMarkStep($data["short_name"], $data["official_name"], $data["minimum_level"], $data["passed"]);
209 }
210 }
211 }
212
218 public function flush()
219 {
220 $this->mark_steps = array();
221 }
222
228 public function sort()
229 {
230 function level_sort($a, $b)
231 {
232 if ($a->getMinimumLevel() == $b->getMinimumLevel()) {
233 $res = strcmp($a->getShortName(), $b->getShortName());
234 if ($res == 0) {
235 return strcmp($a->getOfficialName(), $b->getOfficialName());
236 } else {
237 return $res;
238 }
239 }
240 return ($a->getMinimumLevel() < $b->getMinimumLevel()) ? -1 : 1;
241 }
242 usort($this->mark_steps, 'level_sort');
243 }
244
252 public function deleteMarkStep($index = 0)
253 {
254 if ($index < 0) {
255 return;
256 }
257 if (count($this->mark_steps) < 1) {
258 return;
259 }
260 if ($index >= count($this->mark_steps)) {
261 return;
262 }
263 unset($this->mark_steps[$index]);
264 $this->mark_steps = array_values($this->mark_steps);
265 }
266
274 public function deleteMarkSteps($indexes)
275 {
276 foreach ($indexes as $key => $index) {
277 if (!(($index < 0) or (count($this->mark_steps) < 1))) {
278 unset($this->mark_steps[$index]);
279 }
280 }
281 $this->mark_steps = array_values($this->mark_steps);
282 }
283
293 public function getMatchingMark($percentage)
294 {
295 for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
296 $curMinLevel = $this->mark_steps[$i]->getMinimumLevel();
297
298 if ($percentage > $curMinLevel || (string) $percentage == (string) $curMinLevel) { // >= does NOT work since PHP is a fucking female float pig !!!!
299 return $this->mark_steps[$i];
300 }
301 }
302 return false;
303 }
304
315 public static function _getMatchingMark($test_id, $percentage)
316 {
317 global $ilDB;
318 $result = $ilDB->queryF(
319 "SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
320 array('integer'),
321 array($test_id)
322 );
323
325 while ($row = $ilDB->fetchAssoc($result)) {
326 if ($percentage >= $row["minimum_level"]) {
327 return $row;
328 }
329 }
330 return false;
331 }
332
343 public static function _getMatchingMarkFromObjId($a_obj_id, $percentage)
344 {
345 global $ilDB;
346 $result = $ilDB->queryF(
347 "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",
348 array('integer'),
349 array($a_obj_id)
350 );
351 while ($row = $ilDB->fetchAssoc($result)) {
352 if ($percentage >= $row["minimum_level"]) {
353 return $row;
354 }
355 }
356 return false;
357 }
358
369 public static function _getMatchingMarkFromActiveId($active_id, $percentage)
370 {
372 global $ilDB;
373 $result = $ilDB->queryF(
374 "SELECT tst_mark.* FROM tst_active, tst_mark, tst_tests WHERE tst_mark.test_fi = tst_tests.test_id AND tst_tests.test_id = tst_active.test_fi AND tst_active.active_id = %s ORDER BY minimum_level DESC",
375 array('integer'),
376 array($active_id)
377 );
378
380 while ($row = $ilDB->fetchAssoc($result)) {
381 if ($percentage >= $row["minimum_level"]) {
382 return $row;
383 }
384 }
385 return false;
386 }
387
395 public function checkMarks()
396 {
397 $minimum_percentage = 100;
398 $passed = 0;
399 for ($i = 0; $i < count($this->mark_steps); $i++) {
400 if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage) {
401 $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
402 }
403 if ($this->mark_steps[$i]->getPassed()) {
404 $passed++;
405 }
406 }
407
408 if ($minimum_percentage != 0) {
409 return "min_percentage_ne_0";
410 }
411
412 if ($passed == 0) {
413 return "no_passed_mark";
414 }
415 return true;
416 }
417
421 public function getMarkSteps()
422 {
423 return $this->mark_steps;
424 }
425
429 public function setMarkSteps($mark_steps)
430 {
431 $this->mark_steps = $mark_steps;
432 }
433
442 public function logAction($test_id, $logtext = "")
443 {
445 global $ilUser;
446 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
447 ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromTestID($test_id), $logtext, "", "", true, $_GET["ref_id"]);
448 }
449}
$result
$_GET["client_id"]
A class defining mark schemas for assessment test objects.
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.
setMarkSteps($mark_steps)
addMarkStep($txt_short="", $txt_official="", $percentage=0, $passed=0)
Adds a mark step to the mark schema.
deleteMarkSteps($indexes)
Deletes multiple mark steps using their index positions.
flush()
Empties the mark schema and removes all mark steps.
sort()
Sorts the mark schema using the minimum level values.
deleteMarkStep($index=0)
Deletes the mark step with a given index.
static _getMatchingMarkFromObjId($a_obj_id, $percentage)
Returns the matching mark for a given percentage.
static _getMatchingMark($test_id, $percentage)
Returns the matching mark for a given percentage.
loadFromDb($test_id)
Loads an ASS_MarkSchema object from a database.
checkMarks()
Check the marks for consistency.
getMatchingMark($percentage)
Returns the matching mark for a given percentage.
saveToDb($test_id)
Saves an ASS_MarkSchema object to a database.
__construct()
ASS_MarkSchema constructor.
A class defining marks for assessment test objects.
An exception for terminatinating execution or to throw for unit testing.
static _addLog($user_id, $object_id, $logtext, $question_id="", $original_id="", $test_only=false, $test_ref_id=null)
Add an assessment log entry.
static _getLogLanguage()
retrieve the log language for assessment logging
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
static _getObjectIDFromTestID($test_id)
Returns the ILIAS test object id for a given test id.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
$index
Definition: metadata.php:60
global $lng
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18