ILIAS  Release_4_2_x_branch Revision 61807
 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 
308  function deleteMarkSteps($indexes)
309  {
310  foreach ($indexes as $key => $index)
311  {
312  if (!(($index < 0) or (count($this->mark_steps) < 1)))
313  {
314  unset($this->mark_steps[$index]);
315  }
316  }
317  $this->mark_steps = array_values($this->mark_steps);
318  }
319 
328  function getMatchingMark($percentage)
329  {
330  for ($i = count($this->mark_steps) - 1; $i >= 0; $i--)
331  {
332  if ($percentage >= $this->mark_steps[$i]->getMinimumLevel())
333  {
334  return $this->mark_steps[$i];
335  }
336  }
337  return false;
338  }
339 
349  function _getMatchingMark($test_id, $percentage)
350  {
351  global $ilDB;
352  $result = $ilDB->queryF("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level DESC",
353  array('integer'),
354  array($test_id)
355  );
356  while ($row = $ilDB->fetchAssoc($result))
357  {
358  if ($percentage >= $row["minimum_level"])
359  {
360  return $row;
361  }
362  }
363  return FALSE;
364  }
365 
375  function _getMatchingMarkFromObjId($a_obj_id, $percentage)
376  {
377  global $ilDB;
378  $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",
379  array('integer'),
380  array($a_obj_id)
381  );
382  while ($row = $ilDB->fetchAssoc($result))
383  {
384  if ($percentage >= $row["minimum_level"])
385  {
386  return $row;
387  }
388  }
389  return FALSE;
390  }
391 
401  function _getMatchingMarkFromActiveId($active_id, $percentage)
402  {
403  global $ilDB;
404  $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",
405  array('integer'),
406  array($active_id)
407  );
408  while ($row = $ilDB->fetchAssoc($result))
409  {
410  if ($percentage >= $row["minimum_level"])
411  {
412  return $row;
413  }
414  }
415  return FALSE;
416  }
417 
425  function checkMarks()
426  {
427  $minimum_percentage = 100;
428  $passed = 0;
429  for ($i = 0; $i < count($this->mark_steps); $i++)
430  {
431  if ($this->mark_steps[$i]->getMinimumLevel() < $minimum_percentage)
432  {
433  $minimum_percentage = $this->mark_steps[$i]->getMinimumLevel();
434  }
435  if ($this->mark_steps[$i]->getPassed())
436  {
437  $passed++;
438  }
439  }
440  if ($minimum_percentage != 0)
441  {
442  return "min_percentage_ne_0";
443  }
444  if ($passed == 0)
445  {
446  return "no_passed_mark";
447  }
448  return true;
449  }
450 
458  function logAction($test_id, $logtext = "")
459  {
460  global $ilUser;
461  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
462  ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromTestID($test_id), $logtext, "", "", TRUE, $_GET["ref_id"]);
463  }
464 }
465 
466 ?>