ILIAS  release_8 Revision v8.24
class.ilTestSkillLevelThresholdList.php
Go to the documentation of this file.
1<?php
2
26{
30 private $db;
31
35 private $testId;
36
40 private $thresholds = array();
41
42 public function __construct(ilDBInterface $db)
43 {
44 $this->db = $db;
45 }
46
50 public function setTestId($testId)
51 {
52 $this->testId = $testId;
53 }
54
58 public function getTestId(): int
59 {
60 return $this->testId;
61 }
62
63 public function resetThresholds()
64 {
65 $this->thresholds = array();
66 }
67
68 public function loadFromDb()
69 {
70 $this->resetThresholds();
71
72 $query = "
73 SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
74 FROM tst_skl_thresholds
75 WHERE test_fi = %s
76 ";
77
78 $res = $this->db->queryF($query, array('integer'), array($this->getTestId()));
79
80 while ($row = $this->db->fetchAssoc($res)) {
81 $threshold = $this->buildSkillLevelThresholdByArray($row);
82 $this->addThreshold($threshold);
83 }
84 }
85
88 public function saveToDb()
89 {
90 foreach ($this->thresholds as $skillKey => $skillLevels) {
91 foreach ($skillLevels as $levelThreshold) {
92 /* @var ilTestSkillLevelThreshold $levelThreshold */
93 $levelThreshold->saveToDb();
94 }
95 }
96 }
97
101 public function addThreshold($threshold)
102 {
103 $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
104 $this->thresholds[$skillKey][$threshold->getSkillLevelId()] = $threshold;
105 }
106
112 {
113 $threshold = new ilTestSkillLevelThreshold($this->db);
114
115 $threshold->setTestId($data['test_fi']);
116 $threshold->setSkillBaseId($data['skill_base_fi']);
117 $threshold->setSkillTrefId($data['skill_tref_fi']);
118 $threshold->setSkillLevelId($data['skill_level_fi']);
119 $threshold->setThreshold($data['threshold']);
120
121 return $threshold;
122 }
123
130 public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject = false): ?ilTestSkillLevelThreshold
131 {
132 $skillKey = $skillBaseId . ':' . $skillTrefId;
133
134 if (isset($this->thresholds[$skillKey]) && isset($this->thresholds[$skillKey][$skillLevelId])) {
135 return $this->thresholds[$skillKey][$skillLevelId];
136 }
137
138 if ($forceObject) {
139 $threshold = new ilTestSkillLevelThreshold($this->db);
140
141 $threshold->setTestId($this->getTestId());
142 $threshold->setSkillBaseId($skillBaseId);
143 $threshold->setSkillTrefId($skillTrefId);
144 $threshold->setSkillLevelId($skillLevelId);
145
146 return $threshold;
147 }
148
149 return null;
150 }
151
152 public function cloneListForTest($testId)
153 {
154 foreach ($this->thresholds as $skillKey => $data) {
155 foreach ($data as $levelId => $threshold) {
156 /* @var ilTestSkillLevelThreshold $threshold */
157
158 $threshold->setTestId($testId);
159 $threshold->saveToDb();
160
161 $threshold->setTestId($this->getTestId());
162 }
163 }
164 }
165}
getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject=false)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query