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