ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
59 $this->flush();
60 $this->addMarkStep($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
61 $this->addMarkStep($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
62 }
63
75 public function addMarkStep( $txt_short = "", $txt_official = "", $percentage = 0, $passed = 0)
76 {
77 require_once './Modules/Test/classes/class.assMark.php';
78 $mark = new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
79 array_push($this->mark_steps, $mark);
80 }
81
87 public function saveToDb($test_id)
88 {
89 global $lng;
90 global $ilDB;
91
92 $oldmarks = array();
93 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
95 {
96 $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
97 array('integer'),
98 array($test_id)
99 );
100 if ($result->numRows())
101 {
103 while ($row = $ilDB->fetchAssoc($result))
104 {
105 $oldmarks[$row["minimum_level"]] = $row;
106 }
107 }
108 }
109
110 if (!$test_id) return;
111 // Delete all entries
112 $ilDB->manipulateF("DELETE FROM tst_mark WHERE test_fi = %s",
113 array('integer'),
114 array($test_id)
115 );
116 if (count($this->mark_steps) == 0) return;
117
118 // Write new datasets
119 foreach ($this->mark_steps as $key => $value)
120 {
121 $next_id = $ilDB->nextId('tst_mark');
122 $ilDB->manipulateF("INSERT INTO tst_mark (mark_id, test_fi, short_name, official_name, minimum_level, passed, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)",
123 array('integer','integer','text','text','float','text','integer'),
124 array(
125 $next_id,
126 $test_id,
127 $value->getShortName(),
128 $value->getOfficialName(),
129 $value->getMinimumLevel(),
130 $value->getPassed(),
131 time()
132 )
133 );
134 }
136 {
137 $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
138 array('integer'),
139 array($test_id)
140 );
141 $newmarks = array();
142 if ($result->numRows())
143 {
145 while ($row = $ilDB->fetchAssoc($result))
146 {
147 $newmarks[$row["minimum_level"]] = $row;
148 }
149 }
150 foreach ($oldmarks as $level => $row)
151 {
152 if (array_key_exists($level, $newmarks))
153 {
154 $difffields = array();
155 foreach ($row as $key => $value)
156 {
157 if (strcmp($value, $newmarks[$level][$key]) != 0)
158 {
159 switch ($key)
160 {
161 case "mark_id":
162 case "tstamp":
163 break;
164 default:
165 array_push($difffields, "$key: $value => " .$newmarks[$level][$key]);
166 break;
167 }
168 }
169 }
170 if (count($difffields))
171 {
172 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_changed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . join($difffields, ", "));
173 }
174 }
175 else
176 {
177 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_removed", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
178 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
179 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
180 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
181 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
182 }
183 }
184 foreach ($newmarks as $level => $row)
185 {
186 if (!array_key_exists($level, $oldmarks))
187 {
188 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_added", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
189 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
190 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
191 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
192 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
193 }
194 }
195 }
196 }
197
203 public function loadFromDb($test_id)
204 {
205 global $ilDB;
206
207 if (!$test_id) return;
208 $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
209 array('integer'),
210 array($test_id)
211 );
212 if ($result->numRows() > 0)
213 {
215 while ($data = $ilDB->fetchAssoc($result))
216 {
217 $this->addMarkStep($data["short_name"], $data["official_name"], $data["minimum_level"], $data["passed"]);
218 }
219 }
220 }
221
227 public function flush()
228 {
229 $this->mark_steps = array();
230 }
231
237 public function sort()
238 {
239 function level_sort($a, $b)
240 {
241 if ($a->getMinimumLevel() == $b->getMinimumLevel())
242 {
243 $res = strcmp($a->getShortName(), $b->getShortName());
244 if ($res == 0)
245 {
246 return strcmp($a->getOfficialName(), $b->getOfficialName());
247 }
248 else
249 {
250 return $res;
251 }
252 }
253 return ($a->getMinimumLevel() < $b->getMinimumLevel()) ? -1 : 1;
254 }
255 usort($this->mark_steps, 'level_sort');
256 }
257
265 public function deleteMarkStep($index = 0)
266 {
267 if ($index < 0) return;
268 if (count($this->mark_steps) < 1) return;
269 if ($index >= count($this->mark_steps)) return;
270 unset($this->mark_steps[$index]);
271 $this->mark_steps = array_values($this->mark_steps);
272 }
273
281 public function deleteMarkSteps($indexes)
282 {
283 foreach ($indexes as $key => $index)
284 {
285 if (!(($index < 0) or (count($this->mark_steps) < 1)))
286 {
287 unset($this->mark_steps[$index]);
288 }
289 }
290 $this->mark_steps = array_values($this->mark_steps);
291 }
292
302 public function getMatchingMark($percentage)
303 {
304 for ($i = count($this->mark_steps) - 1; $i >= 0; $i--)
305 {
306 $curMinLevel = $this->mark_steps[$i]->getMinimumLevel();
307
308 if( $percentage > $curMinLevel || (string)$percentage == (string)$curMinLevel )
309 { // >= does NOT work since PHP is a fucking female float pig !!!!
310 return $this->mark_steps[$i];
311 }
312 }
313 return false;
314 }
315
326 public function _getMatchingMark($test_id, $percentage)
327 {
328 global $ilDB;
329 $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
330 array('integer'),
331 array($test_id)
332 );
333
335 while ($row = $ilDB->fetchAssoc($result))
336 {
337 if ($percentage >= $row["minimum_level"])
338 {
339 return $row;
340 }
341 }
342 return FALSE;
343 }
344
355 public function _getMatchingMarkFromObjId($a_obj_id, $percentage)
356 {
357 global $ilDB;
358 $result = $ilDB->queryF("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",
359 array('integer'),
360 array($a_obj_id)
361 );
362 while ($row = $ilDB->fetchAssoc($result))
363 {
364 if ($percentage >= $row["minimum_level"])
365 {
366 return $row;
367 }
368 }
369 return FALSE;
370 }
371
382 public function _getMatchingMarkFromActiveId($active_id, $percentage)
383 {
385 global $ilDB;
386 $result = $ilDB->queryF("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",
387 array('integer'),
388 array($active_id)
389 );
390
392 while ($row = $ilDB->fetchAssoc($result))
393 {
394 if ($percentage >= $row["minimum_level"])
395 {
396 return $row;
397 }
398 }
399 return FALSE;
400 }
401
409 public function checkMarks()
410 {
411 $minimum_percentage = 100;
412 $passed = 0;
413 for ($i = 0; $i < count($this->mark_steps); $i++)
414 {
415 if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage)
416 {
417 $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
418 }
419 if ($this->mark_steps[$i]->getPassed())
420 {
421 $passed++;
422 }
423 }
424
425 if ($minimum_percentage != 0)
426 {
427 return "min_percentage_ne_0";
428 }
429
430 if ($passed == 0)
431 {
432 return "no_passed_mark";
433 }
434 return true;
435 }
436
440 public function getMarkSteps()
441 {
442 return $this->mark_steps;
443 }
444
448 public function setMarkSteps($mark_steps)
449 {
450 $this->mark_steps = $mark_steps;
451 }
452
461 public function logAction($test_id, $logtext = "")
462 {
464 global $ilUser;
465 include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
466 ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromTestID($test_id), $logtext, "", "", TRUE, $_GET["ref_id"]);
467 }
468}
$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)
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.
loadFromDb($test_id)
Loads an ASS_MarkSchema object from a database.
addMarkStep( $txt_short="", $txt_official="", $percentage=0, $passed=0)
Adds a mark step to the mark schema.
_getMatchingMark($test_id, $percentage)
Returns the matching mark for a given percentage.
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.
_getMatchingMarkFromObjId($a_obj_id, $percentage)
Returns the matching mark for a given percentage.
A class defining marks for assessment test objects.
_addLog($user_id, $object_id, $logtext, $question_id="", $original_id="", $test_only=FALSE, $test_ref_id=NULL)
Add an assessment log entry.
_getLogLanguage()
retrieve the log language for assessment logging
_enabledAssessmentLogging()
check wether assessment logging is enabled or not
_getObjectIDFromTestID($test_id)
Returns the ILIAS test object id for a given test id.
$data
global $lng
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15