ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionSkillAssignmentList.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/TestQuestionPool/classes/class.ilAssQuestionSkillAssignment.php';
5 
13 {
17  private $db;
18 
22  private $parentObjId;
23 
27  private $assignments;
28 
33 
38 
43 
44  public function __construct(ilDBInterface $db)
45  {
46  $this->db = $db;
47 
48  $this->parentObjId = null;
49  $this->assignments = array();
50  $this->numAssignsBySkill = array();
51  $this->maxPointsBySkill = array();
52  $this->questionIdFilter = null;
53  }
54 
58  public function setParentObjId($parentObjId)
59  {
60  $this->parentObjId = $parentObjId;
61  }
62 
66  public function getParentObjId()
67  {
68  return $this->parentObjId;
69  }
70 
74  public function getQuestionIdFilter()
75  {
77  }
78 
83  {
84  $this->questionIdFilter = $questionIdFilter;
85  }
86 
87  public function reset()
88  {
89  $this->assignments = array();
90  $this->numAssignsBySkill = array();
91  $this->maxPointsBySkill = array();
92  }
93 
94  public function addAssignment(ilAssQuestionSkillAssignment $assignment)
95  {
96  if( !isset($this->assignments[$assignment->getQuestionId()]) )
97  {
98  $this->assignments[$assignment->getQuestionId()] = array();
99  }
100 
101  $this->assignments[$assignment->getQuestionId()][] = $assignment;
102  }
103 
105  {
106  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
107 
108  if( !isset($this->numAssignsBySkill[$key]) )
109  {
110  $this->numAssignsBySkill[$key] = 0;
111  }
112 
113  $this->numAssignsBySkill[$key]++;
114  }
115 
117  {
118  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
119 
120  if( !isset($this->maxPointsBySkill[$key]) )
121  {
122  $this->maxPointsBySkill[$key] = 0;
123  }
124 
125  $this->maxPointsBySkill[$key] += $assignment->getMaxSkillPoints();
126  }
127 
128  public function loadFromDb()
129  {
130  $this->reset();
131 
132  $res = $this->db->query("
133  SELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode
134  FROM qpl_qst_skl_assigns
135  WHERE {$this->getWhereConditions()}
136  ");
137 
138  while( $row = $this->db->fetchAssoc($res) )
139  {
140  $assignment = $this->buildSkillQuestionAssignmentByArray($row);
141 
142  if( $assignment->hasEvalModeBySolution() )
143  {
144  $assignment->loadComparisonExpressions(); // db query
145  }
146 
147  $this->addAssignment($assignment);
148  $this->incrementNumAssignsBySkill($assignment);
149  $this->incrementMaxPointsBySkill($assignment);
150  }
151  }
152 
153  private function getWhereConditions()
154  {
155  $conditions = array(
156  'obj_fi = '.$this->db->quote($this->getParentObjId(), 'integer')
157  );
158 
159  if( $this->getQuestionIdFilter() )
160  {
161  $conditions[] = 'question_fi = '.$this->db->quote($this->getQuestionIdFilter(), 'integer');
162  }
163 
164  return implode(' AND ', $conditions);
165  }
166 
172  {
173  $assignment = new ilAssQuestionSkillAssignment($this->db);
174 
175  $assignment->setParentObjId($data['obj_fi']);
176  $assignment->setQuestionId($data['question_fi']);
177  $assignment->setSkillBaseId($data['skill_base_fi']);
178  $assignment->setSkillTrefId($data['skill_tref_fi']);
179  $assignment->setSkillPoints($data['skill_points']);
180  $assignment->setEvalMode($data['eval_mode']);
181 
182  return $assignment;
183  }
184 
185  private function buildSkillKey($skillBaseId, $skillTrefId)
186  {
187  return $skillBaseId.':'.$skillTrefId;
188  }
189 
190  public function loadAdditionalSkillData()
191  {
192  foreach($this->assignments as $assignmentsByQuestion)
193  {
194  foreach($assignmentsByQuestion as $assignment)
195  {
196  $assignment->loadAdditionalSkillData();
197  }
198  }
199  }
200 
201  public function getAssignmentsByQuestionId($questionId)
202  {
203  if( !isset($this->assignments[$questionId]) )
204  {
205  return array();
206  }
207 
208  return $this->assignments[$questionId];
209  }
210 
211  public function isAssignedToQuestionId($skillBaseId, $skillTrefId, $questionId)
212  {
213  if( !isset($this->assignments[$questionId]) )
214  {
215  return false;
216  }
217 
218  foreach($this->assignments[$questionId] as $assignment)
219  {
220  if( $assignment->getSkillBaseId() != $skillBaseId )
221  {
222  continue;
223  }
224 
225  if( $assignment->getSkillTrefId() != $skillTrefId )
226  {
227  continue;
228  }
229 
230  return true;
231  }
232 
233  return false;
234  }
235 
236  public function getUniqueAssignedSkills()
237  {
238  require_once 'Services/Skill/classes/class.ilBasicSkill.php';
239 
240  $skills = array();
241 
242  foreach($this->assignments as $assignmentsByQuestion)
243  {
244  foreach($assignmentsByQuestion as $assignment)
245  {
246  /* @var ilAssQuestionSkillAssignment $assignment */
247 
248  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
249 
250  if( !isset($skills[$key]) )
251  {
252  $skills[$key] = array(
253  'skill' => new ilBasicSkill($assignment->getSkillBaseId()),
254  'skill_base_id' => $assignment->getSkillBaseId(),
255  'skill_tref_id' => $assignment->getSkillTrefId(),
256  'skill_title' => $assignment->getSkillTitle(),
257  'skill_path' => $assignment->getSkillPath(),
258  'num_assigns' => $this->getNumAssignsBySkill(
259  $assignment->getSkillBaseId(), $assignment->getSkillTrefId()
260  ),
261  'max_points' => $this->getMaxPointsBySkill(
262  $assignment->getSkillBaseId(), $assignment->getSkillTrefId()
263  )
264  );
265  }
266  }
267  }
268 
269  return $skills;
270  }
271 
272  public function isAssignedSkill($skillBaseId, $skillTrefId)
273  {
274  foreach($this->getUniqueAssignedSkills() as $assignedSkill)
275  {
276  if( $assignedSkill['skill_base_id'] != $skillBaseId )
277  {
278  continue;
279  }
280 
281  if( $assignedSkill['skill_tref_id'] == $skillTrefId )
282  {
283  return true;
284  }
285  }
286 
287  return false;
288  }
289 
290  public function getNumAssignsBySkill($skillBaseId, $skillTrefId)
291  {
292  return $this->numAssignsBySkill[$this->buildSkillKey($skillBaseId, $skillTrefId)];
293  }
294 
295  public function getMaxPointsBySkill($skillBaseId, $skillTrefId)
296  {
297  return $this->maxPointsBySkill[$this->buildSkillKey($skillBaseId, $skillTrefId)];
298  }
299 
301  {
302  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
304 
305  foreach($this->getUniqueAssignedSkills() as $skillData)
306  {
307  if( $skillData['num_assigns'] < $globalBarrier )
308  {
309  return true;
310  }
311  }
312 
313  return false;
314  }
315 }
incrementMaxPointsBySkill(ilAssQuestionSkillAssignment $assignment)
Interface ilDBInterface.
addAssignment(ilAssQuestionSkillAssignment $assignment)
Create styles array
The data for the language used.
Basic Skill.
isAssignedToQuestionId($skillBaseId, $skillTrefId, $questionId)
incrementNumAssignsBySkill(ilAssQuestionSkillAssignment $assignment)