ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  $this->assignments[$assignment->getQuestionId()] = array();
98  }
99 
100  $this->assignments[$assignment->getQuestionId()][] = $assignment;
101  }
102 
104  {
105  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
106 
107  if (!isset($this->numAssignsBySkill[$key])) {
108  $this->numAssignsBySkill[$key] = 0;
109  }
110 
111  $this->numAssignsBySkill[$key]++;
112  }
113 
115  {
116  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
117 
118  if (!isset($this->maxPointsBySkill[$key])) {
119  $this->maxPointsBySkill[$key] = 0;
120  }
121 
122  $this->maxPointsBySkill[$key] += $assignment->getMaxSkillPoints();
123  }
124 
125  public function loadFromDb()
126  {
127  $this->reset();
128 
129  $res = $this->db->query("
130  SELECT obj_fi, question_fi, skill_base_fi, skill_tref_fi, skill_points, eval_mode
131  FROM qpl_qst_skl_assigns
132  WHERE {$this->getWhereConditions()}
133  ");
134 
135  while ($row = $this->db->fetchAssoc($res)) {
136  $assignment = $this->buildSkillQuestionAssignmentByArray($row);
137 
138  if ($assignment->hasEvalModeBySolution()) {
139  $assignment->loadComparisonExpressions(); // db query
140  }
141 
142  $this->addAssignment($assignment);
143  $this->incrementNumAssignsBySkill($assignment);
144  $this->incrementMaxPointsBySkill($assignment);
145  }
146  }
147 
148  private function getWhereConditions()
149  {
150  $conditions = array(
151  'obj_fi = ' . $this->db->quote($this->getParentObjId(), 'integer')
152  );
153 
154  if ($this->getQuestionIdFilter()) {
155  $conditions[] = 'question_fi = ' . $this->db->quote($this->getQuestionIdFilter(), 'integer');
156  }
157 
158  return implode(' AND ', $conditions);
159  }
160 
166  {
167  $assignment = new ilAssQuestionSkillAssignment($this->db);
168 
169  $assignment->setParentObjId($data['obj_fi']);
170  $assignment->setQuestionId($data['question_fi']);
171  $assignment->setSkillBaseId($data['skill_base_fi']);
172  $assignment->setSkillTrefId($data['skill_tref_fi']);
173  $assignment->setSkillPoints($data['skill_points']);
174  $assignment->setEvalMode($data['eval_mode']);
175 
176  return $assignment;
177  }
178 
179  private function buildSkillKey($skillBaseId, $skillTrefId)
180  {
181  return $skillBaseId . ':' . $skillTrefId;
182  }
183 
184  public function loadAdditionalSkillData()
185  {
186  foreach ($this->assignments as $assignmentsByQuestion) {
187  foreach ($assignmentsByQuestion as $assignment) {
188  $assignment->loadAdditionalSkillData();
189  }
190  }
191  }
192 
193  public function getAssignmentsByQuestionId($questionId)
194  {
195  if (!isset($this->assignments[$questionId])) {
196  return array();
197  }
198 
199  return $this->assignments[$questionId];
200  }
201 
202  public function isAssignedToQuestionId($skillBaseId, $skillTrefId, $questionId)
203  {
204  if (!isset($this->assignments[$questionId])) {
205  return false;
206  }
207 
208  foreach ($this->assignments[$questionId] as $assignment) {
209  if ($assignment->getSkillBaseId() != $skillBaseId) {
210  continue;
211  }
212 
213  if ($assignment->getSkillTrefId() != $skillTrefId) {
214  continue;
215  }
216 
217  return true;
218  }
219 
220  return false;
221  }
222 
223  public function getUniqueAssignedSkills()
224  {
225  require_once 'Services/Skill/classes/class.ilBasicSkill.php';
226 
227  $skills = array();
228 
229  foreach ($this->assignments as $assignmentsByQuestion) {
230  foreach ($assignmentsByQuestion as $assignment) {
231  /* @var ilAssQuestionSkillAssignment $assignment */
232 
233  $key = $this->buildSkillKey($assignment->getSkillBaseId(), $assignment->getSkillTrefId());
234 
235  if (!isset($skills[$key])) {
236  $skills[$key] = array(
237  'skill' => new ilBasicSkill($assignment->getSkillBaseId()),
238  'skill_base_id' => $assignment->getSkillBaseId(),
239  'skill_tref_id' => $assignment->getSkillTrefId(),
240  'skill_title' => $assignment->getSkillTitle(),
241  'skill_path' => $assignment->getSkillPath(),
242  'num_assigns' => $this->getNumAssignsBySkill(
243  $assignment->getSkillBaseId(),
244  $assignment->getSkillTrefId()
245  ),
246  'max_points' => $this->getMaxPointsBySkill(
247  $assignment->getSkillBaseId(),
248  $assignment->getSkillTrefId()
249  )
250  );
251  }
252  }
253  }
254 
255  return $skills;
256  }
257 
258  public function isAssignedSkill($skillBaseId, $skillTrefId)
259  {
260  foreach ($this->getUniqueAssignedSkills() as $assignedSkill) {
261  if ($assignedSkill['skill_base_id'] != $skillBaseId) {
262  continue;
263  }
264 
265  if ($assignedSkill['skill_tref_id'] == $skillTrefId) {
266  return true;
267  }
268  }
269 
270  return false;
271  }
272 
273  public function getNumAssignsBySkill($skillBaseId, $skillTrefId)
274  {
275  return $this->numAssignsBySkill[$this->buildSkillKey($skillBaseId, $skillTrefId)];
276  }
277 
278  public function getMaxPointsBySkill($skillBaseId, $skillTrefId)
279  {
280  return $this->maxPointsBySkill[$this->buildSkillKey($skillBaseId, $skillTrefId)];
281  }
282 
284  {
285  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
287 
288  foreach ($this->getUniqueAssignedSkills() as $skillData) {
289  if ($skillData['num_assigns'] < $globalBarrier) {
290  return true;
291  }
292  }
293 
294  return false;
295  }
296 }
incrementMaxPointsBySkill(ilAssQuestionSkillAssignment $assignment)
Interface ilDBInterface.
addAssignment(ilAssQuestionSkillAssignment $assignment)
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
Basic Skill.
$key
Definition: croninfo.php:18
isAssignedToQuestionId($skillBaseId, $skillTrefId, $questionId)
incrementNumAssignsBySkill(ilAssQuestionSkillAssignment $assignment)