ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestSkillLevelThresholdList.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
32  private $db;
33 
37  private $testId;
38 
42  private $thresholds = array();
43 
44  public function __construct(ilDBInterface $db)
45  {
46  $this->db = $db;
47  }
48 
52  public function setTestId($testId)
53  {
54  $this->testId = $testId;
55  }
56 
60  public function getTestId(): int
61  {
62  return $this->testId;
63  }
64 
65  public function resetThresholds()
66  {
67  $this->thresholds = array();
68  }
69 
70  public function loadFromDb()
71  {
72  $this->resetThresholds();
73 
74  $query = "
75  SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
76  FROM tst_skl_thresholds
77  WHERE test_fi = %s
78  ";
79 
80  $res = $this->db->queryF($query, array('integer'), array($this->getTestId()));
81 
82  while ($row = $this->db->fetchAssoc($res)) {
83  $threshold = $this->buildSkillLevelThresholdByArray($row);
84  $this->addThreshold($threshold);
85  }
86  }
87 
90  public function saveToDb()
91  {
92  foreach ($this->thresholds as $skillKey => $skillLevels) {
93  foreach ($skillLevels as $levelThreshold) {
94  /* @var ilTestSkillLevelThreshold $levelThreshold */
95  $levelThreshold->saveToDb();
96  }
97  }
98  }
99 
103  public function addThreshold($threshold)
104  {
105  $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
106  $this->thresholds[$skillKey][$threshold->getSkillLevelId()] = $threshold;
107  }
108 
114  {
115  $threshold = new ilTestSkillLevelThreshold($this->db);
116 
117  $threshold->setTestId($data['test_fi']);
118  $threshold->setSkillBaseId($data['skill_base_fi']);
119  $threshold->setSkillTrefId($data['skill_tref_fi']);
120  $threshold->setSkillLevelId($data['skill_level_fi']);
121  $threshold->setThreshold($data['threshold']);
122 
123  return $threshold;
124  }
125 
132  public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject = false): ?ilTestSkillLevelThreshold
133  {
134  $skillKey = $skillBaseId . ':' . $skillTrefId;
135 
136  if (isset($this->thresholds[$skillKey]) && isset($this->thresholds[$skillKey][$skillLevelId])) {
137  return $this->thresholds[$skillKey][$skillLevelId];
138  }
139 
140  if ($forceObject) {
141  $threshold = new ilTestSkillLevelThreshold($this->db);
142 
143  $threshold->setTestId($this->getTestId());
144  $threshold->setSkillBaseId($skillBaseId);
145  $threshold->setSkillTrefId($skillTrefId);
146  $threshold->setSkillLevelId($skillLevelId);
147 
148  return $threshold;
149  }
150 
151  return null;
152  }
153 
154  public function cloneListForTest($testId)
155  {
156  foreach ($this->thresholds as $data) {
157  foreach ($data as $threshold) {
158  /* @var ilTestSkillLevelThreshold $threshold */
159 
160  $threshold->setTestId($testId);
161  $threshold->saveToDb();
162 
163  $threshold->setTestId($this->getTestId());
164  }
165  }
166  }
167 }
$res
Definition: ltiservices.php:69
getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject=false)