ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestSkillLevelThreshold.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  private $db;
31 
35  private $testId;
36 
40  private $skillBaseId;
41 
45  private $skillTrefId;
46 
50  private $skillLevelId;
51 
55  private $threshold;
56 
57  public function __construct(ilDBInterface $db)
58  {
59  $this->db = $db;
60  }
61 
62  public function loadFromDb()
63  {
64  $query = "
65  SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
66  FROM tst_skl_thresholds
67  WHERE test_fi = %s
68  AND skill_base_fi = %s
69  AND skill_tref_fi = %s
70  AND skill_level_fi = %s
71  ";
72 
73  $res = $this->db->queryF(
74  $query,
75  array('integer', 'integer', 'integer', 'integer'),
76  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
77  );
78 
79  $row = $this->db->fetchAssoc($res);
80 
81  if (is_array($row)) {
82  $this->setThreshold($row['threshold']);
83  }
84  }
85 
86  public function saveToDb()
87  {
88  if ($this->dbRecordExists()) {
89  $this->db->update(
90  'tst_skl_thresholds',
91  array(
92  'threshold' => array('integer', $this->getThreshold())
93  ),
94  array(
95  'test_fi' => array('integer', $this->getTestId()),
96  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
97  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
98  'skill_level_fi' => array('integer', $this->getSkillLevelId())
99  )
100  );
101  } else {
102  $this->db->insert('tst_skl_thresholds', array(
103  'test_fi' => array('integer', $this->getTestId()),
104  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
105  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
106  'skill_level_fi' => array('integer', $this->getSkillLevelId()),
107  'threshold' => array('integer', $this->getThreshold())
108  ));
109  }
110  }
111 
112  public function deleteFromDb()
113  {
114  $query = "
115  DELETE FROM tst_skl_thresholds
116  WHERE test_fi = %s
117  AND skill_base_fi = %s
118  AND skill_tref_fi = %s
119  AND skill_level_fi = %s
120  ";
121 
122  $this->db->manipulateF(
123  $query,
124  array('integer', 'integer', 'integer', 'integer'),
125  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
126  );
127  }
128 
129  public function dbRecordExists(): bool
130  {
131  $query = "
132  SELECT COUNT(*) cnt
133  FROM tst_skl_thresholds
134  WHERE test_fi = %s
135  AND skill_base_fi = %s
136  AND skill_tref_fi = %s
137  AND skill_level_fi = %s
138  ";
139 
140  $res = $this->db->queryF(
141  $query,
142  array('integer', 'integer', 'integer', 'integer'),
143  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
144  );
145 
146  $row = $this->db->fetchAssoc($res);
147 
148  return $row['cnt'] > 0;
149  }
150 
154  public function setTestId($testId)
155  {
156  $this->testId = $testId;
157  }
158 
159  public function getTestId(): ?int
160  {
161  return $this->testId;
162  }
163 
167  public function setSkillBaseId($skillBaseId)
168  {
169  $this->skillBaseId = $skillBaseId;
170  }
171 
172  public function getSkillBaseId(): ?int
173  {
174  return $this->skillBaseId;
175  }
176 
180  public function setSkillTrefId($skillTrefId)
181  {
182  $this->skillTrefId = $skillTrefId;
183  }
184 
185  public function getSkillTrefId(): ?int
186  {
187  return $this->skillTrefId;
188  }
189 
194  {
195  $this->skillLevelId = $skillLevelId;
196  }
197 
198  public function getSkillLevelId(): ?int
199  {
200  return $this->skillLevelId;
201  }
202 
206  public function setThreshold($threshold)
207  {
208  $this->threshold = $threshold;
209  }
210 
211  public function getThreshold(): ?int
212  {
213  return $this->threshold;
214  }
215 }
$res
Definition: ltiservices.php:69
$query