ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $threshold = $this->buildSkillLevelThresholdByArray($row);
69  $this->addThreshold($threshold);
70  }
71  }
72 
75  public function saveToDb()
76  {
77  foreach ($this->thresholds as $skillKey => $skillLevels) {
78  foreach ($skillLevels as $levelThreshold) {
79  /* @var ilTestSkillLevelThreshold $levelThreshold */
80  $levelThreshold->saveToDb();
81  }
82  }
83  }
84 
88  public function addThreshold($threshold)
89  {
90  $skillKey = $threshold->getSkillBaseId() . ':' . $threshold->getSkillTrefId();
91  $this->thresholds[$skillKey][$threshold->getSkillLevelId()] = $threshold;
92  }
93 
99  {
100  $threshold = new ilTestSkillLevelThreshold($this->db);
101 
102  $threshold->setTestId($data['test_fi']);
103  $threshold->setSkillBaseId($data['skill_base_fi']);
104  $threshold->setSkillTrefId($data['skill_tref_fi']);
105  $threshold->setSkillLevelId($data['skill_level_fi']);
106  $threshold->setThreshold($data['threshold']);
107 
108  return $threshold;
109  }
110 
117  public function getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject = false)
118  {
119  $skillKey = $skillBaseId . ':' . $skillTrefId;
120 
121  if (isset($this->thresholds[$skillKey]) && isset($this->thresholds[$skillKey][$skillLevelId])) {
122  return $this->thresholds[$skillKey][$skillLevelId];
123  }
124 
125  if ($forceObject) {
126  $threshold = new ilTestSkillLevelThreshold($this->db);
127 
128  $threshold->setTestId($this->getTestId());
129  $threshold->setSkillBaseId($skillBaseId);
130  $threshold->setSkillTrefId($skillTrefId);
131  $threshold->setSkillLevelId($skillLevelId);
132 
133  return $threshold;
134  }
135 
136  return null;
137  }
138 
139  public function cloneListForTest($testId)
140  {
141  foreach ($this->thresholds as $skillKey => $data) {
142  foreach ($data as $levelId => $threshold) {
143  /* @var ilTestSkillLevelThreshold $threshold */
144 
145  $threshold->setTestId($testId);
146  $threshold->saveToDb();
147 
148  $threshold->setTestId($this->getTestId());
149  }
150  }
151  }
152 }
getThreshold($skillBaseId, $skillTrefId, $skillLevelId, $forceObject=false)
Interface ilDBInterface.
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.