ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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 
37 
44 
51 
56  var $datasets;
57 
58  public function __sleep()
59  {
60  return array('questionTitles', 'participants', 'statistics', 'arrFilter', 'datasets', 'test');
61  }
62 
69  {
70  $this->participants = array();
71  $this->questionTitles = array();
72  if( $test !== null )
73  {
74  $this->test = $test;
75  $this->generateOverview();
76  }
77  }
78 
79  function generateOverview()
80  {
81  global $ilDB;
82 
83  include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
84  include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
85 
86  $this->participants = array();
87 
88  $query = "
89  SELECT usr_data.usr_id,
90  usr_data.firstname,
91  usr_data.lastname,
92  usr_data.title,
93  usr_data.login,
94  tst_pass_result.*
95  FROM tst_pass_result, tst_active
96  LEFT JOIN usr_data
97  ON tst_active.user_fi = usr_data.usr_id
98  WHERE tst_active.active_id = tst_pass_result.active_fi
99  AND tst_active.test_fi = %s
100  ORDER BY usr_data.lastname,
101  usr_data.firstname,
102  tst_pass_result.active_fi,
103  tst_pass_result.pass,
104  tst_pass_result.tstamp
105  ";
106 
107  $result = $ilDB->queryF(
108  $query, array('integer'), array($this->getTest()->getTestId())
109  );
110 
111  $pass = NULL;
112  $checked = array();
113  $thissets = 0;
114 
115  while( $row = $ilDB->fetchAssoc($result) )
116  {
117  $thissets++;
118 
119  $remove = FALSE;
120 
121  if( !$this->participantExists($row["active_fi"]) )
122  {
123  $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
124 
125  $this->getParticipant($row["active_fi"])->setName(
126  $this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"])
127  );
128 
129  $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
130 
131  $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
132  }
133 
134  if( !is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"])) )
135  {
137  $pass->setPass($row["pass"]);
138  $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
139  }
140 
141  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints($row["points"]);
142  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setObligationsAnswered($row["obligations_answered"]);
143 
144  if( $row["questioncount"] == 0 )
145  {
147  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
148  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
149  }
150  else
151  {
152  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
153  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
154  }
155 
156  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
157  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
158 
159  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setRequestedHintsCount($row['hint_count']);
160  $this->getParticipant($row['active_fi'])->getPass($row['pass'])->setDeductedHintPoints($row['hint_points']);
161  }
162  }
163 
164  function getTest()
165  {
166  return $this->test;
167  }
168 
169  function setTest($test)
170  {
171  $this->test =& $test;
172  }
173 
175  {
176  $this->datasets = $datasets;
177  }
178 
179  function getDatasets()
180  {
181  return $this->datasets;
182  }
183 
184  function addQuestionTitle($question_id, $question_title)
185  {
186  $this->questionTitles[$question_id] = $question_title;
187  }
188 
189  function getQuestionTitles()
190  {
191  return $this->questionTitles;
192  }
193 
194  function getQuestionTitle($question_id)
195  {
196  if (array_key_exists($question_id, $this->questionTitles))
197  {
198  return $this->questionTitles[$question_id];
199  }
200  else
201  {
202  return "";
203  }
204  }
205 
207  {
208  include_once "./Modules/Test/classes/class.ilTestStatistics.php";
209  $this->statistics = new ilTestStatistics($this);
210  }
211 
212  function getParticipants()
213  {
214  if (count($this->arrFilter))
215  {
216  $filteredParticipants = array();
217  $courseids = array();
218  $groupids = array();
219  global $ilDB;
220  if (array_key_exists('group', $this->arrFilter))
221  {
222  $ids = ilObject::_getIdsForTitle($this->arrFilter['group'], 'grp', true);
223  $groupids = array_merge($groupids, $ids);
224  }
225  if (array_key_exists('course', $this->arrFilter))
226  {
227  $ids = ilObject::_getIdsForTitle($this->arrFilter['course'], 'crs', true);
228  $courseids = array_merge($courseids, $ids);
229  }
230  foreach ($this->participants as $active_id => $participant)
231  {
232  $remove = FALSE;
233  if (array_key_exists('name', $this->arrFilter))
234  {
235  if (!(strpos(strtolower($participant->getName()), strtolower($this->arrFilter['name'])) !== FALSE)) $remove = TRUE;
236  }
237  if (!$remove)
238  {
239  if (array_key_exists('group', $this->arrFilter))
240  {
241  include_once "./Services/Membership/classes/class.ilParticipants.php";
242  $groups = ilParticipants::_getMembershipByType($participant->getUserID(), "grp");
243  $foundfilter = FALSE;
244  if (count(array_intersect($groupids, $groups))) $foundfilter = TRUE;
245  if (!$foundfilter) $remove = TRUE;
246  }
247  }
248  if (!$remove)
249  {
250  if (array_key_exists('course', $this->arrFilter))
251  {
252  include_once "./Services/Membership/classes/class.ilParticipants.php";
253  $courses = ilParticipants::_getMembershipByType($participant->getUserID(), "crs");
254  $foundfilter = FALSE;
255  if (count(array_intersect($courseids, $courses))) $foundfilter = TRUE;
256  if (!$foundfilter) $remove = TRUE;
257  }
258  }
259  if (!$remove)
260  {
261  if (array_key_exists('active_id', $this->arrFilter))
262  {
263  if ($active_id != $this->arrFilter['active_id']) $remove = TRUE;
264  }
265  }
266  if (!$remove) $filteredParticipants[$active_id] = $participant;
267  }
268  return $filteredParticipants;
269  }
270  else
271  {
272  return $this->participants;
273  }
274  }
275 
276  function resetFilter()
277  {
278  $this->arrFilter = array();
279  }
280 
281  /*
282  * Set an output filter for getParticipants
283  *
284  * @param string $by name, course, group
285  * @param string $text Filter text
286  */
287  function setFilter($by, $text)
288  {
289  $this->arrFilter = array($by => $text);
290  }
291 
292  /*
293  * Set an output filter for getParticipants
294  *
295  * @param array $arrFilter filter values
296  */
298  {
299  $this->arrFilter = $arrFilter;
300  }
301 
302  function addParticipant($active_id, $participant)
303  {
304  $this->participants[$active_id] = $participant;
305  }
306 
311  function &getParticipant($active_id)
312  {
313  return $this->participants[$active_id];
314  }
315 
316  function participantExists($active_id)
317  {
318  return array_key_exists($active_id, $this->participants);
319  }
320 
321  function removeParticipant($active_id)
322  {
323  unset($this->participants[$active_id]);
324  }
325 
326  function &getStatistics()
327  {
328  return $this->statistics;
329  }
330 
331  function getParticipantIds()
332  {
333  return array_keys($this->participants);
334  }
335 } // END ilTestEvaluationData