ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestSkillQuestionAssignment.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 {
14 
18  private $db;
19 
23  private $testId;
24 
28  private $questionId;
29 
33  private $skillBaseId;
34 
38  private $skillTrefId;
39 
43  private $skillPoints;
44 
48  private $skillTitle;
49 
53  private $skillPath;
54 
55 
56  public function __construct(ilDB $db)
57  {
58  $this->db = $db;
59  }
60 
61  public function loadFromDb()
62  {
63  $query = "
64  SELECT test_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points
65  FROM tst_skl_qst_assigns
66  WHERE test_fi = %s
67  AND question_fi = %s
68  AND skill_base_fi = %s
69  AND skill_tref_fi = %s
70  ";
71 
72  $res = $this->db->queryF(
73  $query, array('integer', 'integer', 'integer', 'integer'),
74  array($this->getTestId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
75  );
76 
77  $row = $this->db->fetchAssoc($res);
78 
79  if( is_array($row) )
80  {
81  $this->setSkillPoints($row['skill_points']);
82  }
83  }
84 
85  public function saveToDb()
86  {
87  if( $this->dbRecordExists() )
88  {
89  $this->db->update('tst_skl_qst_assigns', array(
90  'skill_points' => array('integer', $this->getSkillPoints())
91  ),
92  array(
93  'test_fi' => array('integer', $this->getTestId()),
94  'question_fi' => array('integer', $this->getQuestionId()),
95  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
96  'skill_tref_fi' => array('integer', $this->getSkillTrefId())
97  )
98  );
99  }
100  else
101  {
102  $this->db->insert('tst_skl_qst_assigns', array(
103  'test_fi' => array('integer', $this->getTestId()),
104  'question_fi' => array('integer', $this->getQuestionId()),
105  'skill_base_fi' => array('integer', $this->getSkillBaseId()),
106  'skill_tref_fi' => array('integer', $this->getSkillTrefId()),
107  'skill_points' => array('integer', $this->getSkillPoints())
108  ));
109  }
110  }
111 
112  public function deleteFromDb()
113  {
114  $query = "
115  DELETE FROM tst_skl_qst_assigns
116  WHERE test_fi = %s
117  AND question_fi = %s
118  AND skill_base_fi = %s
119  AND skill_tref_fi = %s
120  ";
121 
122  $this->db->manipulateF(
123  $query, array('integer', 'integer', 'integer', 'integer'),
124  array($this->getTestId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
125  );
126  }
127 
128  public function dbRecordExists()
129  {
130  $query = "
131  SELECT COUNT(*) cnt
132  FROM tst_skl_qst_assigns
133  WHERE test_fi = %s
134  AND question_fi = %s
135  AND skill_base_fi = %s
136  AND skill_tref_fi = %s
137  ";
138 
139  $res = $this->db->queryF(
140  $query, array('integer', 'integer', 'integer', 'integer'),
141  array($this->getTestId(), $this->getQuestionId(), $this->getSkillBaseId(), $this->getSkillTrefId())
142  );
143 
144  $row = $this->db->fetchAssoc($res);
145 
146  return $row['cnt'] > 0;
147  }
148 
152  public function setSkillPoints($skillPoints)
153  {
154  $this->skillPoints = $skillPoints;
155  }
156 
160  public function getSkillPoints()
161  {
162  return $this->skillPoints;
163  }
164 
168  public function setQuestionId($questionId)
169  {
170  $this->questionId = $questionId;
171  }
172 
176  public function getQuestionId()
177  {
178  return $this->questionId;
179  }
180 
184  public function setSkillBaseId($skillBaseId)
185  {
186  $this->skillBaseId = $skillBaseId;
187  }
188 
192  public function getSkillBaseId()
193  {
194  return $this->skillBaseId;
195  }
196 
200  public function setSkillTrefId($skillTrefId)
201  {
202  $this->skillTrefId = $skillTrefId;
203  }
204 
208  public function getSkillTrefId()
209  {
210  return $this->skillTrefId;
211  }
212 
216  public function setTestId($testId)
217  {
218  $this->testId = $testId;
219  }
220 
224  public function getTestId()
225  {
226  return $this->testId;
227  }
228 
229  public function loadAdditionalSkillData()
230  {
231  require_once 'Services/Skill/classes/class.ilBasicSkill.php';
232  require_once 'Services/Skill/classes/class.ilSkillTree.php';
233 
234  $this->setSkillTitle(
236  );
237 
238  $tree = new ilSkillTree();
239 
240  $path = $tree->getSkillTreePath(
241  $this->getSkillBaseId(), $this->getSkillTrefId()
242  );
243 
244  $nodes = array();
245  foreach ($path as $node)
246  {
247  if( $node['child'] > 1 && $node['skill_id'] != $this->getSkillBaseId() )
248  {
249  $nodes[] = $node['title'];
250  }
251  }
252 
253  $this->setSkillPath(implode(' > ', $nodes));
254  }
255 
256  public function setSkillTitle($skillTitle)
257  {
258  $this->skillTitle = $skillTitle;
259  }
260 
261  public function getSkillTitle()
262  {
263  return $this->skillTitle;
264  }
265 
266  public function setSkillPath($skillPath)
267  {
268  $this->skillPath = $skillPath;
269  }
270 
271  public function getSkillPath()
272  {
273  return $this->skillPath;
274  }
275 }