ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestSkillLevelThreshold.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 $skillBaseId;
43 
47  private $skillTrefId;
48 
52  private $skillLevelId;
53 
57  private $threshold;
58 
59  public function __construct(ilDBInterface $db)
60  {
61  $this->db = $db;
62  }
63 
64  public function loadFromDb()
65  {
66  $query = "
67  SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
68  FROM tst_skl_thresholds
69  WHERE test_fi = %s
70  AND skill_base_fi = %s
71  AND skill_tref_fi = %s
72  AND skill_level_fi = %s
73  ";
74 
75  $res = $this->db->queryF(
76  $query,
77  array('integer', 'integer', 'integer', 'integer'),
78  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
79  );
80 
81  $row = $this->db->fetchAssoc($res);
82 
83  if (is_array($row)) {
84  $this->setThreshold((int) $row['threshold']);
85  }
86  }
87 
88  public function saveToDb()
89  {
90  if ($this->dbRecordExists()) {
91  $this->db->update(
92  'tst_skl_thresholds',
93  array(
94  'threshold' => array('integer', $this->getThreshold())
95  ),
96  array(
97  'test_fi' => array('integer', $this->getTestId()),
98  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
99  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
100  'skill_level_fi' => array('integer', $this->getSkillLevelId())
101  )
102  );
103  } else {
104  $this->db->insert('tst_skl_thresholds', array(
105  'test_fi' => array('integer', $this->getTestId()),
106  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
107  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
108  'skill_level_fi' => array('integer', $this->getSkillLevelId()),
109  'threshold' => array('integer', $this->getThreshold())
110  ));
111  }
112  }
113 
114  public function deleteFromDb()
115  {
116  $query = "
117  DELETE FROM tst_skl_thresholds
118  WHERE test_fi = %s
119  AND skill_base_fi = %s
120  AND skill_tref_fi = %s
121  AND skill_level_fi = %s
122  ";
123 
124  $this->db->manipulateF(
125  $query,
126  array('integer', 'integer', 'integer', 'integer'),
127  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
128  );
129  }
130 
131  public function dbRecordExists(): bool
132  {
133  $query = "
134  SELECT COUNT(*) cnt
135  FROM tst_skl_thresholds
136  WHERE test_fi = %s
137  AND skill_base_fi = %s
138  AND skill_tref_fi = %s
139  AND skill_level_fi = %s
140  ";
141 
142  $res = $this->db->queryF(
143  $query,
144  array('integer', 'integer', 'integer', 'integer'),
145  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
146  );
147 
148  $row = $this->db->fetchAssoc($res);
149 
150  return $row['cnt'] > 0;
151  }
152 
156  public function setTestId($testId)
157  {
158  $this->testId = $testId;
159  }
160 
161  public function getTestId(): ?int
162  {
163  return $this->testId;
164  }
165 
169  public function setSkillBaseId($skillBaseId)
170  {
171  $this->skillBaseId = $skillBaseId;
172  }
173 
174  public function getSkillBaseId(): ?int
175  {
176  return $this->skillBaseId;
177  }
178 
182  public function setSkillTrefId($skillTrefId)
183  {
184  $this->skillTrefId = $skillTrefId;
185  }
186 
187  public function getSkillTrefId(): ?int
188  {
189  return $this->skillTrefId;
190  }
191 
196  {
197  $this->skillLevelId = $skillLevelId;
198  }
199 
200  public function getSkillLevelId(): ?int
201  {
202  return $this->skillLevelId;
203  }
204 
208  public function setThreshold($threshold)
209  {
210  $this->threshold = $threshold;
211  }
212 
213  public function getThreshold(): ?int
214  {
215  return is_numeric($this->threshold) ? (int) $this->threshold : null;
216  }
217 }
$res
Definition: ltiservices.php:69