1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Export/classes/class.ilExportGUI.php';
5
6/**
7 * Signature Plugin Class
8 * @author       Maximilian Becker <mbecker@databay.de>
9 *
10 * @version      $Id$
11 *
12 * @ingroup      ModulesTest
13 */
14class ilTestSignatureGUI
15{
16    /** @var $lng \ilLanguage */
17    protected $lng;
18
19    /** @var $ilCtrl ilCtrl */
20    protected $ilCtrl;
21
22    /** @var $tpl \ilTemplate  */
23    protected $tpl;
24
25    /** @var $testGUI \ilObjTestGUI */
26    protected $testGUI;
27
28    /** @var $ilTestOutputGUI \ilTestOutputGUI */
29    protected $ilTestOutputGUI;
30
31    /** @var $test \ilObjTest */
32    protected $test;
33
34    /** @var \ilTestSignaturePlugin */
35    protected $plugin;
36
37    public function __construct(ilTestOutputGUI $testOutputGUI)
38    {
39        global $DIC;
40        $lng = $DIC['lng'];
41        $ilCtrl = $DIC['ilCtrl'];
42        $tpl = $DIC['tpl'];
43        $ilPluginAdmin = $DIC['ilPluginAdmin'];
44
45        $this->lng = $lng;
46        $this->ilCtrl = $ilCtrl;
47        $this->tpl = $tpl;
48
49        $this->ilTestOutputGUI = $testOutputGUI;
50        $this->test = $this->ilTestOutputGUI->object;
51
52        $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, 'Test', 'tsig');
53        $pl = current($pl_names);
54        $this->plugin = ilPluginAdmin::getPluginObject(IL_COMP_MODULE, 'Test', 'tsig', $pl);
55        $this->plugin->setGUIObject($this);
56    }
57
58    public function executeCommand()
59    {
60        $next_class = $this->ilCtrl->getNextClass($this);
61
62        switch ($next_class) {
63            default:
64                $ret = $this->dispatchCommand();
65                break;
66        }
67        return $ret;
68    }
69
70    protected function dispatchCommand()
71    {
72        /** @var $ilUser ilObjUser */
73        global $DIC;
74        $ilUser = $DIC['ilUser'];
75        $active = $this->test->getActiveIdOfUser($ilUser->getId());
76        $pass = $this->test->_getMaxPass($active);
77        $key = 'signed_' . $active . '_' . $pass;
78        ilSession::set($key, null);
79
80        $cmd = $this->ilCtrl->getCmd();
81        switch ($cmd) {
82            default:
83                $ret = $this->plugin->invoke($cmd);
84        }
85        return $ret;
86    }
87
88    /**
89     * @param \ilObjTest $test
90     */
91    public function setTest($test)
92    {
93        $this->test = $test;
94    }
95
96    /**
97     * @return \ilObjTest
98     */
99    public function getTest()
100    {
101        return $this->test;
102    }
103
104    /**
105     * @param \ilObjTestGUI $testGUI
106     */
107    public function setTestGUI($testGUI)
108    {
109        $this->testGUI = $testGUI;
110    }
111
112    /**
113     * @return \ilObjTestGUI
114     */
115    public function getTestGUI()
116    {
117        return $this->testGUI;
118    }
119
120    /**
121     * @param \ilTestOutputGUI $testOutputGUI
122     */
123    public function setTestOutputGUI($testOutputGUI)
124    {
125        $this->ilTestOutputGUI = $testOutputGUI;
126    }
127
128    /**
129     * @return \ilTestOutputGUI
130     */
131    public function getTestOutputGUI()
132    {
133        return $this->ilTestOutputGUI;
134    }
135
136    /**
137     * This is to be called by the plugin at the end of the signature process to redirect the user back to the test.
138     */
139    public function redirectToTest($success)
140    {
141        /** @var $ilCtrl ilCtrl */
142        /** @var $ilUser ilObjUser */
143        global $DIC;
144        $ilCtrl = $DIC['ilCtrl'];
145        $ilUser = $DIC['ilUser'];
146        $active = $this->test->getActiveIdOfUser($ilUser->getId());
147        $pass = $this->test->_getMaxPass($active);
148        $key = 'signed_' . $active . '_' . $pass;
149        ilSession::set($key, $success);
150        $ilCtrl->redirect($this->ilTestOutputGUI, 'afterTestPassFinished');
151        return;
152    }
153}
154