ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
41  $ilUser = $DIC['ilUser'];
42 
43  $scoredPass = $this->object->_getResultPass($active_id);
44  $lastPass = ilObjTest::_getPass($active_id);
45 
46  $testPercentage = 0;
47  $testReachedPoints = 0;
48  $testMaxPoints = 0;
49 
50  for ($pass = 0; $pass <= $lastPass; $pass++) {
51  $passFinishDate = ilObjTest::lookupPassResultsUpdateTimestamp($active_id, $pass);
52 
53  if ($passFinishDate <= 0) {
54  continue;
55  }
56 
57  if (!$short) {
58  $resultData = &$this->object->getTestResult($active_id, $pass);
59 
60  if (!$resultData["pass"]["total_max_points"]) {
61  $passPercentage = 0;
62  } else {
63  $passPercentage = ($resultData["pass"]["total_reached_points"] / $resultData["pass"]["total_max_points"]) * 100;
64  }
65 
66  $passMaxPoints = $resultData["pass"]["total_max_points"];
67  $passReachedPoints = $resultData["pass"]["total_reached_points"];
68 
69  $passAnsweredQuestions = $this->object->getAnsweredQuestionCount($active_id, $pass);
70  $passTotalQuestions = count($resultData) - 2;
71 
72  if ($pass == $scoredPass) {
73  $isScoredPass = true;
74 
75  if (!$resultData["test"]["total_max_points"]) {
76  $testPercentage = 0;
77  } else {
78  $testPercentage = ($resultData["test"]["total_reached_points"] / $resultData["test"]["total_max_points"]) * 100;
79  }
80 
81  $testMaxPoints = $resultData["test"]["total_max_points"];
82  $testReachedPoints = $resultData["test"]["total_reached_points"];
83 
84  $passOverwiewData['test'] = array(
85  'active_id' => $active_id,
86  'scored_pass' => $scoredPass,
87  'max_points' => $testMaxPoints,
88  'reached_points' => $testReachedPoints,
89  'percentage' => $testPercentage
90  );
91  } else {
92  $isScoredPass = false;
93  }
94 
95  $passOverwiewData['passes'][] = array(
96  'active_id' => $active_id,
97  'pass' => $pass,
98  'finishdate' => $passFinishDate,
99  'max_points' => $passMaxPoints,
100  'reached_points' => $passReachedPoints,
101  'percentage' => $passPercentage,
102  'answered_questions' => $passAnsweredQuestions,
103  'total_questions' => $passTotalQuestions,
104  'is_scored_pass' => $isScoredPass
105  );
106  }
107  }
108 
109  return $passOverwiewData;
110  }
111 
120  public function getManScoringQuestionGuiList($activeId, $pass)
121  {
122  include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php";
123  $manScoringQuestionTypes = ilObjAssessmentFolder::_getManualScoring();
124 
125  $testResultData = $this->object->getTestResult($activeId, $pass);
126 
127  $manScoringQuestionGuiList = array();
128 
129  foreach ($testResultData as $questionData) {
130  if (!isset($questionData['qid'])) {
131  continue;
132  }
133 
134  if (!isset($questionData['type'])) {
135  throw new ilTestException('no question type given!');
136  }
137 
138  $questionGUI = $this->object->createQuestionGUI("", $questionData['qid']);
139 
140  if (!in_array($questionGUI->object->getQuestionTypeID(), $manScoringQuestionTypes)) {
141  continue;
142  }
143 
144  $manScoringQuestionGuiList[ $questionData['qid'] ] = $questionGUI;
145  }
146 
147  return $manScoringQuestionGuiList;
148  }
149 
159  public static function isManScoringDone($activeId)
160  {
161  $assessmentSetting = new ilSetting("assessment");
162  return $assessmentSetting->get("manscoring_done_" . $activeId, false);
163  }
164 
174  public static function setManScoringDone($activeId, $manScoringDone)
175  {
176  $assessmentSetting = new ilSetting("assessment");
177  $assessmentSetting->set("manscoring_done_" . $activeId, (bool) $manScoringDone);
178  }
179 
180  public function buildVirtualSequence(ilTestSession $testSession)
181  {
182  global $DIC;
183  $ilDB = $DIC['ilDB'];
184  $lng = $DIC['lng'];
185  $ilPluginAdmin = $DIC['ilPluginAdmin'];
186 
187  require_once 'Modules/Test/classes/class.ilTestVirtualSequence.php';
188  $testSequenceFactory = new ilTestSequenceFactory($ilDB, $lng, $ilPluginAdmin, $this->object);
189 
190  if ($this->object->isRandomTest()) {
191  require_once 'Modules/Test/classes/class.ilTestVirtualSequenceRandomQuestionSet.php';
192  $virtualSequence = new ilTestVirtualSequenceRandomQuestionSet($ilDB, $this->object, $testSequenceFactory);
193  } else {
194  require_once 'Modules/Test/classes/class.ilTestVirtualSequence.php';
195  $virtualSequence = new ilTestVirtualSequence($ilDB, $this->object, $testSequenceFactory);
196  }
197 
198  $virtualSequence->setActiveId($testSession->getActiveId());
199 
200  $virtualSequence->init();
201 
202  return $virtualSequence;
203  }
204 
205  public function getVirtualSequenceUserResults(ilTestVirtualSequence $virtualSequence)
206  {
207  $resultsByPass = array();
208 
209  foreach ($virtualSequence->getUniquePasses() as $pass) {
210  $results = $this->object->getTestResult(
211  $virtualSequence->getActiveId(),
212  $pass,
213  false,
214  true,
215  true
216  );
217 
218  $resultsByPass[$pass] = $results;
219  }
220 
221  $virtualPassResults = array();
222 
223  foreach ($virtualSequence->getQuestionsPassMap() as $questionId => $pass) {
224  foreach ($resultsByPass[$pass] as $key => $questionResult) {
225  if ($key === 'test' || $key === 'pass') {
226  continue;
227  }
228 
229  if ($questionResult['qid'] == $questionId) {
230  $questionResult['pass'] = $pass;
231  $virtualPassResults[$questionId] = $questionResult;
232  break;
233  }
234  }
235  }
236 
237  return $virtualPassResults;
238  }
239 
245  public function getQuestionSummaryData(ilTestSequenceSummaryProvider $testSequence, $obligationsFilterEnabled)
246  {
247  $result_array = $testSequence->getSequenceSummary($obligationsFilterEnabled);
248 
249  $marked_questions = array();
250 
251  if ($this->object->getShowMarker()) {
252  include_once "./Modules/Test/classes/class.ilObjTest.php";
253  $marked_questions = ilObjTest::_getSolvedQuestions($testSequence->getActiveId());
254  }
255 
256  $data = array();
257  $firstQuestion = true;
258 
259  foreach ($result_array as $key => $value) {
260  $disableLink = (
261  $this->object->isFollowupQuestionAnswerFixationEnabled()
262  && !$value['presented'] && !$firstQuestion
263  );
264 
265  $description = "";
266  if ($this->object->getListOfQuestionsDescription()) {
267  $description = $value["description"];
268  }
269 
270  $points = "";
271  if (!$this->object->getTitleOutput()) {
272  $points = $value["points"];
273  }
274 
275  $marked = false;
276  if (count($marked_questions)) {
277  if (array_key_exists($value["qid"], $marked_questions)) {
278  $obj = $marked_questions[$value["qid"]];
279  if ($obj["solved"] == 1) {
280  $marked = true;
281  }
282  }
283  }
284 
285  // fau: testNav - add number parameter for getQuestionTitle()
286  $data[] = array(
287  'order' => $value["nr"],
288  'title' => $this->object->getQuestionTitle($value["title"], $value["nr"]),
289  'description' => $description,
290  'disabled' => $disableLink,
291  'worked_through' => $value["worked_through"],
292  'postponed' => $value["postponed"],
293  'points' => $points,
294  'marked' => $marked,
295  'sequence' => $value["sequence"],
296  'obligatory' => $value['obligatory'],
297  'isAnswered' => $value['isAnswered']
298  );
299 
300  $firstQuestion = false;
301  // fau.
302  }
303 
304  return $data;
305  }
306 }
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.
global $DIC
Definition: saml.php:7
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)
$lng
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.
__construct(ilObjTest $a_object)
public
Service class for tests.
static _getManualScoring()
Retrieve the manual scoring settings.
$results
Definition: svg-scanner.php:47
global $ilDB
$key
Definition: croninfo.php:18
$data
Definition: bench.php:6