ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestEvaluationData.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
23 
29  private $test;
30 
36  public $participants;
37 
43  public $statistics;
44 
50  public $arrFilter;
51 
56  public $datasets;
57 
62 
63  public function __sleep()
64  {
65  return array('questionTitles', 'participants', 'statistics', 'arrFilter', 'datasets', 'test');
66  }
67 
73  public function __construct(ilObjTest $test = null)
74  {
75  $this->participants = array();
76  $this->questionTitles = array();
77  if ($test !== null) {
78  $this->test = $test;
79 
80  if ($this->getTest()->getAccessFilteredParticipantList()) {
83  );
84  }
85 
86  $this->generateOverview();
87  }
88  }
89 
94  {
96  }
97 
102  {
103  $this->accessFilteredParticipantList = $accessFilteredParticipantList;
104  }
105 
106  protected function checkParticipantAccess($activeId)
107  {
108  if ($this->getAccessFilteredParticipantList() === null) {
109  return true;
110  }
111 
112  return $this->getAccessFilteredParticipantList()->isActiveIdInList($activeId);
113  }
114 
115  protected function loadRows()
116  {
117  global $DIC; /* @var ILIAS\DI\Container $DIC */
118 
119  $query = "
120  SELECT usr_data.usr_id,
121  usr_data.firstname,
122  usr_data.lastname,
123  usr_data.title,
124  usr_data.login,
125  tst_pass_result.*,
126  tst_active.submitted
127  FROM tst_pass_result, tst_active
128  LEFT JOIN usr_data
129  ON tst_active.user_fi = usr_data.usr_id
130  WHERE tst_active.active_id = tst_pass_result.active_fi
131  AND tst_active.test_fi = %s
132  ORDER BY usr_data.lastname,
133  usr_data.firstname,
134  tst_pass_result.active_fi,
135  tst_pass_result.pass,
136  tst_pass_result.tstamp
137  ";
138 
139  $result = $DIC->database()->queryF(
140  $query,
141  array('integer'),
142  array($this->getTest()->getTestId())
143  );
144 
145  $rows = array();
146 
147  while ($row = $DIC->database()->fetchAssoc($result)) {
148  if (!$this->checkParticipantAccess($row['active_fi'])) {
149  continue;
150  }
151 
152  $rows[] = $row;
153  }
154 
155  return $rows;
156  }
157 
158  public function generateOverview()
159  {
160  include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
161  include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
162 
163  $this->participants = array();
164 
165  $pass = null;
166  $checked = array();
167  $thissets = 0;
168 
169  foreach ($this->loadRows() as $row) {
170  $thissets++;
171 
172  $remove = false;
173 
174  if (!$this->participantExists($row["active_fi"])) {
175  $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
176 
177  $this->getParticipant($row["active_fi"])->setName(
178  $this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"])
179  );
180 
181  $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
182 
183  $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
184 
185  $this->getParticipant($row["active_fi"])->setSubmitted($row['submitted']);
186  }
187 
188  if (!is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"]))) {
190  $pass->setPass($row["pass"]);
191  $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
192  }
193 
194  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints($row["points"]);
195  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setObligationsAnswered($row["obligations_answered"]);
196 
197  if ($row["questioncount"] == 0) {
198  $data = ilObjTest::_getQuestionCountAndPointsForPassOfParticipant($row['active_fi'], $row['pass']);
199  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
200  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
201  } else {
202  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
203  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
204  }
205 
206  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
207  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
208  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setExamId((string) $row["exam_id"]);
209 
210  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setRequestedHintsCount($row['hint_count']);
211  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setDeductedHintPoints($row['hint_points']);
212  }
213  }
214 
215  public function getTest()
216  {
217  return $this->test;
218  }
219 
220  public function setTest($test)
221  {
222  $this->test = &$test;
223  }
224 
225  public function setDatasets($datasets)
226  {
227  $this->datasets = $datasets;
228  }
229 
230  public function getDatasets()
231  {
232  return $this->datasets;
233  }
234 
235  public function addQuestionTitle($question_id, $question_title)
236  {
237  $this->questionTitles[$question_id] = $question_title;
238  }
239 
240  public function getQuestionTitles()
241  {
242  return $this->questionTitles;
243  }
244 
245  public function getQuestionTitle($question_id)
246  {
247  if (array_key_exists($question_id, $this->questionTitles)) {
248  return $this->questionTitles[$question_id];
249  } else {
250  return "";
251  }
252  }
253 
254  public function calculateStatistics()
255  {
256  include_once "./Modules/Test/classes/class.ilTestStatistics.php";
257  $this->statistics = new ilTestStatistics($this);
258  }
259 
261  {
262  $finishedParticipants = 0;
263 
264  foreach ($this->participants as $active_id => $participant) {
265  if (!$participant->isSubmitted()) {
266  continue;
267  }
268 
269  $finishedParticipants++;
270  }
271 
272  return $finishedParticipants;
273  }
274 
275  public function getParticipants()
276  {
277  if (is_array($this->arrFilter) && count($this->arrFilter) > 0) {
278  $filteredParticipants = array();
279  $courseids = array();
280  $groupids = array();
281  global $DIC;
282  $ilDB = $DIC['ilDB'];
283  if (array_key_exists('group', $this->arrFilter)) {
284  $ids = ilObject::_getIdsForTitle($this->arrFilter['group'], 'grp', true);
285  $groupids = array_merge($groupids, $ids);
286  }
287  if (array_key_exists('course', $this->arrFilter)) {
288  $ids = ilObject::_getIdsForTitle($this->arrFilter['course'], 'crs', true);
289  $courseids = array_merge($courseids, $ids);
290  }
291  foreach ($this->participants as $active_id => $participant) {
292  $remove = false;
293  if (array_key_exists('name', $this->arrFilter)) {
294  if (!(strpos(strtolower($participant->getName()), strtolower($this->arrFilter['name'])) !== false)) {
295  $remove = true;
296  }
297  }
298  if (!$remove) {
299  if (array_key_exists('group', $this->arrFilter)) {
300  include_once "./Services/Membership/classes/class.ilParticipants.php";
301  $groups = ilParticipants::_getMembershipByType($participant->getUserID(), "grp");
302  $foundfilter = false;
303  if (count(array_intersect($groupids, $groups))) {
304  $foundfilter = true;
305  }
306  if (!$foundfilter) {
307  $remove = true;
308  }
309  }
310  }
311  if (!$remove) {
312  if (array_key_exists('course', $this->arrFilter)) {
313  include_once "./Services/Membership/classes/class.ilParticipants.php";
314  $courses = ilParticipants::_getMembershipByType($participant->getUserID(), "crs");
315  $foundfilter = false;
316  if (count(array_intersect($courseids, $courses))) {
317  $foundfilter = true;
318  }
319  if (!$foundfilter) {
320  $remove = true;
321  }
322  }
323  }
324  if (!$remove) {
325  if (array_key_exists('active_id', $this->arrFilter)) {
326  if ($active_id != $this->arrFilter['active_id']) {
327  $remove = true;
328  }
329  }
330  }
331  if (!$remove) {
332  $filteredParticipants[$active_id] = $participant;
333  }
334  }
335  return $filteredParticipants;
336  } else {
337  return $this->participants;
338  }
339  }
340 
341  public function resetFilter()
342  {
343  $this->arrFilter = array();
344  }
345 
346  /*
347  * Set an output filter for getParticipants
348  *
349  * @param string $by name, course, group
350  * @param string $text Filter text
351  */
352  public function setFilter($by, $text)
353  {
354  $this->arrFilter = array($by => $text);
355  }
356 
357  /*
358  * Set an output filter for getParticipants
359  *
360  * @param array $arrFilter filter values
361  */
362  public function setFilterArray($arrFilter)
363  {
364  $this->arrFilter = $arrFilter;
365  }
366 
367  public function addParticipant($active_id, $participant)
368  {
369  $this->participants[$active_id] = $participant;
370  }
371 
376  public function getParticipant($active_id)
377  {
378  return $this->participants[$active_id];
379  }
380 
381  public function participantExists($active_id)
382  {
383  return array_key_exists($active_id, $this->participants);
384  }
385 
386  public function removeParticipant($active_id)
387  {
388  unset($this->participants[$active_id]);
389  }
390 
391  public function getStatistics()
392  {
393  return $this->statistics;
394  }
395 
396  public function getParticipantIds()
397  {
398  return array_keys($this->participants);
399  }
400 } // END ilTestEvaluationData
$result
global $DIC
Definition: saml.php:7
addQuestionTitle($question_id, $question_title)
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
setAccessFilteredParticipantList($accessFilteredParticipantList)
__construct(ilObjTest $test=null)
Constructor.
static _getQuestionCountAndPointsForPassOfParticipant($active_id, $pass)
$text
Definition: errorreport.php:18
This class calculates statistical data for a test which has to be calculated using all participant da...
$query
test()
Definition: build.php:107
addParticipant($active_id, $participant)
$row
$rows
Definition: xhr_table.php:10
global $ilDB
static _getIdsForTitle($title, $type='', $partialmatch=false)
$data
Definition: bench.php:6