ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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(ilDB $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, array('integer', 'integer', 'integer', 'integer'),
61  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
62  );
63 
64  $row = $this->db->fetchAssoc($res);
65 
66  if( is_array($row) )
67  {
68  $this->setThreshold($row['threshold']);
69  }
70  }
71 
72  public function saveToDb()
73  {
74  if( $this->dbRecordExists() )
75  {
76  $this->db->update('tst_skl_thresholds', array(
77  'threshold' => array('integer', $this->getThreshold())
78  ),
79  array(
80  'test_fi' => array('integer', $this->getTestId()),
81  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
82  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
83  'skill_level_fi' => array('integer', $this->getSkillLevelId())
84  )
85  );
86  }
87  else
88  {
89  $this->db->insert('tst_skl_thresholds', array(
90  'test_fi' => array('integer', $this->getTestId()),
91  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
92  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
93  'skill_level_fi' => array('integer', $this->getSkillLevelId()),
94  'threshold' => array('integer', $this->getThreshold())
95  ));
96  }
97  }
98 
99  public function deleteFromDb()
100  {
101  $query = "
102  DELETE FROM tst_skl_thresholds
103  WHERE test_fi = %s
104  AND skill_base_fi = %s
105  AND skill_tref_fi = %s
106  AND skill_level_fi = %s
107  ";
108 
109  $this->db->manipulateF(
110  $query, 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, array('integer', 'integer', 'integer', 'integer'),
128  array($this->getTestId(), $this->getSkillBaseId(), $this->getSkillTrefId(), $this->getSkillLevelId())
129  );
130 
131  $row = $this->db->fetchAssoc($res);
132 
133  return $row['cnt'] > 0;
134  }
135 
139  public function setTestId($testId)
140  {
141  $this->testId = $testId;
142  }
143 
147  public function getTestId()
148  {
149  return $this->testId;
150  }
151 
155  public function setSkillBaseId($skillBaseId)
156  {
157  $this->skillBaseId = $skillBaseId;
158  }
159 
163  public function getSkillBaseId()
164  {
165  return $this->skillBaseId;
166  }
167 
171  public function setSkillTrefId($skillTrefId)
172  {
173  $this->skillTrefId = $skillTrefId;
174  }
175 
179  public function getSkillTrefId()
180  {
181  return $this->skillTrefId;
182  }
183 
188  {
189  $this->skillLevelId = $skillLevelId;
190  }
191 
195  public function getSkillLevelId()
196  {
197  return $this->skillLevelId;
198  }
199 
203  public function setThreshold($threshold)
204  {
205  $this->threshold = $threshold;
206  }
207 
211  public function getThreshold()
212  {
213  return $this->threshold;
214  }
215 }
Database Wrapper.
Definition: class.ilDB.php:28