• 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                 include_once ("./classes/class.ilObjAssessmentFolder.php");
00168                 if (ilObjAssessmentFolder::_enabledAssessmentLogging())
00169                 {
00170                         $query = sprintf("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
00171                                 $db->quote($test_id)
00172                         );
00173                         $result = $db->query($query);
00174                         $newmarks = array();
00175                         if ($result->numRows())
00176                         {
00177                                 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00178                                 {
00179                                         $newmarks[$row["minimum_level"]] = $row;
00180                                 }
00181                         }
00182                         foreach ($oldmarks as $level => $row)
00183                         {
00184                                 if (array_key_exists($level, $newmarks))
00185                                 {
00186                                         $difffields = array();
00187                                         foreach ($row as $key => $value)
00188                                         {
00189                                                 if (strcmp($value, $newmarks[$level][$key]) != 0)
00190                                                 {
00191                                                         switch ($key)
00192                                                         {
00193                                                                 case "mark_id":
00194                                                                 case "TIMESTAMP":
00195                                                                         break;
00196                                                                 default:
00197                                                                         array_push($difffields, "$key: $value => " .$newmarks[$level][$key]); 
00198                                                                         break;
00199                                                         }
00200                                                 }
00201                                         }
00202                                         if (count($difffields))
00203                                         {
00204                                                 $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_changed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . join($difffields, ", "));
00205                                         }
00206                                 }
00207                                 else
00208                                 {
00209                                         $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_removed", ilObjAssessmentFolder::_getLogLanguage()) . ": " . 
00210                                                 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
00211                                                 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
00212                                                 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
00213                                                 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);                                              
00214                                 }
00215                         }
00216                         foreach ($newmarks as $level => $row)
00217                         {
00218                                 if (!array_key_exists($level, $oldmarks))
00219                                 {
00220                                         $this->logAction($test_id, $lng->txtlng("assessment", "log_mark_added", ilObjAssessmentFolder::_getLogLanguage()) . ": " . 
00221                                                 $lng->txtlng("assessment", "tst_mark_minimum_level", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["minimum_level"] . ", " .
00222                                                 $lng->txtlng("assessment", "tst_mark_short_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["short_name"] . ", " .
00223                                                 $lng->txtlng("assessment", "tst_mark_official_form", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["official_name"] . ", " .
00224                                                 $lng->txtlng("assessment", "tst_mark_passed", ilObjAssessmentFolder::_getLogLanguage()) . " = " . $row["passed"]);
00225                                 }
00226                         }
00227                 }
00228   }
00229 
00238   function loadFromDb($test_id)
00239   {
00240                 global $ilias;
00241                 $db =& $ilias->db->db;
00242                 
00243     if (!$test_id) return;
00244     $query = sprintf("SELECT * FROM tst_mark WHERE test_fi = %s ORDER BY minimum_level",
00245       $db->quote($test_id)
00246     );
00247 
00248     $result = $db->query($query);
00249     if (strcmp(strtolower(get_class($result)), db_result) == 0) {
00250       while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT)) {
00251         $this->add_mark_step($data->short_name, $data->official_name, $data->minimum_level, $data->passed);
00252       }
00253     }
00254   }
00255   
00264   function flush() {
00265     $this->mark_steps = array();
00266   }
00267   
00276   function sort() {
00277     function level_sort($a, $b) {
00278       if ($a->get_minimum_level() == $b->get_minimum_level()) {
00279         $res = strcmp($a->get_short_name(), $b->get_short_name());
00280         if ($res == 0) {
00281           return strcmp($a->get_official_name(), $b->get_official_name());
00282         } else {
00283           return $res;
00284         }
00285       }
00286       return ($a->get_minimum_level() < $b->get_minimum_level()) ? -1 : 1;
00287     }
00288     
00289     usort($this->mark_steps, 'level_sort');
00290   }
00291   
00301   function delete_mark_step($index = 0) {
00302     if ($index < 0) return;
00303     if (count($this->mark_steps) < 1) return;
00304     if ($index >= count($this->mark_steps)) return;
00305     unset($this->mark_steps[$index]);
00306     $this->mark_steps = array_values($this->mark_steps);
00307   }
00308 
00318   function delete_mark_steps($indexes) {
00319     foreach ($indexes as $key => $index) {
00320       if (!(($index < 0) or (count($this->mark_steps) < 1))) {
00321         unset($this->mark_steps[$index]);
00322       }
00323     }
00324     $this->mark_steps = array_values($this->mark_steps);
00325   }
00326 
00337   function get_matching_mark($percentage) {
00338     for ($i = count($this->mark_steps) - 1; $i >= 0; $i--) {
00339       if ($percentage >= $this->mark_steps[$i]->get_minimum_level()) {
00340         return $this->mark_steps[$i];
00341       }
00342     }
00343                 return false;
00344   }
00345   
00355         function checkMarks()
00356         {
00357                 $minimum_percentage = 100;
00358                 $passed = 0;
00359     for ($i = 0; $i < count($this->mark_steps); $i++) {
00360                         if ($this->mark_steps[$i]->get_minimum_level() < $minimum_percentage)
00361                         {
00362                                 $minimum_percentage = $this->mark_steps[$i]->get_minimum_level();
00363                         }
00364                         if ($this->mark_steps[$i]->get_passed())
00365                         {
00366                                 $passed++;
00367                         }
00368     }
00369                 if ($minimum_percentage != 0)
00370                 {
00371                         return "min_percentage_ne_0";
00372                 }
00373                 if ($passed == 0)
00374                 {
00375                         return "no_passed_mark";
00376                 }
00377                 return true;
00378         }
00379 
00389         function logAction($test_id, $logtext = "")
00390         {
00391                 global $ilUser;
00392                 include_once "./classes/class.ilObjAssessmentFolder.php";
00393                 ilObjAssessmentFolder::_addLog($ilUser->id, ilObjTest::_getObjectIDFromTestID($test_id), $logtext);
00394         }
00395 }
00396 
00397 ?>

Generated on Fri Dec 13 2013 10:18:25 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1