ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  tst_active.last_finished_pass
128  FROM tst_pass_result, tst_active
129  LEFT JOIN usr_data
130  ON tst_active.user_fi = usr_data.usr_id
131  WHERE tst_active.active_id = tst_pass_result.active_fi
132  AND tst_active.test_fi = %s
133  ORDER BY usr_data.lastname,
134  usr_data.firstname,
135  tst_pass_result.active_fi,
136  tst_pass_result.pass,
137  tst_pass_result.tstamp
138  ";
139 
140  $result = $DIC->database()->queryF(
141  $query,
142  array('integer'),
143  array($this->getTest()->getTestId())
144  );
145 
146  $rows = array();
147 
148  while ($row = $DIC->database()->fetchAssoc($result)) {
149  if (!$this->checkParticipantAccess($row['active_fi'])) {
150  continue;
151  }
152 
153  $rows[] = $row;
154  }
155 
156  return $rows;
157  }
158 
159  public function generateOverview()
160  {
161  include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
162  include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
163 
164  $this->participants = array();
165 
166  $pass = null;
167  $checked = array();
168  $thissets = 0;
169 
170  foreach ($this->loadRows() as $row) {
171  $thissets++;
172 
173  $remove = false;
174 
175  if (!$this->participantExists($row["active_fi"])) {
176  $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
177 
178  $this->getParticipant($row["active_fi"])->setName(
179  $this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"])
180  );
181 
182  $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
183 
184  $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
185 
186  $this->getParticipant($row["active_fi"])->setSubmitted($row['submitted']);
187 
188  $this->getParticipant($row["active_fi"])->setLastFinishedPass($row['last_finished_pass']);
189  }
190 
191  if (!is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"]))) {
193  $pass->setPass($row["pass"]);
194  $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
195  }
196 
197  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints($row["points"]);
198  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setObligationsAnswered($row["obligations_answered"]);
199 
200  if ($row["questioncount"] == 0) {
201  $data = ilObjTest::_getQuestionCountAndPointsForPassOfParticipant($row['active_fi'], $row['pass']);
202  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
203  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
204  } else {
205  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
206  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
207  }
208 
209  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
210  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
211  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setExamId((string) $row["exam_id"]);
212 
213  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setRequestedHintsCount($row['hint_count']);
214  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setDeductedHintPoints($row['hint_points']);
215  }
216  }
217 
218  public function getTest()
219  {
220  return $this->test;
221  }
222 
223  public function setTest($test)
224  {
225  $this->test = &$test;
226  }
227 
228  public function setDatasets($datasets)
229  {
230  $this->datasets = $datasets;
231  }
232 
233  public function getDatasets()
234  {
235  return $this->datasets;
236  }
237 
238  public function addQuestionTitle($question_id, $question_title)
239  {
240  $this->questionTitles[$question_id] = $question_title;
241  }
242 
243  public function getQuestionTitles()
244  {
245  return $this->questionTitles;
246  }
247 
248  public function getQuestionTitle($question_id)
249  {
250  if (array_key_exists($question_id, $this->questionTitles)) {
251  return $this->questionTitles[$question_id];
252  } else {
253  return "";
254  }
255  }
256 
257  public function calculateStatistics()
258  {
259  include_once "./Modules/Test/classes/class.ilTestStatistics.php";
260  $this->statistics = new ilTestStatistics($this);
261  }
262 
264  {
265  $finishedParticipants = 0;
266 
267  foreach ($this->participants as $active_id => $participant) {
268  if (!$participant->isSubmitted()) {
269  continue;
270  }
271 
272  $finishedParticipants++;
273  }
274 
275  return $finishedParticipants;
276  }
277 
278  public function getParticipants()
279  {
280  if (is_array($this->arrFilter) && count($this->arrFilter) > 0) {
281  $filteredParticipants = array();
282  $courseids = array();
283  $groupids = array();
284  global $DIC;
285  $ilDB = $DIC['ilDB'];
286  if (array_key_exists('group', $this->arrFilter)) {
287  $ids = ilObject::_getIdsForTitle($this->arrFilter['group'], 'grp', true);
288  $groupids = array_merge($groupids, $ids);
289  }
290  if (array_key_exists('course', $this->arrFilter)) {
291  $ids = ilObject::_getIdsForTitle($this->arrFilter['course'], 'crs', true);
292  $courseids = array_merge($courseids, $ids);
293  }
294  foreach ($this->participants as $active_id => $participant) {
295  $remove = false;
296  if (array_key_exists('name', $this->arrFilter)) {
297  if (!(strpos(strtolower($participant->getName()), strtolower($this->arrFilter['name'])) !== false)) {
298  $remove = true;
299  }
300  }
301  if (!$remove) {
302  if (array_key_exists('group', $this->arrFilter)) {
303  include_once "./Services/Membership/classes/class.ilParticipants.php";
304  $groups = ilParticipants::_getMembershipByType($participant->getUserID(), "grp");
305  $foundfilter = false;
306  if (count(array_intersect($groupids, $groups))) {
307  $foundfilter = true;
308  }
309  if (!$foundfilter) {
310  $remove = true;
311  }
312  }
313  }
314  if (!$remove) {
315  if (array_key_exists('course', $this->arrFilter)) {
316  include_once "./Services/Membership/classes/class.ilParticipants.php";
317  $courses = ilParticipants::_getMembershipByType($participant->getUserID(), "crs");
318  $foundfilter = false;
319  if (count(array_intersect($courseids, $courses))) {
320  $foundfilter = true;
321  }
322  if (!$foundfilter) {
323  $remove = true;
324  }
325  }
326  }
327  if (!$remove) {
328  if (array_key_exists('active_id', $this->arrFilter)) {
329  if ($active_id != $this->arrFilter['active_id']) {
330  $remove = true;
331  }
332  }
333  }
334  if (!$remove) {
335  $filteredParticipants[$active_id] = $participant;
336  }
337  }
338  return $filteredParticipants;
339  } else {
340  return $this->participants;
341  }
342  }
343 
344  public function resetFilter()
345  {
346  $this->arrFilter = array();
347  }
348 
349  /*
350  * Set an output filter for getParticipants
351  *
352  * @param string $by name, course, group
353  * @param string $text Filter text
354  */
355  public function setFilter($by, $text)
356  {
357  $this->arrFilter = array($by => $text);
358  }
359 
360  /*
361  * Set an output filter for getParticipants
362  *
363  * @param array $arrFilter filter values
364  */
365  public function setFilterArray($arrFilter)
366  {
367  $this->arrFilter = $arrFilter;
368  }
369 
370  public function addParticipant($active_id, $participant)
371  {
372  $this->participants[$active_id] = $participant;
373  }
374 
379  public function getParticipant($active_id)
380  {
381  return $this->participants[$active_id];
382  }
383 
384  public function participantExists($active_id)
385  {
386  return array_key_exists($active_id, $this->participants);
387  }
388 
389  public function removeParticipant($active_id)
390  {
391  unset($this->participants[$active_id]);
392  }
393 
394  public function getStatistics()
395  {
396  return $this->statistics;
397  }
398 
399  public function getParticipantIds()
400  {
401  return array_keys($this->participants);
402  }
403 } // END ilTestEvaluationData
$data
Definition: storeScorm.php:23
$result
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)
global $DIC
Definition: goto.php:24
This class calculates statistical data for a test which has to be calculated using all participant da...
$query
addParticipant($active_id, $participant)
$rows
Definition: xhr_table.php:10
global $ilDB
static _getIdsForTitle($title, $type='', $partialmatch=false)