ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 build()
59  {
60  $this->initTemplate();
61 
62  $this->loadResultData();
63 
64  if( $this->testOBJ->isShowGradingStatusEnabled() )
65  {
66  $this->populateGradingStatus();
67  }
68 
69  if( $this->testOBJ->areObligationsEnabled() )
70  {
72  }
73 
74  if( $this->testOBJ->isShowGradingMarkEnabled() )
75  {
76  $this->populateGradingMark();
77  }
78 
79  if( $this->testOBJ->getECTSOutput() )
80  {
81  $this->populateEctsGrade();
82  }
83  }
84 
85  public function getMessage()
86  {
87  return $this->tpl->get();
88  }
89 
90  private function initTemplate()
91  {
92  $this->tpl = new ilTemplate('tpl.tst_grading_message.html', true, true, 'Modules/Test');
93  }
94 
95  private function loadResultData()
96  {
97  $this->resultData = $this->testOBJ->getResultsForActiveId($this->getActiveId());
98 
99  if( $this->testOBJ->getECTSOutput() )
100  {
101  $ectsMark = $this->testOBJ->getECTSGrade(
102  $this->testOBJ->getTotalPointsPassedArray(),
103  $this->resultData['reached_points'],
104  $this->resultData['max_points']
105  );
106 
107  $this->resultData['ects_grade'] = strtoupper($ectsMark);
108  }
109  }
110 
111  private function populateGradingStatus()
112  {
113  $this->tpl->setCurrentBlock('status_css_class');
114  $this->tpl->setVariable('STATUS_CSS_CLASS', $this->getGradingStatusCssClass());
115  $this->tpl->parseCurrentBlock();
116 
117  $this->tpl->setCurrentBlock('grading_status_msg');
118  $this->tpl->setVariable('GRADING_STATUS_MSG', $this->buildGradingStatusMsg());
119  $this->tpl->parseCurrentBlock();
120  }
121 
122  private function getGradingStatusCssClass()
123  {
124  if( $this->isPassed() )
125  {
126  return 'passed';
127  }
128 
129  return 'failed';
130  }
131 
132  private function buildGradingStatusMsg()
133  {
134  if( $this->isPassed() )
135  {
136  return $this->lng->txt('grading_status_passed_msg');
137  }
138 
139  return $this->lng->txt('grading_status_failed_msg');
140  }
141 
142  private function isPassed()
143  {
144  return (bool)$this->resultData['passed'];
145  }
146 
147  private function populateGradingMark()
148  {
149  $this->tpl->setCurrentBlock('grading_mark_msg');
150  $this->tpl->setVariable('GRADING_MARK_MSG', $this->buildGradingMarkMsg());
151  $this->tpl->parseCurrentBlock();
152  }
153 
154  private function buildGradingMarkMsg()
155  {
156  $markMsg = $this->lng->txt('grading_mark_msg');
157 
158  $markMsg = str_replace("[mark]", $this->getMarkOfficial(), $markMsg);
159  $markMsg = str_replace("[markshort]", $this->getMarkShort(), $markMsg);
160  $markMsg = str_replace("[percentage]", $this->getPercentage(), $markMsg);
161  $markMsg = str_replace("[reached]", $this->getReachedPoints(), $markMsg);
162  $markMsg = str_replace("[max]", $this->getMaxPoints(), $markMsg);
163 
164  return $markMsg;
165  }
166 
167  private function getMarkOfficial()
168  {
169  return $this->resultData['mark_official'];
170  }
171 
172  private function getMarkShort()
173  {
174  return $this->resultData['mark_short'];
175  }
176 
177  private function getPercentage()
178  {
179  $percentage = 0;
180 
181  if( $this->getMaxPoints() > 0 )
182  {
183  $percentage = $this->getReachedPoints() / $this->getMaxPoints();
184  }
185 
186  return sprintf("%.2f", $percentage);
187  }
188 
189  private function getReachedPoints()
190  {
191  return $this->resultData['reached_points'];
192  }
193 
194  private function getMaxPoints()
195  {
196  return $this->resultData['max_points'];
197  }
198 
199  private function populateObligationsStatus()
200  {
201  $this->tpl->setCurrentBlock('obligations_msg');
202  $this->tpl->setVariable('OBLIGATIONS_MSG', $this->buildObligationsMsg());
203  $this->tpl->parseCurrentBlock();
204  }
205 
206  private function buildObligationsMsg()
207  {
208  if( $this->areObligationsAnswered() )
209  {
210  return $this->lng->txt('grading_obligations_answered_msg');
211  }
212 
213  return $this->lng->txt('grading_obligations_missing_msg');
214  }
215 
216  private function areObligationsAnswered()
217  {
218  return (bool)$this->resultData['obligations_answered'];
219  }
220 
221  private function populateEctsGrade()
222  {
223  $this->tpl->setCurrentBlock('grading_mark_ects_msg');
224  $this->tpl->setVariable('GRADING_MARK_ECTS_MSG', $this->buildEctsGradeMsg());
225  $this->tpl->parseCurrentBlock();
226  }
227 
228  private function buildEctsGradeMsg()
229  {
230  return str_replace('[markects]', $this->getEctsGrade(), $this->lng->txt('mark_tst_ects'));
231  }
232 
233  private function getEctsGrade()
234  {
235  return $this->resultData['ects_grade'];
236  }
237 }
__construct(ilLanguage $lng, ilObjTest $testOBJ)
special template class to simplify handling of ITX/PEAR
language handling