ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestSkillLevelThresholdList.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
5
13{
17 private $db;
18
22 private $testId;
23
27 private $thresholds = array();
28
29 public function __construct(ilDB $db)
30 {
31 $this->db = $db;
32 }
33
37 public function setTestId($testId)
38 {
39 $this->testId = $testId;
40 }
41
45 public function getTestId()
46 {
47 return $this->testId;
48 }
49
50 public function resetThresholds()
51 {
52 $this->thresholds = array();
53 }
54
55 public function loadFromDb()
56 {
57 $this->resetThresholds();
58
59 $query = "
60 SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
61 FROM tst_skl_thresholds
62 WHERE test_fi = %s
63 ";
64
65 $res = $this->db->queryF( $query, array('integer'), array($this->getTestId()) );
66
67 while( $row = $this->db->fetchAssoc($res) )
68 {
69 $threshold = $this->buildSkillLevelThresholdByArray($row);
70
71 $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
72
73 $this->addThreshold($skillKey, $threshold->getSkillLevelId(), $threshold);
74 }
75 }
76
77 private function addThreshold($skillKey, $skillLevelId, $threshold)
78 {
79 $this->thresholds[$skillKey][$skillLevelId] = $threshold;
80 }
81
83 {
84 $threshold = new ilTestSkillLevelThreshold($this->db);
85
86 $threshold->setTestId($data['test_fi']);
87 $threshold->setSkillBaseId($data['skill_base_fi']);
88 $threshold->setSkillTrefId($data['skill_tref_fi']);
89 $threshold->setSkillLevelId($data['skill_level_fi']);
90 $threshold->setThreshold($data['threshold']);
91
92 return $threshold;
93 }
94
95 public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId)
96 {
97 $skillKey = $skillBaseId . ':' . $skillTrefId;
98
99 if( !isset($this->thresholds[$skillKey]) || !isset($this->thresholds[$skillKey][$skillLevelId]) )
100 {
101 return null;
102 }
103
104 return $this->thresholds[$skillKey][$skillLevelId];
105 }
106
107 public function cloneListForTest($testId)
108 {
109 foreach($this->thresholds as $skillKey => $data)
110 {
111 foreach($data as $levelId => $threshold)
112 {
113 /* @var ilTestSkillLevelThreshold $threshold */
114
115 $threshold->setTestId($testId);
116 $threshold->saveToDb();
117
118 $threshold->setTestId($this->getTestId());
119 }
120 }
121 }
122}
Database Wrapper.
Definition: class.ilDB.php:29
addThreshold($skillKey, $skillLevelId, $threshold)
getThreshold($skillBaseId, $skillTrefId, $skillLevelId)
$data