1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
5require_once 'Modules/Test/classes/class.ilTestPlayerFactory.php';
6require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
7require_once 'Modules/Test/classes/class.ilTestSequenceFactory.php';
8require_once 'Modules/Test/classes/class.ilTestDynamicQuestionSetFilterSelection.php';
9require_once 'Modules/Test/classes/toolbars/class.ilTestInfoScreenToolbarGUI.php';
10
11/**
12 * @author        Björn Heyser <bheyser@databay.de>
13 * @version        $Id$
14 *
15 * @package     Modules/Test
16 */
17class ilTestInfoScreenToolbarFactory
18{
19    /**
20     * @var integer
21     */
22    private $testRefId;
23
24    /**
25     * @var ilObjTest
26     */
27    private $testOBJ;
28
29    /**
30     * @var ilTestQuestionSetConfigFactory
31     */
32    private $testQuestionSetConfigFactory;
33
34    /**
35     * @var ilTestPlayerFactory
36     */
37    private $testPlayerFactory;
38
39    /**
40     * @var ilTestSessionFactory
41     */
42    private $testSessionFactory;
43
44    /**
45     * @var ilTestSequenceFactory
46     */
47    private $testSequenceFactory;
48
49    /**
50     * @return int
51     */
52    public function getTestRefId()
53    {
54        return $this->testRefId;
55    }
56
57    /**
58     * @param int $testRefId
59     */
60    public function setTestRefId($testRefId)
61    {
62        $this->testRefId = $testRefId;
63    }
64
65    /**
66     * @return ilObjTest
67     */
68    public function getTestOBJ()
69    {
70        return $this->testOBJ;
71    }
72
73    /**
74     * @param ilObjTest $testOBJ
75     */
76    public function setTestOBJ($testOBJ)
77    {
78        $this->testOBJ = $testOBJ;
79    }
80
81    protected function ensureInitialised()
82    {
83        $this->ensureTestObjectInitialised();
84
85        $d = $GLOBALS['DIC'];
86
87        $this->testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory(
88            $d['tree'],
89            $d['ilDB'],
90            $d['ilPluginAdmin'],
91            $this->getTestOBJ()
92        );
93
94        $this->testPlayerFactory = new ilTestPlayerFactory($this->getTestOBJ());
95        $this->testSessionFactory = new ilTestSessionFactory($this->getTestOBJ());
96
97        $this->testSequenceFactory = new ilTestSequenceFactory(
98            $d['ilDB'],
99            $d['lng'],
100            $d['ilPluginAdmin'],
101            $this->getTestOBJ()
102        );
103    }
104
105    private function ensureTestObjectInitialised()
106    {
107        if (!($this->testOBJ instanceof ilObjTest)) {
108            $this->testOBJ = ilObjectFactory::getInstanceByRefId($this->testRefId);
109        }
110    }
111
112    public function getToolbarInstance()
113    {
114        $this->ensureInitialised();
115
116        $d = $GLOBALS['DIC'];
117
118        $toolbar = new ilTestInfoScreenToolbarGUI($d['ilDB'], $d['ilAccess'], $d['ilCtrl'], $d['lng'], $d['ilPluginAdmin']);
119
120        $toolbar->setTestOBJ($this->getTestOBJ());
121        $toolbar->setTestPlayerGUI($this->testPlayerFactory->getPlayerGUI());
122
123        $testQuestionSetConfig = $this->testQuestionSetConfigFactory->getQuestionSetConfig();
124        $testSession = $this->testSessionFactory->getSession();
125        $testSequence = $this->testSequenceFactory->getSequenceByTestSession($testSession);
126        $testSequence->loadFromDb();
127        $testSequence->loadQuestions($testQuestionSetConfig, new ilTestDynamicQuestionSetFilterSelection());
128
129        $toolbar->setTestQuestionSetConfig($testQuestionSetConfig);
130        $toolbar->setTestSession($testSession);
131        $toolbar->setTestSequence($testSequence);
132
133        return $toolbar;
134    }
135}
136