ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestSkillLevelThresholdList.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 require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
5 
13 {
17  private $db;
18 
22  private $testId;
23 
27  private $thresholds = array();
28 
29  public function __construct(ilDB $db)
30  {
31  $this->db = $db;
32  }
33 
37  public function setTestId($testId)
38  {
39  $this->testId = $testId;
40  }
41 
45  public function getTestId()
46  {
47  return $this->testId;
48  }
49 
50  public function resetThresholds()
51  {
52  $this->thresholds = array();
53  }
54 
55  public function loadFromDb()
56  {
57  $this->resetThresholds();
58 
59  $query = "
60  SELECT test_fi, skill_base_fi, skill_tref_fi, skill_level_fi, threshold
61  FROM tst_skl_thresholds
62  WHERE test_fi = %s
63  ";
64 
65  $res = $this->db->queryF( $query, array('integer'), array($this->getTestId()) );
66 
67  while( $row = $this->db->fetchAssoc($res) )
68  {
69  $threshold = $this->buildSkillLevelThresholdByArray($row);
70 
71  $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
72 
73  $this->addThreshold($skillKey, $threshold->getSkillLevelId(), $threshold);
74  }
75  }
76 
77  private function addThreshold($skillKey, $skillLevelId, $threshold)
78  {
79  $this->thresholds[$skillKey][$skillLevelId] = $threshold;
80  }
81 
83  {
84  $threshold = new ilTestSkillLevelThreshold($this->db);
85 
86  $threshold->setTestId($data['test_fi']);
87  $threshold->setSkillBaseId($data['skill_base_fi']);
88  $threshold->setSkillTrefId($data['skill_tref_fi']);
89  $threshold->setSkillLevelId($data['skill_level_fi']);
90  $threshold->setThreshold($data['threshold']);
91 
92  return $threshold;
93  }
94 
95  public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId)
96  {
97  $skillKey = $skillBaseId . ':' . $skillTrefId;
98 
99  if( !isset($this->thresholds[$skillKey]) || !isset($this->thresholds[$skillKey][$skillLevelId]) )
100  {
101  return null;
102  }
103 
104  return $this->thresholds[$skillKey][$skillLevelId];
105  }
106 }
getThreshold($skillBaseId, $skillTrefId, $skillLevelId)
addThreshold($skillKey, $skillLevelId, $threshold)
Database Wrapper.
Definition: class.ilDB.php:28