ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTestQuestionRelatedObjectivesList.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 {
17 
21  protected $objectivesTitles;
22 
23  public function __construct()
24  {
25  $this->objectivesByQuestion = array();
26  $this->objectivesTitles = array();
27  }
28 
33  public function addQuestionRelatedObjectives($questionId, $objectiveIds)
34  {
35  $this->objectivesByQuestion[$questionId] = $objectiveIds;
36  }
37 
42  public function hasQuestionRelatedObjectives($questionId)
43  {
44  if (!isset($this->objectivesByQuestion[$questionId])) {
45  return false;
46  }
47 
48  return (bool) count($this->objectivesByQuestion[$questionId]);
49  }
50 
55  public function getQuestionRelatedObjectives($questionId)
56  {
57  return $this->objectivesByQuestion[$questionId];
58  }
59 
60  public function loadObjectivesTitles()
61  {
62  require_once 'Modules/Course/classes/class.ilCourseObjective.php';
63 
64  foreach ($this->objectivesByQuestion as $objectiveIds) {
65  foreach ($objectiveIds as $objectiveId) {
66  if (!isset($this->objectivesTitles[$objectiveId])) {
67  $objectiveTitle = ilCourseObjective::lookupObjectiveTitle($objectiveId);
68  $this->objectivesTitles[$objectiveId] = $objectiveTitle;
69  }
70  }
71  }
72  }
73 
78  public function getQuestionRelatedObjectiveTitles($questionId)
79  {
80  $titles = array();
81 
82  foreach ((array) $this->objectivesByQuestion[$questionId] as $objectiveId) {
83  $titles[] = $this->objectivesTitles[$objectiveId];
84  }
85 
86  return implode(', ', $titles);
87  }
88 
89  public function getUniqueObjectivesString()
90  {
91  return implode(', ', $this->objectivesTitles);
92  }
93 
94  public function getUniqueObjectivesStringForQuestions($questionIds)
95  {
96  $objectiveTitles = array();
97 
98  foreach ($this->objectivesByQuestion as $questionId => $objectiveIds) {
99  if (!in_array($questionId, $questionIds)) {
100  continue;
101  }
102 
103  foreach ($objectiveIds as $objectiveId) {
104  $objectiveTitles[$objectiveId] = $this->objectivesTitles[$objectiveId];
105  }
106  }
107 
108  return implode(', ', $objectiveTitles);
109  }
110 
111  public function getObjectiveTitleById($objectiveId)
112  {
113  return $this->objectivesTitles[$objectiveId];
114  }
115 
116  public function getObjectives()
117  {
119  }
120 
121  public function isQuestionRelatedToObjective($questionId, $objectiveId)
122  {
123  foreach ($this->objectivesByQuestion[$questionId] as $relatedObjectiveId) {
124  if ($relatedObjectiveId == $objectiveId) {
125  return true;
126  }
127  }
128 
129  return false;
130  }
131 
132  public function filterResultsByObjective($testResults, $objectiveId)
133  {
134  $filteredResults = array();
135 
136  foreach ($testResults as $questionId => $resultData) {
137  if (!$this->isQuestionRelatedToObjective($questionId, $objectiveId)) {
138  continue;
139  }
140 
141  $filteredResults[$questionId] = $resultData;
142  }
143 
144  return $filteredResults;
145  }
146 }
static lookupObjectiveTitle($a_objective_id, $a_add_description=false)
Create styles array
The data for the language used.