ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestEvaluationData.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 {
42 
48  private $test;
49 
56 
63 
69  var $filterby;
70 
77 
82  var $datasets;
83 
84  public function __sleep()
85  {
86  return array('questionTitles', 'participants', 'statistics', 'filterby', 'filtertext', 'datasets', 'test');
87  }
88 
94  function ilTestEvaluationData($test = "")
95  {
96  $this->participants = array();
97  $this->questionTitles = array();
98  if (is_object($test)) $this->test =& $test;
99  if (is_object($test))
100  {
101  $this->generateOverview();
102  }
103  }
104 
105  function generateOverview()
106  {
107  $this->participants = array();
108  global $ilDB;
109  global $ilLog;
110  include_once "./Modules/Test/classes/class.ilTestEvaluationPassData.php";
111  include_once "./Modules/Test/classes/class.ilTestEvaluationUserData.php";
112  $query = sprintf("SELECT usr_data.usr_id, usr_data.firstname, usr_data.lastname, usr_data.title, usr_data.login, " .
113  "tst_test_pass_result.* FROM tst_test_pass_result, tst_active " .
114  "LEFT JOIN usr_data ON tst_active.user_fi = usr_data.usr_id " .
115  "WHERE tst_active.active_id = tst_test_pass_result.active_fi " .
116  "AND tst_active.test_fi = %s " .
117  "ORDER BY usr_data.lastname, usr_data.firstname, active_id, pass, TIMESTAMP",
118  $ilDB->quote($this->getTest()->getTestId() . "")
119  );
120  $ilLog->write($query);
121  $result = $ilDB->query($query);
122  $pass = NULL;
123  $checked = array();
124  $thissets = 0;
125  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
126  {
127  $thissets++;
128  $remove = FALSE;
129  if (!$this->participantExists($row["active_fi"]))
130  {
131  $this->addParticipant($row["active_fi"], new ilTestEvaluationUserData($this->getTest()->getPassScoring()));
132  $this->getParticipant($row["active_fi"])->setName($this->getTest()->buildName($row["usr_id"], $row["firstname"], $row["lastname"], $row["title"]));
133  $this->getParticipant($row["active_fi"])->setLogin($row["login"]);
134  $this->getParticipant($row["active_fi"])->setUserID($row["usr_id"]);
135  }
136  if (!is_object($this->getParticipant($row["active_fi"])->getPass($row["pass"])))
137  {
139  $pass->setPass($row["pass"]);
140  $this->getParticipant($row["active_fi"])->addPass($row["pass"], $pass);
141  }
142  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setReachedPoints($row["points"]);
143  if ($row["questioncount"] == 0)
144  {
145  $data = ilObjTest::_getQuestionCountAndPointsForPassOfParticipant($row['active_fi'], $row['pass']);
146  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($data['points']);
147  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($data['count']);
148  }
149  else
150  {
151  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setMaxPoints($row["maxpoints"]);
152  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setQuestionCount($row["questioncount"]);
153  }
154  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setNrOfAnsweredQuestions($row["answeredquestions"]);
155  $this->getParticipant($row["active_fi"])->getPass($row["pass"])->setWorkingTime($row["workingtime"]);
156  }
157  }
158 
159  function getTest()
160  {
161  return $this->test;
162  }
163 
164  function setTest($test)
165  {
166  $this->test =& $test;
167  }
168 
170  {
171  $this->datasets = $datasets;
172  }
173 
174  function getDatasets()
175  {
176  return $this->datasets;
177  }
178 
179  function addQuestionTitle($question_id, $question_title)
180  {
181  $this->questionTitles[$question_id] = $question_title;
182  }
183 
184  function getQuestionTitles()
185  {
186  return $this->questionTitles;
187  }
188 
189  function getQuestionTitle($question_id)
190  {
191  if (array_key_exists($question_id, $this->questionTitles))
192  {
193  return $this->questionTitles[$question_id];
194  }
195  else
196  {
197  return "";
198  }
199  }
200 
202  {
203  include_once "./Modules/Test/classes/class.ilTestStatistics.php";
204  $this->statistics = new ilTestStatistics($this);
205  }
206 
207  private function getMembershipByType($a_usr_id,$a_type)
208  {
209  global $ilDB;
210 
211  $query = "SELECT DISTINCT obd.obj_id,obr.ref_id FROM rbac_ua AS ua ".
212  "JOIN rbac_fa AS fa ON ua.rol_id = fa.rol_id ".
213  "JOIN tree AS t1 ON t1.child = fa.parent ".
214  "JOIN object_reference AS obr ON t1.parent = obr.ref_id ".
215  "JOIN object_data AS obd ON obr.obj_id = obd.obj_id ".
216  "WHERE obd.type = ".$ilDB->quote($a_type)." ".
217  "AND fa.assign = 'y' ".
218  "AND ua.usr_id = ".$ilDB->quote($a_usr_id)." ";
219  $res = $ilDB->query($query);
220 
221  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
222  {
223  $ref_ids[] = $row->obj_id;
224  }
225 
226  return $ref_ids ? $ref_ids : array();
227  }
228 
229  function getParticipants()
230  {
231  if (strlen($this->filterby) && strlen($this->filtertext))
232  {
233  $filteredParticipants = array();
234  $courseids = array();
235  $groupids = array();
236  global $ilDB;
237  switch ($this->filterby)
238  {
239  case "group":
240  $query = sprintf("SELECT obj_id FROM object_data WHERE type = 'grp' AND title LIKE %s",
241  $ilDB->quote("%" . $this->filtertext . "%")
242  );
243  $result = $ilDB->query($query);
244  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
245  {
246  array_push($groupids, $row["obj_id"]);
247  }
248  break;
249  case "course":
250  $query = sprintf("SELECT obj_id FROM object_data WHERE type = 'crs' AND title LIKE %s",
251  $ilDB->quote("%" . $this->filtertext . "%")
252  );
253  $result = $ilDB->query($query);
254  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
255  {
256  array_push($courseids, $row["obj_id"]);
257  }
258  break;
259  }
260  foreach ($this->participants as $active_id => $participant)
261  {
262  $remove = FALSE;
263  switch ($this->filterby)
264  {
265  case "name":
266  if (!(strpos(strtolower($participant->getName()), strtolower($this->filtertext)) !== FALSE)) $remove = TRUE;
267  break;
268  case "group":
269  $groups = $this->getMembershipByType($participant->getUserID(), "grp");
270  $foundfilter = FALSE;
271  if (count(array_intersect($groupids, $groups))) $foundfilter = TRUE;
272  if (!$foundfilter) $remove = TRUE;
273  break;
274  case "course":
275  $courses = $this->getMembershipByType($participant->getUserID(), "crs");
276  $foundfilter = FALSE;
277  if (count(array_intersect($courseids, $courses))) $foundfilter = TRUE;
278  if (!$foundfilter) $remove = TRUE;
279  break;
280  }
281  if (!$remove) $filteredParticipants[$active_id] = $participant;
282  }
283  return $filteredParticipants;
284  }
285  else
286  {
287  return $this->participants;
288  }
289  }
290 
291  function resetFilter()
292  {
293  $this->filterby = "";
294  $this->filtertext = "";
295  }
296 
297  /*
298  * Set an output filter for getParticipants
299  *
300  * @param string $by name, course, group
301  * @param string $text Filter text
302  */
303  function setFilter($by, $text)
304  {
305  $this->filterby = $by;
306  $this->filtertext = $text;
307  }
308 
309  function addParticipant($active_id, $participant)
310  {
311  $this->participants[$active_id] = $participant;
312  }
313 
314  function &getParticipant($active_id)
315  {
316  return $this->participants[$active_id];
317  }
318 
319  function participantExists($active_id)
320  {
321  return array_key_exists($active_id, $this->participants);
322  }
323 
324  function removeParticipant($active_id)
325  {
326  unset($this->participants[$active_id]);
327  }
328 
329  function &getStatistics()
330  {
331  return $this->statistics;
332  }
333 
334  function getParticipantIds()
335  {
336  return array_keys($this->participants);
337  }
338 } // END ilTestEvaluationData
339 
340 ?>