ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestQuestionRelatedObjectivesList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
33
38
39 public function __construct()
40 {
41 $this->objectivesByQuestion = [];
42 $this->objectivesTitles = [];
43 }
44
49 public function addQuestionRelatedObjectives($questionId, $objectiveIds)
50 {
51 $this->objectivesByQuestion[$questionId] = $objectiveIds;
52 }
53
58 public function hasQuestionRelatedObjectives($questionId): bool
59 {
60 if (!isset($this->objectivesByQuestion[$questionId])) {
61 return false;
62 }
63
64 return (bool) count($this->objectivesByQuestion[$questionId]);
65 }
66
70 public function getQuestionRelatedObjectives($questionId)
71 {
72 return $this->objectivesByQuestion[$questionId];
73 }
74
75 public function loadObjectivesTitles()
76 {
77 foreach ($this->objectivesByQuestion as $objectiveIds) {
78 foreach ($objectiveIds as $objectiveId) {
79 if (!isset($this->objectivesTitles[$objectiveId])) {
80 $objectiveTitle = ilCourseObjective::lookupObjectiveTitle($objectiveId);
81 $this->objectivesTitles[$objectiveId] = $objectiveTitle;
82 }
83 }
84 }
85 }
86
91 public function getQuestionRelatedObjectiveTitles($questionId): string
92 {
93 if (!isset($this->objectivesByQuestion[$questionId])
94 || !is_array($this->objectivesByQuestion[$questionId])) {
95 return '';
96 }
97
98 $titles = [];
99 foreach ($this->objectivesByQuestion[$questionId] as $objectiveId) {
100 $titles[] = $this->objectivesTitles[$objectiveId];
101 }
102
103 return implode(', ', $titles);
104 }
105
106 public function getUniqueObjectivesString(): string
107 {
108 return implode(', ', $this->objectivesTitles);
109 }
110
111 public function getUniqueObjectivesStringForQuestions($questionIds): string
112 {
113 $objectiveTitles = [];
114
115 foreach ($this->objectivesByQuestion as $questionId => $objectiveIds) {
116 if (!in_array($questionId, $questionIds)) {
117 continue;
118 }
119
120 foreach ($objectiveIds as $objectiveId) {
121 $objectiveTitles[$objectiveId] = $this->objectivesTitles[$objectiveId];
122 }
123 }
124
125 return implode(', ', $objectiveTitles);
126 }
127
128 public function getObjectiveTitleById($objectiveId)
129 {
130 return $this->objectivesTitles[$objectiveId];
131 }
132
133 public function getObjectives(): array
134 {
136 }
137
138 public function isQuestionRelatedToObjective($questionId, $objectiveId): bool
139 {
140 if (!isset($this->objectivesByQuestion[$questionId])
141 || !is_array($this->objectivesByQuestion[$questionId])) {
142 return false;
143 }
144
145 foreach ($this->objectivesByQuestion[$questionId] as $relatedObjectiveId) {
146 if ($relatedObjectiveId == $objectiveId) {
147 return true;
148 }
149 }
150
151 return false;
152 }
153
154 public function filterResultsByObjective($testResults, $objectiveId): array
155 {
156 $filteredResults = [];
157
158 foreach ($testResults as $questionId => $resultData) {
159 if (!$this->isQuestionRelatedToObjective($questionId, $objectiveId)) {
160 continue;
161 }
162
163 $filteredResults[$questionId] = $resultData;
164 }
165
166 return $filteredResults;
167 }
168}
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)