ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestSkillLevelThreshold.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
12 {
16  private $db;
17 
21  private $testId;
22 
26  private $skillBaseId;
27 
31  private $skillTrefId;
32 
36  private $skillLevelId;
37 
41  private $threshold;
42 
43  public function __construct(ilDBInterface $db)
44  {
45  $this->db = $db;
46  }
47 
48  public function loadFromDb()
49  {
50  $query = "
51  SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
52  FROM tst_skl_thresholds
53  WHERE test_fi = %s
54  AND skill_base_fi = %s
55  AND skill_tref_fi = %s
56  AND skill_level_fi = %s
57  ";
58 
59  $res = $this->db->queryF(
60  $query,
61  array('integer', 'integer', 'integer', 'integer'),
62  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
63  );
64 
65  $row = $this->db->fetchAssoc($res);
66 
67  if (is_array($row)) {
68  $this->setThreshold($row['threshold']);
69  }
70  }
71 
72  public function saveToDb()
73  {
74  if ($this->dbRecordExists()) {
75  $this->db->update(
76  'tst_skl_thresholds',
77  array(
78  'threshold' => array('integer', $this->getThreshold())
79  ),
80  array(
81  'test_fi' => array('integer', $this->getTestId()),
82  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
83  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
84  'skill_level_fi' => array('integer', $this->getSkillLevelId())
85  )
86  );
87  } else {
88  $this->db->insert('tst_skl_thresholds', array(
89  'test_fi' => array('integer', $this->getTestId()),
90  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
91  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
92  'skill_level_fi' => array('integer', $this->getSkillLevelId()),
93  'threshold' => array('integer', $this->getThreshold())
94  ));
95  }
96  }
97 
98  public function deleteFromDb()
99  {
100  $query = "
101  DELETE FROM tst_skl_thresholds
102  WHERE test_fi = %s
103  AND skill_base_fi = %s
104  AND skill_tref_fi = %s
105  AND skill_level_fi = %s
106  ";
107 
108  $this->db->manipulateF(
109  $query,
110  array('integer', 'integer', 'integer', 'integer'),
111  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
112  );
113  }
114 
115  public function dbRecordExists()
116  {
117  $query = "
118  SELECT COUNT(*) cnt
119  FROM tst_skl_thresholds
120  WHERE test_fi = %s
121  AND skill_base_fi = %s
122  AND skill_tref_fi = %s
123  AND skill_level_fi = %s
124  ";
125 
126  $res = $this->db->queryF(
127  $query,
128  array('integer', 'integer', 'integer', 'integer'),
129  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
130  );
131 
132  $row = $this->db->fetchAssoc($res);
133 
134  return $row['cnt'] > 0;
135  }
136 
140  public function setTestId($testId)
141  {
142  $this->testId = $testId;
143  }
144 
148  public function getTestId()
149  {
150  return $this->testId;
151  }
152 
156  public function setSkillBaseId($skillBaseId)
157  {
158  $this->skillBaseId = $skillBaseId;
159  }
160 
164  public function getSkillBaseId()
165  {
166  return $this->skillBaseId;
167  }
168 
172  public function setSkillTrefId($skillTrefId)
173  {
174  $this->skillTrefId = $skillTrefId;
175  }
176 
180  public function getSkillTrefId()
181  {
182  return $this->skillTrefId;
183  }
184 
189  {
190  $this->skillLevelId = $skillLevelId;
191  }
192 
196  public function getSkillLevelId()
197  {
198  return $this->skillLevelId;
199  }
200 
204  public function setThreshold($threshold)
205  {
206  $this->threshold = $threshold;
207  }
208 
212  public function getThreshold()
213  {
214  return $this->threshold;
215  }
216 }
foreach($_POST as $key=> $value) $res
$query
$row