1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestVirtualSequence.php';
5require_once 'Modules/Test/interfaces/interface.ilTestRandomQuestionSequence.php';
6
7/**
8 * @author		Björn Heyser <bheyser@databay.de>
9 * @version		$Id$
10 *
11 * @package     Modules/Test
12 */
13class ilTestVirtualSequenceRandomQuestionSet extends ilTestVirtualSequence implements ilTestRandomQuestionSequence
14{
15    private $questionsSourcePoolDefinitionMap;
16
17    public function __construct(ilDBInterface $db, ilObjTest $testOBJ, ilTestSequenceFactory $testSequenceFactory)
18    {
19        parent::__construct($db, $testOBJ, $testSequenceFactory);
20
21        $this->questionsSourcePoolDefinitionMap = array();
22    }
23
24    public function getResponsibleSourcePoolDefinitionId($questionId)
25    {
26        return $this->questionsSourcePoolDefinitionMap[$questionId];
27    }
28
29    protected function fetchQuestionsFromPasses($activeId, $passes)
30    {
31        $this->questionsPassMap = array();
32
33        foreach ($passes as $pass) {
34            $handledSourcePoolDefinitions = array_flip($this->questionsSourcePoolDefinitionMap);
35
36            $testSequence = $this->getTestSequence($activeId, $pass);
37
38            foreach ($testSequence->getOrderedSequenceQuestions() as $questionId) {
39                $definitionId = $testSequence->getResponsibleSourcePoolDefinitionId($questionId);
40
41                if (isset($handledSourcePoolDefinitions[$definitionId])) {
42                    continue;
43                }
44
45                if ($this->wasAnsweredInThisPass($testSequence, $questionId)) {
46                    $this->questionsPassMap[$questionId] = $pass;
47
48                    $this->questionsSourcePoolDefinitionMap[$questionId] = $definitionId;
49                }
50            }
51        }
52    }
53}
54