ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapTestAdministration.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 
24 
33 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
34 
36 {
38  {
40  }
41 
42  function saveQuestionResult($sid,$user_id,$test_id,$question_id,$pass,$solution)
43  {
44  include_once './include/inc.header.php';
45  if(!$this->__checkSession($sid))
46  {
47  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
48  }
49 
50  // Include main header
51  include_once "./Modules/Test/classes/class.ilObjTest.php";
52  $active_id = ilObjTest::_getActiveIdOfUser($user_id, $test_id);
53  $ilDB = $GLOBALS['ilDB'];
54  if (($active_id > 0) && ($question_id > 0) && (strlen($pass) > 0))
55  {
56  $deletequery = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
57  $ilDB->quote($active_id . ""),
58  $ilDB->quote($question_id . ""),
59  $ilDB->quote($pass . "")
60  );
61  $ilDB->query($deletequery);
62  }
63  $saved_solutions = FALSE;
64  for($i = 0; $i < count($solution); $i += 3)
65  {
66  $query = sprintf("INSERT INTO tst_solutions ".
67  "SET active_fi = %s, ".
68  "question_fi = %s, ".
69  "value1 = %s, ".
70  "value2 = %s, ".
71  "points = %s, ".
72  "pass = %s",
73  $ilDB->quote($active_id . ""),
74  $ilDB->quote($question_id . ""),
75  $ilDB->quote($solution[$i]),
76  $ilDB->quote($solution[$i+1]),
77  $ilDB->quote($solution[$i+2]),
78  $ilDB->quote($pass . "")
79  );
80  $saved_solutions = TRUE;
81  $ilDB->query($query);
82  }
83  return $saved_solutions;
84  }
85 
86  function saveQuestion($sid,$active_id,$question_id,$pass,$solution)
87  {
88  if(!$this->__checkSession($sid))
89  {
90  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
91  }
92 
93  if (is_array($solution) && (array_key_exists("item", $solution))) $solution = $solution["item"];
94 
95  // Include main header
96  include_once './include/inc.header.php';
97  $ilDB = $GLOBALS['ilDB'];
98  if (($active_id > 0) && ($question_id > 0) && (strlen($pass) > 0))
99  {
100  $deletequery = sprintf("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
101  $ilDB->quote($active_id . ""),
102  $ilDB->quote($question_id . ""),
103  $ilDB->quote($pass . "")
104  );
105  $ilDB->query($deletequery);
106  }
107  for($i = 0; $i < count($solution); $i += 3)
108  {
109  $query = sprintf("INSERT INTO tst_solutions ".
110  "SET active_fi = %s, ".
111  "question_fi = %s, ".
112  "value1 = %s, ".
113  "value2 = %s, ".
114  "points = %s, ".
115  "pass = %s",
116  $ilDB->quote($active_id . ""),
117  $ilDB->quote($question_id . ""),
118  $ilDB->quote($solution[$i]),
119  $ilDB->quote($solution[$i+1]),
120  $ilDB->quote($solution[$i+2]),
121  $ilDB->quote($pass . "")
122  );
123  $ilDB->query($query);
124  }
125  return true;
126  }
127 
128  function getQuestionSolution($sid,$active_id,$question_id,$pass)
129  {
130  if(!$this->__checkSession($sid))
131  {
132  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
133  }
134  $solution = array();
135  // Include main header
136  include_once './include/inc.header.php';
137  $ilDB = $GLOBALS['ilDB'];
138  if (($active_id > 0) && ($question_id > 0) && (strlen($pass) > 0))
139  {
140  $query = sprintf("SELECT * FROM tst_solutions ".
141  "WHERE active_fi = %s AND ".
142  "question_fi = %s AND ".
143  "pass = %s",
144  $ilDB->quote($active_id . ""),
145  $ilDB->quote($question_id . ""),
146  $ilDB->quote($pass . "")
147  );
148  $result = $ilDB->query($query);
149  if ($result->numRows())
150  {
151  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
152  {
153  array_push($solution, $row["value1"]);
154  array_push($solution, $row["value2"]);
155  array_push($solution, $row["points"]);
156  }
157  }
158  }
159  return $solution;
160  }
161 
174  function getTestResults ($sid, $test_ref_id, $sum_only) {
175  if(!$this->__checkSession($sid))
176  {
177  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
178  }
179  if(!strlen($test_ref_id))
180  {
181  return $this->__raiseError('No test id given. Aborting!',
182  'Client');
183  }
184  include_once './include/inc.header.php';
185  global $rbacsystem, $tree, $ilLog;
186 
187  if(ilObject::_isInTrash($test_ref_id))
188  {
189  return $this->__raiseError('Test is trashed. Aborting!',
190  'Client');
191  }
192 
193  // get obj_id
194  if(!$obj_id = ilObject::_lookupObjectId($test_ref_id))
195  {
196  return $this->__raiseError('No test found for id: '.$test_ref_id,
197  'Client');
198  }
199 
200 
201  // Check access
202  $permission_ok = false;
203  foreach($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id)
204  {
205  if($rbacsystem->checkAccess('edit',$ref_id))
206  {
207  $permission_ok = true;
208  break;
209  }
210  }
211  if(!$permission_ok)
212  {
213  return $this->__raiseError('No permission to edit the object with id: '.$test_ref_id,
214  'Server');
215  }
216  // store into xml result set
217  include_once './webservice/soap/classes/class.ilXMLResultSet.php';
218  include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
219 
220  $xmlResultSet = new ilXMLResultSet();
221  $xmlResultSet->addColumn("user_id");
222  $xmlResultSet->addColumn("login");
223  $xmlResultSet->addColumn("firstname");
224  $xmlResultSet->addColumn("lastname");
225  $xmlResultSet->addColumn("matriculation");
226 
227  include_once './Modules/Test/classes/class.ilObjTest.php';
228  $test_obj = new ilObjTest($obj_id, false);
229  $participants = $test_obj->getTestParticipants();
230 
231 
232  if ($sum_only)
233  {
234  $data = $test_obj->getAllTestResults($participants, false);
235 #print_r($data);
236  // create xml
237  $xmlResultSet->addColumn("maximum_points");
238  $xmlResultSet->addColumn("received_points");
239  // skip titles
240  $titles = array_shift($data);
241  foreach ($data as $row) {
242  $xmlRow = new ilXMLResultSetRow();
243  $xmlRow->setValue(0, $row["user_id"]);
244  $xmlRow->setValue(1, $row["login"]);
245  $xmlRow->setValue(2, $row["firstname"]);
246  $xmlRow->setValue(3, $row["lastname"]);
247  $xmlRow->setValue(4, $row["matriculation"]);
248  $xmlRow->setValue(5, $row["max_points"]);
249  $xmlRow->setValue(6, $row["reached_points"]);
250  $xmlResultSet->addRow($xmlRow);
251  }
252  } else {
253  $data = $test_obj->getDetailedTestResults($participants);
254  // create xml
255  $xmlResultSet->addColumn("question_id");
256  $xmlResultSet->addColumn("question_title");
257  $xmlResultSet->addColumn("maximum_points");
258  $xmlResultSet->addColumn("received_points");
259  foreach ($data as $row) {
260  $xmlRow = new ilXMLResultSetRow();
261  $xmlRow->setValue(0, $row["user_id"]);
262  $xmlRow->setValue(1, $row["login"]);
263  $xmlRow->setValue(2, $row["firstname"]);
264  $xmlRow->setValue(3, $row["lastname"]);
265  $xmlRow->setValue(4, $row["matriculation"]);
266  $xmlRow->setValue(5, $row["question_id"]);
267  $xmlRow->setValue(6, $row["question_title"]);
268  $xmlRow->setValue(7, $row["max_points"]);
269  $xmlRow->setValue(8, $row["reached_points"]);
270  $xmlResultSet->addRow($xmlRow);
271  }
272  }
273 
274 
275  // create writer
276  $xmlWriter = new ilXMLResultSetWriter($xmlResultSet);
277  $xmlWriter->start();
278 
279  return $xmlWriter->getXML();
280  }
281 
282 
283 }
284 ?>