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