1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4/**
5 * @author        Björn Heyser <bheyser@databay.de>
6 * @version        $Id$
7 *
8 * @package     Modules/Test(QuestionPool)
9 */
10class ilTestSkillLevelThresholdExporter
11{
12    /**
13     * @var ilXmlWriter
14     */
15    protected $xmlWriter;
16
17    /**
18     * @var ilAssQuestionSkillAssignmentList
19     */
20    protected $assignmentList;
21
22    /**
23     * @var ilTestSkillLevelThresholdList
24     */
25    protected $thresholdList;
26
27    /**
28     * ilAssQuestionSkillAssignmentExporter constructor.
29     */
30    public function __construct()
31    {
32        $this->xmlWriter = null;
33    }
34
35    /**
36     * @return ilXmlWriter
37     */
38    public function getXmlWriter()
39    {
40        return $this->xmlWriter;
41    }
42
43    /**
44     * @param ilXmlWriter $xmlWriter
45     */
46    public function setXmlWriter(ilXmlWriter $xmlWriter)
47    {
48        $this->xmlWriter = $xmlWriter;
49    }
50
51    /**
52     * @return ilAssQuestionSkillAssignmentList
53     */
54    public function getAssignmentList()
55    {
56        return $this->assignmentList;
57    }
58
59    /**
60     * @param ilAssQuestionSkillAssignmentList $assignmentList
61     */
62    public function setAssignmentList($assignmentList)
63    {
64        $this->assignmentList = $assignmentList;
65    }
66
67    /**
68     * @return ilTestSkillLevelThresholdList
69     */
70    public function getThresholdList()
71    {
72        return $this->thresholdList;
73    }
74
75    /**
76     * @param ilTestSkillLevelThresholdList $thresholdList
77     */
78    public function setThresholdList($thresholdList)
79    {
80        $this->thresholdList = $thresholdList;
81    }
82
83    public function export()
84    {
85        $this->getXmlWriter()->xmlStartTag('SkillsLevelThresholds');
86
87        foreach ($this->getAssignmentList()->getUniqueAssignedSkills() as $assignedSkillData) {
88            $this->getXmlWriter()->xmlStartTag('QuestionsAssignedSkill', array(
89                'BaseId' => $assignedSkillData['skill_base_id'],
90                'TrefId' => $assignedSkillData['skill_tref_id']
91            ));
92
93            $this->getXmlWriter()->xmlElement('OriginalSkillTitle', null, $assignedSkillData['skill_title']);
94            $this->getXmlWriter()->xmlElement('OriginalSkillPath', null, $assignedSkillData['skill_path']);
95
96            /* @var ilBasicSkill $assignedSkill */
97            $assignedSkill = $assignedSkillData['skill'];
98            $skillLevels = $assignedSkill->getLevelData();
99
100            for ($i = 0, $max = count($skillLevels); $i < $max; $i++) {
101                $levelData = $skillLevels[$i];
102
103                $skillLevelThreshold = $this->getThresholdList()->getThreshold(
104                    $assignedSkillData['skill_base_id'],
105                    $assignedSkillData['skill_tref_id'],
106                    $levelData['id'],
107                    true
108                );
109
110                $this->getXmlWriter()->xmlStartTag('SkillLevel', array(
111                    'Id' => $levelData['id'], 'Nr' => $levelData['nr']
112                ));
113
114                $this->getXmlWriter()->xmlElement('ThresholdPercentage', null, $skillLevelThreshold->getThreshold());
115
116                $this->getXmlWriter()->xmlElement('OriginalLevelTitle', null, $levelData['title']);
117                $this->getXmlWriter()->xmlElement('OriginalLevelDescription', null, $levelData['description']);
118
119                $this->getXmlWriter()->xmlEndTag('SkillLevel');
120            }
121
122            $this->getXmlWriter()->xmlEndTag('QuestionsAssignedSkill');
123        }
124
125        $this->getXmlWriter()->xmlEndTag('SkillsLevelThresholds');
126    }
127}
128