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

assessment/classes/class.ilCommandControl.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004         +-----------------------------------------------------------------------------+
00005         | ILIAS open source                                                           |
00006         +-----------------------------------------------------------------------------+
00007         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00008         |                                                                             |
00009         | This program is free software; you can redistribute it and/or               |
00010         | modify it under the terms of the GNU General Public License                 |
00011         | as published by the Free Software Foundation; either version 2              |
00012         | of the License, or (at your option) any later version.                      |
00013         |                                                                             |
00014         | This program is distributed in the hope that it will be useful,             |
00015         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017         | GNU General Public License for more details.                                |
00018         |                                                                             |
00019         | You should have received a copy of the GNU General Public License           |
00020         | along with this program; if not, write to the Free Software                 |
00021         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022         +-----------------------------------------------------------------------------+
00023 */
00024 
00025 
00039 class CommandControl 
00040 {       
00041         var $gui;
00042         var $obj;
00043         var $lng;
00044         var $tpl;
00045         var $tree;
00046         
00047         function CommandControl (&$gui, &$object) {
00048                 $this->gui = & $gui;
00049                 $this->obj = & $object;
00050                 $this->lng = & $gui->lng;
00051                 $this->tpl = & $gui->tpl;
00052                 $this->tree = & $gui->tree;
00053         }               
00054 }
00055 
00056 
00063 class DefaultTestCommandControl extends CommandControl {
00064         
00065         function DefaultTestCommandControl (&$gui, &$object) {
00066                 parent::CommandControl($gui, $object);
00067         }
00068                         
00072         function prepareRequestVariables (){
00073                 // set showresult cmd if pressed on sort in result overview
00074                 if ($_GET["sortres"])
00075                         $_POST["cmd"]["showresults"] = 1; 
00076         }
00077         
00081         function onRunObjectEnter (){
00082                 // cancel Test if it's not online test
00083                 if ($_POST["cmd"]["cancelTest"])
00084                 {
00085                         $this->handleCancelCommand();
00086                 }               
00087                 // check online exams access restrictions due to participants and client ip
00088         }       
00089         
00090         
00094         function handleCommands () {
00095                 global $ilUser;
00096                 if ($_POST["cmd"]["confirmdeleteresults"])
00097                 {
00098                         $this->obj->deleteResults($ilUser->id);
00099                         sendInfo($this->gui->lng->txt("tst_confirm_delete_results_info"));
00100                 }
00101                 
00102                 if ($_POST["cmd"]["deleteresults"])
00103                 {
00104                         $this->gui->confirmDeleteResults();
00105                         return true;
00106                 }
00107                 
00108                 if ($_GET["evaluation"])
00109                 {
00110                         $this->gui->outEvaluationForm();
00111                         return true;
00112                 }
00113 
00114                 if (($_POST["cmd"]["showresults"]) or ($_GET["sortres"]))
00115                 {
00116                         $this->gui->outTestResults();
00117                         return true;
00118                 }
00119                 
00120                 return false;           
00121         }
00122         
00127         function handleStartCommands () {
00128                 global $ilUser;
00129                         
00130                 if ($_POST["cmd"]["start"] && $this->obj->isRandomTest())
00131                 {
00132                         if ($this->obj->getRandomQuestionCount() > 0)
00133                         {
00134                                 $qpls =& $this->obj->getRandomQuestionpools();
00135                                 $rndquestions = $this->obj->randomSelectQuestions($this->obj->getRandomQuestionCount(), 0, 1, $qpls);
00136                                 $allquestions = array();
00137                                 foreach ($rndquestions as $question_id)
00138                                 {
00139                                         array_push($allquestions, $question_id);
00140                                 }
00141                                 srand ((float)microtime()*1000000);
00142                                 shuffle($allquestions);
00143                                 foreach ($allquestions as $question_id)
00144                                 {
00145                                         $this->obj->saveRandomQuestion($question_id);
00146                                 }
00147                                 $this->obj->loadQuestions();
00148                         }
00149                         else
00150                         {
00151                                 $qpls =& $this->obj->getRandomQuestionpools();
00152                                 $allquestions = array();
00153                                 foreach ($qpls as $key => $value)
00154                                 {
00155                                         if ($value["count"] > 0)
00156                                         {
00157                                                 $rndquestions = $this->obj->randomSelectQuestions($value["count"], $value["qpl"], 1);
00158                                                 foreach ($rndquestions as $question_id)
00159                                                 {
00160                                                         array_push($allquestions, $question_id);
00161                                                 }
00162                                         }
00163                                 }
00164                                 srand ((float)microtime()*1000000);
00165                                 shuffle($allquestions);
00166                                 foreach ($allquestions as $question_id)
00167                                 {
00168                                         $this->obj->saveRandomQuestion($question_id);
00169                                 }
00170                                 $this->obj->loadQuestions();
00171                         }
00172                 }
00173                         
00174                 // create new time dataset and set start time
00175                 $active_time_id = $this->obj->startWorkingTime($ilUser->id);
00176                 $_SESSION["active_time_id"] = $active_time_id;
00177                 
00178                 if ($_POST["chb_javascript"])
00179                 {
00180                         $ilUser->setPref("tst_javascript", 1);
00181                         $ilUser->writePref("tst_javascript", 1);
00182                 }
00183                 else
00184                 {
00185                         $ilUser->setPref("tst_javascript", 0);
00186                         $ilUser->writePref("tst_javascript", 0);
00187                 }
00188                 
00189                 return true;
00190                                 
00191         }
00192                 
00197         function handleCancelCommand (){
00198                 sendInfo($this->gui->lng->txt("test_cancelled"), true);
00199                 $path = $this->gui->tree->getPathFull($this->obj->getRefID());
00200                 ilUtil::redirect($this->gui->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00201                 exit();
00202         }
00203         
00208         function getSequence () {
00209                 $sequence = $_GET["sequence"];
00210                 $saveResult = $this->gui->saveResult;
00211                 
00212                 if ($_POST["cmd"]["deleteresults"] or $_POST["cmd"]["canceldeleteresults"] or $_POST["cmd"]["confirmdeleteresults"])
00213                 {
00214                         // reset sequence. it is not needed for test reset
00215                         $sequence = "";
00216                 }
00217                                                         
00218                 if (isset($_POST["cmd"]["next"]) and $saveResult == true)
00219                 {
00220                         if($_GET['crs_show_result'])
00221                         {
00222                                 $sequence = $this->obj->incrementSequenceByResult($sequence);
00223                         }
00224                         else
00225                         {
00226                                 $sequence++;
00227                         }
00228                 }
00229                 elseif (($_POST["cmd"]["previous"]) and ($sequence != 0) and ($saveResult))
00230                 {
00231                         if($_GET['crs_show_result'])
00232                         {
00233                                 $sequence = $this->obj->decrementSequenceByResult($sequence);
00234                         }
00235                         else
00236                         {
00237                                 $sequence--;
00238                         }
00239                 }               
00240                 
00241                 return $sequence;
00242         }
00243         
00244         // logic functions to determin control flow
00245         
00250         function isTestResumable () {
00251                 $active = $this->obj->getActiveTestUser();              
00252                 return is_object($active) && $this->obj->startingTimeReached() && !$this->obj->endingTimeReached();
00253         }
00254         
00258         function isNrOfTriesReached () {
00259                 $active = $this->obj->getActiveTestUser();
00260                 return $this->obj->hasNrOfTriesRestriction() && is_object($active) && $this->obj->isNrOfTriesReached ($active->tries);  
00261         }
00262         
00267         function isTestAccessible() {           
00268                 return  !$this->isNrOfTriesReached()                            
00269                                 and      !$this->gui->isMaxProcessingTimeReached()
00270                                 and  $this->obj->startingTimeReached()
00271                                 and  !$this->gui->isEndingTimeReached();
00272         }
00273         
00274         
00278         function showTestResults () {
00279                 return $_GET['crs_show_result'];// && $this->obj->canViewResults();
00280         }
00281         
00285         function canShowTestResults () {
00286                 $active = $this->obj->getActiveTestUser();
00287                 return ($active->tries > 0) and $this->obj->canViewResults();
00288         }
00289         
00290         
00295          function canSaveResult () {
00296                 #print_r($_POST);
00297                 #print_r($_GET);
00298                 $do_save = (($_POST["cmd"]["next"] || $_POST["cmd"]["previous"] || $_POST["cmd"]["postpone"]
00299                                         || ($_POST["cmd"]["summary"] && !$_GET["sort_summary"])  
00300                                         || $_POST["cmd"]["directfeedback"] ||  $_POST["cmd"]["setsolved"]  || $_POST["cmd"]["resetsolved"] 
00301                                     || isset($_GET["selImage"])) && (isset ($_GET["sequence"]) && is_numeric ($_GET["sequence"])));
00302 
00303                 return $do_save == true &&                              
00304                                 !$this->gui->isEndingTimeReached() && !$this->gui->isMaxProcessingTimeReached() && !$this->isNrOfTriesReached();
00305          }
00306         
00307 }
00308 
00309 
00310 
00311 
00312 ?>

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