ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMarkSchema.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 
34 {
41 
49  function ASS_MarkSchema()
50  {
51  $this->mark_steps = array();
52  }
53 
70  $txt_failed_short = "failed",
71  $txt_failed_official = "failed",
72  $percentage_failed = 0,
73  $failed_passed = 0,
74  $txt_passed_short = "passed",
75  $txt_passed_official = "passed",
76  $percentage_passed = 50,
77  $passed_passed = 1
78  )
79  {
80  $this->flush();
81  $this->addMarkStep($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
82  $this->addMarkStep($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
83  }
84 
96  function addMarkStep(
97  $txt_short = "",
98  $txt_official = "",
99  $percentage = 0,
100  $passed = 0
101  )
102  {
103  include_once "./Modules/Test/classes/class.assMark.php";
104  $mark = new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
105  array_push($this->mark_steps, $mark);
106  }
107 
114  function saveToDb($test_id)
115  {
116  global $lng;
117  global $ilDB;
118 
119  $oldmarks = array();
120  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
122  {
123  $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
124  array('integer'),
125  array($test_id)
126  );
127  if ($result->numRows())
128  {
129  while ($row = $ilDB->fetchAssoc($result))
130  {
131  $oldmarks[$row["minimum_level"]] = $row;
132  }
133  }
134  }
135 
136  if (!$test_id) return;
137  // Delete all entries
138  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_mark WHERE test_fi = %s",
139  array('integer'),
140  array($test_id)
141  );
142  if (count($this->mark_steps) == 0) return;
143 
144  // Write new datasets
145  foreach ($this->mark_steps as $key => $value)
146  {
147  $next_id = $ilDB->nextId('tst_mark');
148  $affectedRows = $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)",
149  array('integer','integer','text','text','float','text','integer'),
150  array(
151  $next_id,
152  $test_id,
153  $value->getShortName(),
154  $value->getOfficialName(),
155  $value->getMinimumLevel(),
156  $value->getPassed(),
157  time()
158  )
159  );
160  }
162  {
163  $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
164  array('integer'),
165  array($test_id)
166  );
167  $newmarks = array();
168  if ($result->numRows())
169  {
170  while ($row = $ilDB->fetchAssoc($result))
171  {
172  $newmarks[$row["minimum_level"]] = $row;
173  }
174  }
175  foreach ($oldmarks as $level => $row)
176  {
177  if (array_key_exists($level, $newmarks))
178  {
179  $difffields = array();
180  foreach ($row as $key => $value)
181  {
182  if (strcmp($value, $newmarks[$level][$key]) != 0)
183  {
184  switch ($key)
185  {
186  case "mark_id":
187  case "tstamp":
188  break;
189  default:
190  array_push($difffields, "$key: $value => " .$newmarks[$level][$key]);
191  break;
192  }
193  }
194  }
195  if (count($difffields))
196  {
197  $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_changed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . join($difffields, ", "));
198  }
199  }
200  else
201  {
202  $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_removed", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
203  $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
204  $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
205  $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
206  $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
207  }
208  }
209  foreach ($newmarks as $level => $row)
210  {
211  if (!array_key_exists($level, $oldmarks))
212  {
213  $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_added", ilObjAssessmentFolder::_getLogLanguage()) . ": " .
214  $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
215  $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
216  $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
217  $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
218  }
219  }
220  }
221  }
222 
229  function loadFromDb($test_id)
230  {
231  global $ilDB;
232 
233  if (!$test_id) return;
234  $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
235  array('integer'),
236  array($test_id)
237  );
238  if ($result->numRows() > 0)
239  {
240  while ($data = $ilDB->fetchAssoc($result))
241  {
242  $this->addMarkStep($data["short_name"], $data["official_name"], $data["minimum_level"], $data["passed"]);
243  }
244  }
245  }
246 
253  function flush()
254  {
255  $this->mark_steps = array();
256  }
257 
264  function sort()
265  {
266  function level_sort($a, $b)
267  {
268  if ($a->getMinimumLevel() == $b->getMinimumLevel())
269  {
270  $res = strcmp($a->getShortName(), $b->getShortName());
271  if ($res == 0)
272  {
273  return strcmp($a->getOfficialName(), $b->getOfficialName());
274  }
275  else
276  {
277  return $res;
278  }
279  }
280  return ($a->getMinimumLevel() < $b->getMinimumLevel()) ? -1 : 1;
281  }
282  usort($this->mark_steps, 'level_sort');
283  }
284 
292  function deleteMarkStep($index = 0)
293  {
294  if ($index < 0) return;
295  if (count($this->mark_steps) < 1) return;
296  if ($index >= count($this->mark_steps)) return;
297  unset($this->mark_steps[$index]);
298  $this->mark_steps = array_values($this->mark_steps);
299  }
300 
301  public function getMarkSteps()
302  {
303  return $this->mark_steps;
304  }
305 
313  function deleteMarkSteps($indexes)
314  {
315  foreach ($indexes as $key => $index)
316  {
317  if (!(($index < 0) or (count($this->mark_steps) < 1)))
318  {
319  unset($this->mark_steps[$index]);
320  }
321  }
322  $this->mark_steps = array_values($this->mark_steps);
323  }
324 
333  function getMatchingMark($percentage)
334  {
335  for ($i = count($this->mark_steps) - 1; $i >= 0; $i--)
336  {
337  if ($percentage >= $this->mark_steps[$i]->getMinimumLevel())
338  {
339  return $this->mark_steps[$i];
340  }
341  }
342  return false;
343  }
344 
354  function _getMatchingMark($test_id, $percentage)
355  {
356  global $ilDB;
357  $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
358  array('integer'),
359  array($test_id)
360  );
361  while ($row = $ilDB->fetchAssoc($result))
362  {
363  if ($percentage >= $row["minimum_level"])
364  {
365  return $row;
366  }
367  }
368  return FALSE;
369  }
370 
380  function _getMatchingMarkFromObjId($a_obj_id, $percentage)
381  {
382  global $ilDB;
383  $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",
384  array('integer'),
385  array($a_obj_id)
386  );
387  while ($row = $ilDB->fetchAssoc($result))
388  {
389  if ($percentage >= $row["minimum_level"])
390  {
391  return $row;
392  }
393  }
394  return FALSE;
395  }
396 
406  function _getMatchingMarkFromActiveId($active_id, $percentage)
407  {
408  global $ilDB;
409  $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",
410  array('integer'),
411  array($active_id)
412  );
413  while ($row = $ilDB->fetchAssoc($result))
414  {
415  if ($percentage >= $row["minimum_level"])
416  {
417  return $row;
418  }
419  }
420  return FALSE;
421  }
422 
430  function checkMarks()
431  {
432  $minimum_percentage = 100;
433  $passed = 0;
434  for ($i = 0; $i < count($this->mark_steps); $i++)
435  {
436  if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage)
437  {
438  $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
439  }
440  if ($this->mark_steps[$i]->getPassed())
441  {
442  $passed++;
443  }
444  }
445  if ($minimum_percentage != 0)
446  {
447  return "min_percentage_ne_0";
448  }
449  if ($passed == 0)
450  {
451  return "no_passed_mark";
452  }
453  return true;
454  }
455 
463  function logAction($test_id, $logtext = "")
464  {
465  global $ilUser;
466  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
467  ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromTestID($test_id), $logtext, "", "", TRUE, $_GET["ref_id"]);
468  }
469 }
470 
471 ?>