ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 = [];
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 = [];
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, ['integer'], [$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 
126  public function getThreshold(
127  $skill_base_id,
128  $skill_tref_id,
129  $skill_level_id,
130  $force_object = false
132  $skillKey = $skill_base_id . ':' . $skill_tref_id;
133 
134  if (isset($this->thresholds[$skillKey]) && isset($this->thresholds[$skillKey][$skill_level_id])) {
135  return $this->thresholds[$skillKey][$skill_level_id];
136  }
137 
138  if ($force_object) {
139  $threshold = new ilTestSkillLevelThreshold($this->db);
140 
141  $threshold->setTestId($this->getTestId());
142  $threshold->setSkillBaseId($skill_base_id);
143  $threshold->setSkillTrefId($skill_tref_id);
144  $threshold->setSkillLevelId($skill_level_id);
145 
146  return $threshold;
147  }
148 
149  return null;
150  }
151 
153  int $skill_base_id,
154  int $skill_tref_id
155  ): array {
156  return $this->thresholds["{$skill_base_id}:{$skill_tref_id}"] ?? [];
157  }
158 
159  public function cloneListForTest($testId)
160  {
161  foreach ($this->thresholds as $data) {
162  foreach ($data as $threshold) {
163  /* @var ilTestSkillLevelThreshold $threshold */
164 
165  $threshold->setTestId($testId);
166  $threshold->saveToDb();
167 
168  $threshold->setTestId($this->getTestId());
169  }
170  }
171  }
172 }
$res
Definition: ltiservices.php:66
getThesholdsOfBaseAndTrefId(int $skill_base_id, int $skill_tref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getThreshold( $skill_base_id, $skill_tref_id, $skill_level_id, $force_object=false)