ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestGradingMessageBuilder.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{
16 private $lng;
17
21 private $testOBJ;
22
26 private $tpl;
27
31 private $resultData;
32
36 private $activeId;
40 private $messageText = [];
46 {
47 $this->lng = $lng;
48 $this->testOBJ = $testOBJ;
49 }
50
51 public function setActiveId($activeId)
52 {
53 $this->activeId = $activeId;
54 }
55
56 public function getActiveId()
57 {
58 return $this->activeId;
59 }
60
61 public function buildMessage()
62 {
63 $this->loadResultData();
64
65 if ($this->testOBJ->isShowGradingStatusEnabled()) {
67 }
68
69 if ($this->testOBJ->isShowGradingMarkEnabled()) {
70 $this->addMessagePart($this->buildGradingMarkMsg());
71 }
72
73 if ($this->testOBJ->getECTSOutput()) {
74 $this->addMessagePart($this->buildEctsGradeMsg());
75 }
76 }
77
78 private function addMessagePart($msgPart)
79 {
80 $this->messageText[] = $msgPart;
81 }
82
83 private function getFullMessage()
84 {
85 return implode(' ', $this->messageText);
86 }
87
88 private function isPassed()
89 {
90 return (bool) $this->resultData['passed'];
91 }
92
93 public function sendMessage()
94 {
95 if (!$this->testOBJ->isShowGradingStatusEnabled()) {
97 } elseif ($this->isPassed()) {
98 ilUtil::sendSuccess($this->getFullMessage());
99 } else {
101 }
102 }
103
104 private function loadResultData()
105 {
106 $this->resultData = $this->testOBJ->getResultsForActiveId($this->getActiveId());
107
108 if ($this->testOBJ->getECTSOutput()) {
109 $ectsMark = $this->testOBJ->getECTSGrade(
110 $this->testOBJ->getTotalPointsPassedArray(),
111 $this->resultData['reached_points'],
112 $this->resultData['max_points']
113 );
114
115 $this->resultData['ects_grade'] = strtoupper($ectsMark);
116 }
117 }
118
119 private function buildGradingStatusMsg()
120 {
121 if ($this->isPassed()) {
122 return $this->lng->txt('grading_status_passed_msg');
123 }
124
125 return $this->lng->txt('grading_status_failed_msg');
126 }
127
128 private function buildGradingMarkMsg()
129 {
130 $markMsg = $this->lng->txt('grading_mark_msg');
131
132 $markMsg = str_replace("[mark]", $this->getMarkOfficial(), $markMsg);
133 $markMsg = str_replace("[markshort]", $this->getMarkShort(), $markMsg);
134 $markMsg = str_replace("[percentage]", $this->getPercentage(), $markMsg);
135 $markMsg = str_replace("[reached]", $this->getReachedPoints(), $markMsg);
136 $markMsg = str_replace("[max]", $this->getMaxPoints(), $markMsg);
137
138 return $markMsg;
139 }
140
141 private function getMarkOfficial()
142 {
143 return $this->resultData['mark_official'];
144 }
145
146 private function getMarkShort()
147 {
148 return $this->resultData['mark_short'];
149 }
150
151 private function getPercentage()
152 {
153 $percentage = 0;
154
155 if ($this->getMaxPoints() > 0) {
156 $percentage = $this->getReachedPoints() / $this->getMaxPoints();
157 }
158
159 return sprintf("%.2f", $percentage);
160 }
161
162 private function getReachedPoints()
163 {
164 return $this->resultData['reached_points'];
165 }
166
167 private function getMaxPoints()
168 {
169 return $this->resultData['max_points'];
170 }
171
172 private function areObligationsAnswered()
173 {
174 return (bool) $this->resultData['obligations_answered'];
175 }
176
177 private function buildEctsGradeMsg()
178 {
179 return str_replace('[markects]', $this->getEctsGrade(), $this->lng->txt('mark_tst_ects'));
180 }
181
182 private function getEctsGrade()
183 {
184 return $this->resultData['ects_grade'];
185 }
186
187 public function buildList()
188 {
189 $this->loadResultData();
190
191 $this->initListTemplate();
192
193 if ($this->testOBJ->isShowGradingStatusEnabled()) {
194 $passedStatusLangVar = $this->isPassed() ? 'passed_official' : 'failed_official';
195
196 $this->populateListEntry(
197 $this->lng->txt('passed_status'),
198 $this->lng->txt($passedStatusLangVar)
199 );
200 }
201
202 if ($this->testOBJ->areObligationsEnabled()) {
203 if ($this->areObligationsAnswered()) {
204 $obligAnsweredStatusLangVar = 'grading_obligations_answered_listentry';
205 } else {
206 $obligAnsweredStatusLangVar = 'grading_obligations_missing_listentry';
207 }
208
209 $this->populateListEntry(
210 $this->lng->txt('grading_obligations_listlabel'),
211 $this->lng->txt($obligAnsweredStatusLangVar)
212 );
213 }
214
215 if ($this->testOBJ->isShowGradingMarkEnabled()) {
216 $this->populateListEntry($this->lng->txt('tst_mark'), $this->getMarkOfficial());
217 }
218
219 if ($this->testOBJ->getECTSOutput()) {
220 $this->populateListEntry($this->lng->txt('ects_grade'), $this->getEctsGrade());
221 }
222
223 $this->parseListTemplate();
224 }
225
226 public function initListTemplate()
227 {
228 $this->tpl = new ilTemplate('tpl.tst_grading_msg_list.html', true, true, 'Modules/Test');
229 }
230
231 private function populateListEntry($label, $value)
232 {
233 $this->tpl->setCurrentBlock('grading_msg_entry');
234 $this->tpl->setVariable('LABEL', $label);
235 $this->tpl->setVariable('VALUE', $value);
236 $this->tpl->parseCurrentBlock();
237 }
238
239 private function parseListTemplate()
240 {
241 $this->tpl->setCurrentBlock('grading_msg_list');
242 $this->tpl->parseCurrentBlock();
243 }
244
245 public function getList()
246 {
247 return $this->tpl->get();
248 }
249}
An exception for terminatinating execution or to throw for unit testing.
language handling
special template class to simplify handling of ITX/PEAR
__construct(ilLanguage $lng, ilObjTest $testOBJ)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.