ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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(ilDBInterface $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  $this->addThreshold($threshold);
71  }
72  }
73 
76  public function saveToDb()
77  {
78  foreach($this->thresholds as $skillKey => $skillLevels)
79  {
80  foreach($skillLevels as $levelThreshold)
81  {
82  /* @var ilTestSkillLevelThreshold $levelThreshold */
83  $levelThreshold->saveToDb();
84  }
85  }
86  }
87 
91  public function addThreshold($threshold)
92  {
93  $skillKey = $threshold->getSkillBaseId().':'.$threshold->getSkillTrefId();
94  $this->thresholds[$skillKey][$threshold->getSkillLevelId()] = $threshold;
95  }
96 
102  {
103  $threshold = new ilTestSkillLevelThreshold($this->db);
104 
105  $threshold->setTestId($data['test_fi']);
106  $threshold->setSkillBaseId($data['skill_base_fi']);
107  $threshold->setSkillTrefId($data['skill_tref_fi']);
108  $threshold->setSkillLevelId($data['skill_level_fi']);
109  $threshold->setThreshold($data['threshold']);
110 
111  return $threshold;
112  }
113 
120  public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject = false)
121  {
122  $skillKey = $skillBaseId . ':' . $skillTrefId;
123 
124  if( isset($this->thresholds[$skillKey]) && isset($this->thresholds[$skillKey][$skillLevelId]) )
125  {
126  return $this->thresholds[$skillKey][$skillLevelId];
127  }
128 
129  if( $forceObject )
130  {
131  $threshold = new ilTestSkillLevelThreshold($this->db);
132 
133  $threshold->setTestId($this->getTestId());
134  $threshold->setSkillBaseId($skillBaseId);
135  $threshold->setSkillTrefId($skillTrefId);
136  $threshold->setSkillLevelId($skillLevelId);
137 
138  return $threshold;
139  }
140 
141  return null;
142  }
143 
144  public function cloneListForTest($testId)
145  {
146  foreach($this->thresholds as $skillKey => $data)
147  {
148  foreach($data as $levelId => $threshold)
149  {
150  /* @var ilTestSkillLevelThreshold $threshold */
151 
152  $threshold->setTestId($testId);
153  $threshold->saveToDb();
154 
155  $threshold->setTestId($this->getTestId());
156  }
157  }
158  }
159 }
getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject=false)
Interface ilDBInterface.
Create styles array
The data for the language used.