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

course/classes/class.ilCourseObjectiveQuestion.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 
00035 class ilCourseObjectiveQuestion
00036 {
00037         var $db = null;
00038 
00039         var $objective_id = null;
00040         var $questions;
00041 
00042         function ilCourseObjectiveQuestion($a_objective_id)
00043         {
00044                 global $ilDB;
00045 
00046                 $this->db =& $ilDB;
00047         
00048                 $this->objective_id = $a_objective_id;
00049 
00050                 $this->__read();
00051         }
00052 
00053         // ########################################################  Methods for test table
00054         function setTestStatus($a_status)
00055         {
00056                 $this->tst_status = $a_status;
00057         }
00058         function getTestStatus()
00059         {
00060                 return (int) $this->tst_status;
00061         }
00062         function setTestSuggestedLimit($a_limit)
00063         {
00064                 $this->tst_limit = $a_limit;
00065         }
00066         function getTestSuggestedLimit()
00067         {
00068                 return (int) $this->tst_limit;
00069         }
00070         function __addTest()
00071         {
00072                 // CHECK if entry already exists
00073                 $query = "SELECT * FROM crs_objective_tst ".
00074                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00075                         "AND ref_id = '".$this->getTestRefId()."'";
00076 
00077                 $res = $this->db->query($query);
00078                 if($res->numRows())
00079                 {
00080                         return false;
00081                 }
00082                 $query = "INSERT INTO crs_objective_tst ".
00083                         "SET objective_id = '".$this->getObjectiveId()."', ".
00084                         "ref_id = '".$this->getTestRefId()."', ".
00085                         "obj_id = '".$this->getTestObjId()."', ".
00086                         "tst_status = '".$this->getTestStatus()."', ".
00087                         "tst_limit = '100'";
00088 
00089                 $this->db->query($query);
00090 
00091                 return true;
00092         }
00093 
00094         function __deleteTest($a_test_ref_id)
00095         {
00096                 // Delete questions
00097                 $query = "DELETE FROM crs_objective_qst ".
00098                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00099                         "AND ref_id = '".$a_test_ref_id."'";
00100 
00101                 $this->db->query($query);
00102 
00103                 // delete tst entries
00104                 $query = "DELETE FROM crs_objective_tst ".
00105                         "WHERE objective_id = '".$this->getObjectiveId()."' ".
00106                         "AND ref_id = '".$a_test_ref_id."'";
00107 
00108                 $this->db->query($query);
00109 
00110                 return true;
00111         }
00112 
00113         function updateTest($a_test_objective_id)
00114         {
00115                 $query = "UPDATE crs_objective_tst ".
00116                         "SET tst_status = '".$this->getTestStatus()."', ".
00117                         "tst_limit = '".$this->getTestSuggestedLimit()."' ".
00118                         "WHERE test_objective_id = '".$a_test_objective_id."'";
00119 
00120                 $this->db->query($query);
00121 
00122                 return true;
00123         }
00124 
00125         function getTests()
00126         {
00127                 $query = "SELECT * FROM crs_objective_tst ".
00128                         "WHERE objective_id = '".$this->getObjectiveId()."'";
00129 
00130                 $res = $this->db->query($query);
00131                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00132                 {
00133                         $test['test_objective_id'] = $row->test_objective_id;
00134                         $test['objective_id']           = $row->objective_id;
00135                         $test['ref_id']                 = $row->ref_id;
00136                         $test['obj_id']                 = $row->obj_id;
00137                         $test['tst_status']             = $row->tst_status;
00138                         $test['tst_limit']              = $row->tst_limit;
00139 
00140                         $tests[] = $test;
00141                 }
00142 
00143                 return $tests ? $tests : array();
00144         }
00145         
00146         function _getTest($a_test_objective_id)
00147         {
00148                 global $ilDB;
00149 
00150                 $query = "SELECT * FROM crs_objective_tst ".
00151                         "WHERE test_objective_id = '".$a_test_objective_id."'";
00152 
00153                 $res = $ilDB->query($query);
00154                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00155                 {
00156                         $test['test_objective_id'] = $row->test_objective_id;
00157                         $test['objective_id']           = $row->objective_id;
00158                         $test['ref_id']                 = $row->ref_id;
00159                         $test['obj_id']                 = $row->obj_id;
00160                         $test['tst_status']             = $row->tst_status;
00161                         $test['tst_limit']              = $row->tst_limit;
00162                 }
00163 
00164                 return $test ? $test : array();
00165         }
00166 
00167         // ############################################################# METHODS for question table
00168         function getQuestions()
00169         {
00170                 return $this->questions ? $this->questions : array();
00171         }
00172         
00173         function getQuestion($question_id)
00174         {
00175                 return $this->questions[$question_id] ? $this->questions[$question_id] : array();
00176         }
00177 
00178         function getObjectiveId()
00179         {
00180                 return $this->objective_id;
00181         }
00182 
00183         function setTestRefId($a_ref_id)
00184         {
00185                 $this->tst_ref_id = $a_ref_id;
00186         }
00187         function getTestRefId()
00188         {
00189                 return $this->tst_ref_id ? $this->tst_ref_id : 0;
00190         }
00191         function setTestObjId($a_obj_id)
00192         {
00193                 $this->tst_obj_id = $a_obj_id;
00194         }
00195         function getTestObjId()
00196         {
00197                 return $this->tst_obj_id ? $this->tst_obj_id : 0;
00198         }
00199         function setQuestionId($a_question_id)
00200         {
00201                 $this->question_id = $a_question_id;
00202         }
00203         function getQuestionId()
00204         {
00205                 return $this->question_id;
00206         }
00207 
00208 
00209         function getMaxPointsByObjective()
00210         {
00211                 include_once './assessment/classes/class.ilObjTest.php';
00212 
00213                 $points = 0;
00214                 foreach($this->getQuestions() as $question)
00215                 {
00216                         $tmp_test =& ilObjectFactory::getInstanceByRefId($question['ref_id']);
00217 
00218                         $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
00219 
00220                         $points += $tmp_question->getMaximumPoints();
00221 
00222                         unset($tmp_question);
00223                         unset($tmp_test);
00224                 }
00225                 return $points;
00226         }
00227         
00228         function getMaxPointsByTest($a_test_ref_id)
00229         {
00230                 $points = 0;
00231 
00232                 $tmp_test =& ilObjectFactory::getInstanceByRefId($a_test_ref_id);
00233 
00234                 foreach($this->getQuestions() as $question)
00235                 {
00236                         if($question['ref_id'] == $a_test_ref_id)
00237                         {
00238                                 $tmp_question =& ilObjTest::_instanciateQuestion($question['question_id']);
00239 
00240                                 $points += $tmp_question->getMaximumPoints();
00241 
00242                                 unset($tmp_question);
00243                         }
00244                 }
00245                 unset($tmp_test);
00246 
00247                 return $points;
00248         }
00249 
00250         function getNumberOfQuestionsByTest($a_test_ref_id)
00251         {
00252                 $counter = 0;
00253 
00254                 foreach($this->getQuestions() as $question)
00255                 {
00256                         if($question['ref_id'] == $a_test_ref_id)
00257                         {
00258                                 ++$counter;
00259                         }
00260                 }
00261                 return $counter;
00262         }
00263 
00264         function getQuestionsByTest($a_test_ref_id)
00265         {
00266                 foreach($this->getQuestions() as $question)
00267                 {
00268                         if($question['ref_id'] == $a_test_ref_id)
00269                         {
00270                                 $qst[] = $question['question_id'];
00271                         }
00272                 }
00273                 return $qst ? $qst : array();
00274         }
00275 
00276 
00277         function add()
00278         {
00279                 $query = "INSERT INTO crs_objective_qst ".
00280                         "SET objective_id = '".$this->getObjectiveId()."', ".
00281                         "ref_id = '".$this->getTestRefId()."', ".
00282                         "obj_id = '".$this->getTestObjId()."', ".
00283                         "question_id = '".$this->getQuestionId()."'";
00284 
00285                 $this->db->query($query);
00286 
00287                 $this->__addTest();
00288 
00289                 return true;
00290         }
00291         function delete($qst_id)
00292         {
00293                 if(!$qst_id)
00294                 {
00295                         return false;
00296                 }
00297                 
00298                 $query = "SELECT * FROM crs_objective_qst ".
00299                         "WHERE qst_ass_id = '".$qst_id."'";
00300 
00301                 $res = $this->db->query($query);
00302                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00303                 {
00304                         $test_rid = $row->ref_id;
00305                         $test_oid = $row->obj_id;
00306                 }
00307 
00308                 $query = "DELETE FROM crs_objective_qst ".
00309                         "WHERE qst_ass_id = '".$qst_id."'";
00310 
00311                 $this->db->query($query);
00312 
00313                 // delete test if it was the last question
00314                 $query = "SELECT * FROM crs_objective_qst ".
00315                         "WHERE ref_id = '".$test_rid."' ".
00316                         "AND obj_id = '".$test_oid."'";
00317 
00318                 $res = $this->db->query($query);
00319                 if(!$res->numRows())
00320                 {
00321                         $this->__deleteTest($test_rid);
00322                 }
00323 
00324                 return true;
00325         }
00326 
00327         function deleteAll()
00328         {
00329                 $query = "DELETE FROM crs_objective_qst ".
00330                         "WHERE objective_id = '".$this->getObjectiveId()."'";
00331 
00332                 $this->db->query($query);
00333 
00334                 $query = "DELETE FROM crs_objective_tst ".
00335                         "WHERE objective_id = '".$this->getObjectiveId()."'";
00336 
00337                 $this->db->query($query);
00338 
00339                 return true;
00340         }
00341 
00342 
00343         // PRIVATE
00344         function __read()
00345         {
00346                 include_once './assessment/classes/class.ilObjTest.php';
00347 
00348                 global $tree;
00349 
00350                 $this->questions = array();
00351                 $query = "SELECT * FROM crs_objective_qst ".
00352                         "WHERE objective_id = '".$this->getObjectiveId()."'";
00353 
00354                 $res = $this->db->query($query);
00355                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00356                 {
00357                         if(!$tree->isInTree($row->ref_id))
00358                         {
00359                                 $this->__deleteTest($row->ref_id);
00360                                 continue;
00361                         }
00362                         if(!$question = ilObjTest::_instanciateQuestion($row->question_id))
00363                         {
00364                                 $this->delete($row->question_id);
00365                                 continue;
00366                         }
00367                         $qst['ref_id'] = $row->ref_id;
00368                         $qst['obj_id'] = $row->obj_id;
00369                         $qst['question_id'] = $row->question_id;
00370                         $qst['qst_ass_id'] = $row->qst_ass_id;
00371                         $qst['title'] = $question->getTitle();
00372 
00373                         $this->questions[$row->qst_ass_id] = $qst;
00374                 }
00375                 return true;
00376         }
00377 
00378         // STATIC
00379         function _isAssigned($a_objective_id,$a_tst_ref_id,$a_question_id)
00380         {
00381                 global $ilDB;
00382 
00383                 $query = "SELECT crs_qst.objective_id as objective_id FROM crs_objective_qst as crs_qst, crs_objectives as crs_obj ".
00384                         "WHERE crs_qst.objective_id = crs_obj.objective_id ".
00385                         "AND crs_qst.objective_id = '".$a_objective_id ."' ".
00386                         "AND ref_id = '".$a_tst_ref_id."' ".
00387                         "AND question_id = '".$a_question_id."'";
00388 
00389                 $res = $ilDB->query($query);
00390                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00391                 {
00392                         $objective_id = $row->objective_id;
00393                 }
00394                 
00395                 return $objective_id ? $objective_id : 0;
00396         }
00397 
00398 }
00399 ?>

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