• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

assessment/classes/class.assMarkSchema.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once "./assessment/classes/class.assMark.php";
00025 require_once "./assessment/classes/class.ilObjTest.php";
00026 
00037 class ASS_MarkSchema {
00045   var $mark_steps;
00046 
00054   function ASS_MarkSchema() 
00055   {
00056     $this->mark_steps = array();
00057   }
00058 
00076   function create_simple_schema(
00077     $txt_failed_short = "failed", 
00078     $txt_failed_official = "failed", 
00079     $percentage_failed = 0,
00080                 $failed_passed = 0,
00081     $txt_passed_short = "passed",
00082     $txt_passed_official = "passed",
00083     $percentage_passed = 50,
00084                 $passed_passed = 1
00085   )
00086   {
00087     $this->flush();
00088     $this->add_mark_step($txt_failed_short, $txt_failed_official, $percentage_failed, $failed_passed);
00089     $this->add_mark_step($txt_passed_short, $txt_passed_official, $percentage_passed, $passed_passed);
00090   }
00091 
00105   function add_mark_step(
00106     $txt_short = "", 
00107     $txt_official = "", 
00108     $percentage = 0,
00109                 $passed = 0
00110   )
00111   {
00112     $mark = new ASS_Mark($txt_short, $txt_official, $percentage, $passed);
00113     array_push($this->mark_steps, $mark);
00114   }
00115 
00124   function saveToDb($test_id)
00125   {
00126                 global $ilias, $lng;
00127                 $db =& $ilias->db->db;
00128 
00129                 $oldmarks = array();
00130                 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00131                 {
00132                         $query = sprintf("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
00133                                 $db->quote($test_id)
00134                         );
00135                         $result = $db->query($query);
00136                         if ($result->numRows())
00137                         {
00138                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00139                                 {
00140                                         $oldmarks[$row["minimum_level"]] = $row;
00141                                 }
00142                         }
00143                 }
00144                 
00145     if (!$test_id) return;
00146     // Delete all entries
00147     $query = sprintf("DELETE FROM tst_mark WHERE test_fi = %s",
00148       $db->quote($test_id)
00149     );
00150     $result = $db->query($query);
00151     if (count($this->mark_steps) == 0) return;
00152     
00153     // Write new datasets
00154     foreach ($this->mark_steps as $key => $value) 
00155                 {
00156       $query = sprintf("INSERT INTO tst_mark (mark_id, test_fi, short_name, official_name, minimum_level, passed, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00157         $db->quote($test_id),
00158         $db->quote($value->get_short_name()), 
00159         $db->quote($value->get_official_name()), 
00160         $db->quote($value->get_minimum_level()),
00161         $db->quote(sprintf("%d", $value->get_passed()))
00162       );
00163       $result = $db->query($query);
00164       if ($result == DB_OK) {
00165       }
00166     }
00167                 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00168                 {
00169                         $query = sprintf("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
00170                                 $db->quote($test_id)
00171                         );
00172                         $result = $db->query($query);
00173                         $newmarks = array();
00174                         if ($result->numRows())
00175                         {
00176                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00177                                 {
00178                                         $newmarks[$row["minimum_level"]] = $row;
00179                                 }
00180                         }
00181                         foreach ($oldmarks as $level => $row)
00182                         {
00183                                 if (array_key_exists($level, $newmarks))
00184                                 {
00185                                         $difffields = array();
00186                                         foreach ($row as $key => $value)
00187                                         {
00188                                                 if (strcmp($value, $newmarks[$level][$key]) != 0)
00189                                                 {
00190                                                         switch ($key)
00191                                                         {
00192                                                                 case "mark_id":
00193                                                                 case "TIMESTAMP":
00194                                                                         break;
00195                                                                 default:
00196                                                                         array_push($difffields, "$key: $value => " .$newmarks[$level][$key]); 
00197                                                                         break;
00198                                                         }
00199                                                 }
00200                                         }
00201                                         if (count($difffields))
00202                                         {
00203                                                 $this->logAction($test_id, $lng->txt("log_mark_changed") . ": " . join($difffields, ", "));
00204                                         }
00205                                 }
00206                                 else
00207                                 {
00208                                         $this->logAction($test_id, $lng->txt("log_mark_removed") . ": " . 
00209                                                 $lng->txt("tst_mark_minimum_level") . " = " . $row["minimum_level"] . ", " .
00210                                                 $lng->txt("tst_mark_short_form") . " = " . $row["short_name"] . ", " .
00211                                                 $lng->txt("tst_mark_official_form") . " = " . $row["official_name"] . ", " .
00212                                                 $lng->txt("tst_mark_passed") . " = " . $row["passed"]);
00213                                 }
00214                         }
00215                         foreach ($newmarks as $level => $row)
00216                         {
00217                                 if (!array_key_exists($level, $oldmarks))
00218                                 {
00219                                         $this->logAction($test_id, $lng->txt("log_mark_added") . ": " . 
00220                                                 $lng->txt("tst_mark_minimum_level") . " = " . $row["minimum_level"] . ", " .
00221                                                 $lng->txt("tst_mark_short_form") . " = " . $row["short_name"] . ", " .
00222                                                 $lng->txt("tst_mark_official_form") . " = " . $row["official_name"] . ", " .
00223                                                 $lng->txt("tst_mark_passed") . " = " . $row["passed"]);
00224                                 }
00225                         }
00226                 }
00227   }
00228 
00237   function loadFromDb($test_id)
00238   {
00239                 global $ilias;
00240                 $db =& $ilias->db->db;
00241                 
00242     if (!$test_id) return;
00243     $query = sprintf("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
00244       $db->quote($test_id)
00245     );
00246 
00247     $result = $db->query($query);
00248     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00249       while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
00250         $this->add_mark_step($data->short_name, $data->official_name, $data->minimum_level, $data->passed);
00251       }
00252     }
00253   }
00254   
00263   function flush() {
00264     $this->mark_steps = array();
00265   }
00266   
00275   function sort() {
00276     function level_sort($a, $b) {
00277       if ($a->get_minimum_level() == $b->get_minimum_level()) {
00278         $res = strcmp($a->get_short_name(), $b->get_short_name());
00279         if ($res == 0) {
00280           return strcmp($a->get_official_name(), $b->get_official_name());
00281         } else {
00282           return $res;
00283         }
00284       }
00285       return ($a->get_minimum_level() < $b->get_minimum_level()) ? -1 : 1;
00286     }
00287     
00288     usort($this->mark_steps, 'level_sort');
00289   }
00290   
00300   function delete_mark_step($index = 0) {
00301     if ($index < 0) return;
00302     if (count($this->mark_steps) < 1) return;
00303     if ($index >= count($this->mark_steps)) return;
00304     unset($this->mark_steps[$index]);
00305     $this->mark_steps = array_values($this->mark_steps);
00306   }
00307 
00317   function delete_mark_steps($indexes) {
00318     foreach ($indexes as $key => $index) {
00319       if (!(($index < 0) or (count($this->mark_steps) < 1))) {
00320         unset($this->mark_steps[$index]);
00321       }
00322     }
00323     $this->mark_steps = array_values($this->mark_steps);
00324   }
00325 
00336   function get_matching_mark($percentage) {
00337     for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
00338       if ($percentage >= $this->mark_steps[$i]->get_minimum_level()) {
00339         return $this->mark_steps[$i];
00340       }
00341     }
00342                 return false;
00343   }
00344   
00354         function checkMarks()
00355         {
00356                 $minimum_percentage = 100;
00357                 $passed = 0;
00358     for ($i = 0; $i < count($this->mark_steps); $i++) {
00359                         if ($this->mark_steps[$i]->get_minimum_level() < $minimum_percentage)
00360                         {
00361                                 $minimum_percentage = $this->mark_steps[$i]->get_minimum_level();
00362                         }
00363                         if ($this->mark_steps[$i]->get_passed())
00364                         {
00365                                 $passed++;
00366                         }
00367     }
00368                 if ($minimum_percentage != 0)
00369                 {
00370                         return "min_percentage_ne_0";
00371                 }
00372                 if ($passed == 0)
00373                 {
00374                         return "no_passed_mark";
00375                 }
00376                 return true;
00377         }
00378 
00388         function logAction($test_id, $logtext = "")
00389         {
00390                 global $ilUser, $ilDB;
00391 
00392                 $query = sprintf("INSERT INTO ass_log (ass_log_id, user_fi, obj_fi, logtext, question_fi, original_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL, NULL)",
00393                         $ilDB->quote($ilUser->id . ""),
00394                         $ilDB->quote(ilObjTest::_getObjectIDFromTestID($test_id) . ""),
00395                         $ilDB->quote($logtext . "")
00396                 );
00397                 $result = $ilDB->query($query);
00398         }
00399 }
00400 
00401 ?>

Generated on Fri Dec 13 2013 09:06:32 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1