ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTestService.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
18  protected $object = null;
19 
24  public function __construct(ilObjTest $a_object)
25  {
26  $this->object = $a_object;
27  }
28 
36  public function getPassOverviewData($active_id, $short = false)
37  {
38  $passOverwiewData = array();
39 
40  global $ilUser;
41 
42  $scoredPass = $this->object->_getResultPass($active_id);
43  $lastPass = ilObjTest::_getPass($active_id);
44 
45  $testPercentage = 0;
46  $testReachedPoints = 0;
47  $testMaxPoints = 0;
48 
49  for ($pass = 0; $pass <= $lastPass; $pass++) {
50  $passFinishDate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
51 
52  if ($passFinishDate <= 0) {
53  continue;
54  }
55 
56  if (!$short) {
57  $resultData =&$this->object->getTestResult($active_id, $pass);
58 
59  if (!$resultData["pass"]["total_max_points"]) {
60  $passPercentage = 0;
61  } else {
62  $passPercentage = ($resultData["pass"]["total_reached_points"]/$resultData["pass"]["total_max_points"])*100;
63  }
64 
65  $passMaxPoints = $resultData["pass"]["total_max_points"];
66  $passReachedPoints = $resultData["pass"]["total_reached_points"];
67 
68  $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
69  $passTotalQuestions = count($resultData) - 2;
70 
71  if ($pass == $scoredPass) {
72  $isScoredPass = true;
73 
74  if (!$resultData["test"]["total_max_points"]) {
75  $testPercentage = 0;
76  } else {
77  $testPercentage = ($resultData["test"]["total_reached_points"]/$resultData["test"]["total_max_points"])*100;
78  }
79 
80  $testMaxPoints = $resultData["test"]["total_max_points"];
81  $testReachedPoints = $resultData["test"]["total_reached_points"];
82 
83  $passOverwiewData['test'] = array(
84  'active_id' => $active_id,
85  'scored_pass' => $scoredPass,
86  'max_points' => $testMaxPoints,
87  'reached_points' => $testReachedPoints,
88  'percentage' => $testPercentage
89  );
90  } else {
91  $isScoredPass = false;
92  }
93 
94  $passOverwiewData['passes'][] = array(
95  'active_id' => $active_id,
96  'pass' => $pass,
97  'finishdate' => $passFinishDate,
98  'max_points' => $passMaxPoints,
99  'reached_points' => $passReachedPoints,
100  'percentage' => $passPercentage,
101  'answered_questions' => $passAnsweredQuestions,
102  'total_questions' => $passTotalQuestions,
103  'is_scored_pass' => $isScoredPass
104  );
105  }
106  }
107 
108  return $passOverwiewData;
109  }
110 
119  public function getManScoringQuestionGuiList($activeId, $pass)
120  {
121  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
122  $manScoringQuestionTypes = ilObjAssessmentFolder::_getManualScoring();
123 
124  $testResultData = $this->object->getTestResult($activeId, $pass);
125 
126  $manScoringQuestionGuiList = array();
127 
128  foreach ($testResultData as $questionData) {
129  if (!isset($questionData['qid'])) {
130  continue;
131  }
132 
133  if (!isset($questionData['type'])) {
134  throw new ilTestException('no question type given!');
135  }
136 
137  $questionGUI = $this->object->createQuestionGUI("", $questionData['qid']);
138 
139  if (!in_array($questionGUI->object->getQuestionTypeID(), $manScoringQuestionTypes)) {
140  continue;
141  }
142 
143  $manScoringQuestionGuiList[ $questionData['qid'] ] = $questionGUI;
144  }
145 
146  return $manScoringQuestionGuiList;
147  }
148 
158  public static function isManScoringDone($activeId)
159  {
160  $assessmentSetting = new ilSetting("assessment");
161  return $assessmentSetting->get("manscoring_done_" . $activeId, false);
162  }
163 
173  public static function setManScoringDone($activeId, $manScoringDone)
174  {
175  $assessmentSetting = new ilSetting("assessment");
176  $assessmentSetting->set("manscoring_done_" . $activeId, (bool) $manScoringDone);
177  }
178 
179  public function buildVirtualSequence(ilTestSession $testSession)
180  {
181  global $ilDB, $lng, $ilPluginAdmin;
182 
183  require_once 'Modules/Test/classes/class.ilTestVirtualSequence.php';
184  $testSequenceFactory = new ilTestSequenceFactory($ilDB, $lng, $ilPluginAdmin, $this->object);
185 
186  if ($this->object->isRandomTest()) {
187  require_once 'Modules/Test/classes/class.ilTestVirtualSequenceRandomQuestionSet.php';
188  $virtualSequence = new ilTestVirtualSequenceRandomQuestionSet($ilDB, $this->object, $testSequenceFactory);
189  } else {
190  require_once 'Modules/Test/classes/class.ilTestVirtualSequence.php';
191  $virtualSequence = new ilTestVirtualSequence($ilDB, $this->object, $testSequenceFactory);
192  }
193 
194  $virtualSequence->setActiveId($testSession->getActiveId());
195 
196  $virtualSequence->init();
197 
198  return $virtualSequence;
199  }
200 
201  public function getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
202  {
203  $resultsByPass = array();
204 
205  foreach ($virtualSequence->getUniquePasses() as $pass) {
206  $results = $this->object->getTestResult(
207  $virtualSequence->getActiveId(),
208  $pass,
209  false,
210  true,
211  true
212  );
213 
214  $resultsByPass[$pass] = $results;
215  }
216 
217  $virtualPassResults = array();
218 
219  foreach ($virtualSequence->getQuestionsPassMap() as $questionId => $pass) {
220  foreach ($resultsByPass[$pass] as $key => $questionResult) {
221  if ($key === 'test' || $key === 'pass') {
222  continue;
223  }
224 
225  if ($questionResult['qid'] == $questionId) {
226  $questionResult['pass'] = $pass;
227  $virtualPassResults[$questionId] = $questionResult;
228  break;
229  }
230  }
231  }
232 
233  return $virtualPassResults;
234  }
235 
241  public function getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, $obligationsFilterEnabled)
242  {
243  $result_array = $testSequence->getSequenceSummary($obligationsFilterEnabled);
244 
245  $marked_questions = array();
246 
247  if ($this->object->getShowMarker()) {
248  include_once "./Modules/Test/classes/class.ilObjTest.php";
249  $marked_questions = ilObjTest::_getSolvedQuestions($testSequence->getActiveId());
250  }
251 
252  $data = array();
253 
254  foreach ($result_array as $key => $value) {
255  $description = "";
256  if ($this->object->getListOfQuestionsDescription()) {
257  $description = $value["description"];
258  }
259 
260  $points = "";
261  if (!$this->object->getTitleOutput()) {
262  $points = $value["points"];
263  }
264 
265  $marked = false;
266  if (count($marked_questions)) {
267  if (array_key_exists($value["qid"], $marked_questions)) {
268  $obj = $marked_questions[$value["qid"]];
269  if ($obj["solved"] == 1) {
270  $marked = true;
271  }
272  }
273  }
274 
275  // fau: testNav - add number parameter for getQuestionTitle()
276  $data[] = array('order' => $value["nr"], 'title' => $this->object->getQuestionTitle($value["title"], $value["nr"]), 'description' => $description, 'worked_through' => $value["worked_through"], 'postponed' => $value["postponed"], 'points' => $points, 'marked' => $marked, 'sequence' => $value["sequence"], 'obligatory' => $value['obligatory'], 'isAnswered' => $value['isAnswered']);
277  // fau.
278  }
279 
280  return $data;
281  }
282 }
getPassOverviewData($active_id, $short=false)
public ilObjUser $ilUser
static setManScoringDone($activeId, $manScoringDone)
stores the flag wether manscoring is done for the given test active or not within the global settings...
getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, $obligationsFilterEnabled)
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
static lookupPassResultsUpdateTimestamp($active_id, $pass)
getSequenceSummary($obligationsFilterEnabled=false)
static isManScoringDone($activeId)
reads the flag wether manscoring is done for the given test active or not from the global settings (s...
Base Exception for all Exceptions relating to Modules/Test.
buildVirtualSequence(ilTestSession $testSession)
static _getSolvedQuestions($active_id, $question_fi=null)
get solved questions
$ilUser
Definition: imgupload.php:18
Test session handler.
getManScoringQuestionGuiList($activeId, $pass)
Returns the list of answers of a users test pass and offers a scoring option.
Create styles array
The data for the language used.
__construct(ilObjTest $a_object)
public
Service class for tests.
Create new PHPExcel object
obj_idprivate
static _getManualScoring()
Retrieve the manual scoring settings.
$results
Definition: svg-scanner.php:47
global $lng
Definition: privfeed.php:17
global $ilDB
$key
Definition: croninfo.php:18