ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestService.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
19  protected $object = null;
20 
25  public function __construct(ilObjTest $a_object)
26  {
27  $this->object = $a_object;
28  }
29 
37  public function getPassOverviewData($active_id, $short = false)
38  {
39  $passOverwiewData = array();
40 
41  global $ilUser;
42 
43  $scoredPass = $this->object->_getResultPass($active_id);
44  $lastPass = $this->object->_getPass($active_id);
45 
46  $testPercentage = 0;
47  $testReachedPoints = 0;
48  $testMaxPoints = 0;
49 
50  for( $pass = 0; $pass <= $lastPass; $pass++)
51  {
52  $passFinishDate = $this->object->getPassFinishDate($active_id, $pass);
53 
54  if( $passFinishDate <= 0 )
55  {
56  continue;
57  }
58 
59  if( !$short )
60  {
61  $resultData =& $this->object->getTestResult($active_id, $pass);
62 
63  if (!$resultData["pass"]["total_max_points"])
64  {
65  $passPercentage = 0;
66  }
67  else
68  {
69  $passPercentage = ($resultData["pass"]["total_reached_points"]/$resultData["pass"]["total_max_points"])*100;
70  }
71 
72  $passMaxPoints = $resultData["pass"]["total_max_points"];
73  $passReachedPoints = $resultData["pass"]["total_reached_points"];
74 
75  $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
76  $passTotalQuestions = count($resultData) - 2;
77 
78  if( $pass == $scoredPass )
79  {
80  $isScoredPass = true;
81 
82  if (!$resultData["test"]["total_max_points"])
83  {
84  $testPercentage = 0;
85  }
86  else
87  {
88  $testPercentage = ($resultData["test"]["total_reached_points"]/$resultData["test"]["total_max_points"])*100;
89  }
90 
91  $testMaxPoints = $resultData["test"]["total_max_points"];
92  $testReachedPoints = $resultData["test"]["total_reached_points"];
93 
94  $passOverwiewData['test'] = array(
95  'active_id' => $active_id,
96  'scored_pass' => $scoredPass,
97  'max_points' => $testMaxPoints,
98  'reached_points' => $testReachedPoints,
99  'percentage' => $testPercentage
100  );
101  }
102  else $isScoredPass = false;
103 
104  $passOverwiewData['passes'][] = array(
105  'active_id' => $active_id,
106  'pass' => $pass,
107  'finishdate' => $passFinishDate,
108  'max_points' => $passMaxPoints,
109  'reached_points' => $passReachedPoints,
110  'percentage' => $passPercentage,
111  'answered_questions' => $passAnsweredQuestions,
112  'total_questions' => $passTotalQuestions,
113  'is_scored_pass' => $isScoredPass
114  );
115  }
116  }
117 
118  return $passOverwiewData;
119  }
120 
129  public function getManScoringQuestionGuiList($activeId, $pass)
130  {
131  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
132  $manScoringQuestionTypes = ilObjAssessmentFolder::_getManualScoring();
133 
134  $testResultData = $this->object->getTestResult($activeId, $pass);
135 
136  $manScoringQuestionGuiList = array();
137 
138  foreach($testResultData as $questionData)
139  {
140  if( !isset($questionData['qid']) )
141  {
142  continue;
143  }
144 
145  if( !isset($questionData['type']) )
146  {
147  throw new ilTestException('no question type given!');
148  }
149 
150  $questionGUI = $this->object->createQuestionGUI("", $questionData['qid']);
151 
152  if( !in_array($questionGUI->object->getQuestionTypeID(), $manScoringQuestionTypes) )
153  {
154  continue;
155  }
156 
157  $manScoringQuestionGuiList[ $questionData['qid'] ] = $questionGUI;
158  }
159 
160  return $manScoringQuestionGuiList;
161  }
162 
172  public static function isManScoringDone($activeId)
173  {
174  $assessmentSetting = new ilSetting("assessment");
175  return $assessmentSetting->get("manscoring_done_" . $activeId, false);
176  }
177 
187  public static function setManScoringDone($activeId, $manScoringDone)
188  {
189  $assessmentSetting = new ilSetting("assessment");
190  $assessmentSetting->set("manscoring_done_" . $activeId, (bool)$manScoringDone);
191  }
192 }
193