ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assOrderingHorizontal.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 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
24 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
25 
34 {
35  protected $ordertext;
36  protected $textsize;
37  protected $separator = "::";
38 
51  function __construct(
52  $title = "",
53  $comment = "",
54  $author = "",
55  $owner = -1,
56  $question = ""
57  )
58  {
60  $this->ordertext = "";
61  }
62 
68  public function isComplete()
69  {
70  if (($this->title) and ($this->author) and ($this->question) and ($this->getMaximumPoints() > 0))
71  {
72  return true;
73  }
74  else
75  {
76  return false;
77  }
78  }
79 
84  public function saveToDb($original_id = "")
85  {
86  global $ilDB;
87 
89 
90  // save additional data
91  $affectedRows = $ilDB->manipulateF("DELETE FROM " . $this->getAdditionalTableName() . " WHERE question_fi = %s",
92  array("integer"),
93  array($this->getId())
94  );
95 
96  $affectedRows = $ilDB->manipulateF("INSERT INTO " . $this->getAdditionalTableName() . " (question_fi, ordertext, textsize) VALUES (%s, %s, %s)",
97  array("integer", "text", "float"),
98  array(
99  $this->getId(),
100  $this->getOrderText(),
101  ($this->getTextSize() < 10) ? NULL : $this->getTextSize()
102  )
103  );
104 
106  }
107 
114  public function loadFromDb($question_id)
115  {
116  global $ilDB;
117 
118  $result = $ilDB->queryF("SELECT qpl_questions.*, " . $this->getAdditionalTableName() . ".* FROM qpl_questions LEFT JOIN " . $this->getAdditionalTableName() . " ON " . $this->getAdditionalTableName() . ".question_fi = qpl_questions.question_id WHERE qpl_questions.question_id = %s",
119  array("integer"),
120  array($question_id)
121  );
122  if ($result->numRows() == 1)
123  {
124  $data = $ilDB->fetchAssoc($result);
125  $this->setId($question_id);
126  $this->setObjId($data["obj_fi"]);
127  $this->setTitle($data["title"]);
128  $this->setComment($data["description"]);
129  $this->setOriginalId($data["original_id"]);
130  $this->setNrOfTries($data['nr_of_tries']);
131  $this->setAuthor($data["author"]);
132  $this->setPoints($data["points"]);
133  $this->setOwner($data["owner"]);
134  include_once("./Services/RTE/classes/class.ilRTE.php");
135  $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc($data["question_text"], 1));
136  $this->setOrderText($data["ordertext"]);
137  $this->setTextSize($data["textsize"]);
138  $this->setEstimatedWorkingTime(substr($data["working_time"], 0, 2), substr($data["working_time"], 3, 2), substr($data["working_time"], 6, 2));
139  }
140 
141  parent::loadFromDb($question_id);
142  }
143 
147  public function duplicate($for_test = true, $title = "", $author = "", $owner = "")
148  {
149  if ($this->id <= 0)
150  {
151  // The question has not been saved. It cannot be duplicated
152  return;
153  }
154  // duplicate the question in database
155  $this_id = $this->getId();
156  $clone = $this;
157  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
159  $clone->id = -1;
160  if ($title)
161  {
162  $clone->setTitle($title);
163  }
164 
165  if ($author)
166  {
167  $clone->setAuthor($author);
168  }
169  if ($owner)
170  {
171  $clone->setOwner($owner);
172  }
173 
174  if ($for_test)
175  {
176  $clone->saveToDb($original_id);
177  }
178  else
179  {
180  $clone->saveToDb();
181  }
182 
183  // copy question page content
184  $clone->copyPageOfQuestion($this_id);
185  // copy XHTML media objects
186  $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
187  // duplicate the generic feedback
188  $clone->duplicateFeedbackGeneric($this_id);
189 
190  $clone->onDuplicate($this_id);
191  return $clone->id;
192  }
193 
197  public function copyObject($target_questionpool, $title = "")
198  {
199  if ($this->id <= 0)
200  {
201  // The question has not been saved. It cannot be duplicated
202  return;
203  }
204  // duplicate the question in database
205  $clone = $this;
206  include_once ("./Modules/TestQuestionPool/classes/class.assQuestion.php");
208  $clone->id = -1;
209  $source_questionpool = $this->getObjId();
210  $clone->setObjId($target_questionpool);
211  if ($title)
212  {
213  $clone->setTitle($title);
214  }
215  $clone->saveToDb();
216 
217  // copy question page content
218  $clone->copyPageOfQuestion($original_id);
219  // copy XHTML media objects
220  $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
221  // duplicate the generic feedback
222  $clone->duplicateFeedbackGeneric($original_id);
223 
224  $clone->onCopy($this->getObjId(), $this->getId());
225 
226  return $clone->id;
227  }
228 
234  public function getMaximumPoints()
235  {
236  return $this->getPoints();
237  }
238 
247  public function calculateReachedPoints($active_id, $pass = NULL)
248  {
249  global $ilDB;
250 
251  $found_values = array();
252  if (is_null($pass))
253  {
254  $pass = $this->getSolutionMaxPass($active_id);
255  }
256  $result = $ilDB->queryF("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
257  array('integer','integer','integer'),
258  array($active_id, $this->getId(), $pass)
259  );
260  $points = 0;
261  $data = $ilDB->fetchAssoc($result);
262  if (strcmp($data["value1"], join($this->getOrderingElements(), "{::}")) == 0)
263  {
264  $points = $this->getPoints();
265  }
266  $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
267  return $points;
268  }
269 
277  public function saveWorkingData($active_id, $pass = NULL)
278  {
279  global $ilDB;
280  global $ilUser;
281 
282  if (is_null($pass))
283  {
284  include_once "./Modules/Test/classes/class.ilObjTest.php";
285  $pass = ilObjTest::_getPass($active_id);
286  }
287 
288  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
289  array('integer','integer','integer'),
290  array($active_id, $this->getId(), $pass)
291  );
292 
293  $entered_values = false;
294  if (strlen($_POST["orderresult"]))
295  {
296  $next_id = $ilDB->nextId('tst_solutions');
297  $affectedRows = $ilDB->insert("tst_solutions", array(
298  "solution_id" => array("integer", $next_id),
299  "active_fi" => array("integer", $active_id),
300  "question_fi" => array("integer", $this->getId()),
301  "value1" => array("clob", $_POST['orderresult']),
302  "value2" => array("clob", null),
303  "pass" => array("integer", $pass),
304  "tstamp" => array("integer", time())
305  ));
306  $entered_values = true;
307  }
308  if ($entered_values)
309  {
310  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
312  {
313  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
314  }
315  }
316  else
317  {
318  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
320  {
321  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
322  }
323  }
324  parent::saveWorkingData($active_id, $pass);
325  return true;
326  }
327 
328  /*
329  * Move an element to the right during a test when a user selects/deselects a word without using javascript
330  */
331  public function moveRight($position, $active_id, $pass = null)
332  {
333  global $ilDB;
334  global $ilUser;
335 
336  if (is_null($pass))
337  {
338  include_once "./Modules/Test/classes/class.ilObjTest.php";
339  $pass = ilObjTest::_getPass($active_id);
340  }
341 
342  $solutions =& $this->getSolutionValues($active_id, $pass);
343  $elements = array();
344  if (count($solutions) == 1)
345  {
346  $elements = split("{::}", $solutions[0]["value1"]);
347  }
348  else
349  {
350  $elements = $_SESSION['qst_ordering_horizontal_elements'];
351  }
352  if (count($elements))
353  {
354  $affectedRows = $ilDB->manipulateF("DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
355  array('integer','integer','integer'),
356  array($active_id, $this->getId(), $pass)
357  );
358 
359  if ($position < count($elements)-1)
360  {
361  $temp = $elements[$position];
362  $elements[$position] = $elements[$position+1];
363  $elements[$position+1] = $temp;
364  }
365  $entered_values = false;
366  $next_id = $ilDB->nextId('tst_solutions');
367  $affectedRows = $ilDB->insert("tst_solutions", array(
368  "solution_id" => array("integer", $next_id),
369  "active_fi" => array("integer", $active_id),
370  "question_fi" => array("integer", $this->getId()),
371  "value1" => array("clob", join($elements, '{::}')),
372  "value2" => array("clob", null),
373  "pass" => array("integer", $pass),
374  "tstamp" => array("integer", time())
375  ));
376  $entered_values = true;
377  if ($entered_values)
378  {
379  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
381  {
382  $this->logAction($this->lng->txtlng("assessment", "log_user_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
383  }
384  }
385  else
386  {
387  include_once ("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
389  {
390  $this->logAction($this->lng->txtlng("assessment", "log_user_not_entered_values", ilObjAssessmentFolder::_getLogLanguage()), $active_id, $this->getId());
391  }
392  }
393 
394  $this->calculateReachedPoints($active_id, $pass);
395  }
396  }
397 
403  public function getQuestionType()
404  {
405  return "assOrderingHorizontal";
406  }
407 
413  public function getAdditionalTableName()
414  {
415  return "qpl_qst_horder";
416  }
417 
423  public function getAnswerTableName()
424  {
425  return "";
426  }
427 
433  public function deleteAnswers($question_id)
434  {
435  }
436 
441  public function getRTETextWithMediaObjects()
442  {
444  return $text;
445  }
446 
455  public function setExportDetailsXLS(&$adapter, $startrow, $active_id, $pass)
456  {
457  $adapter->setCellValue($startrow, 0, $this->lng->txt($this->getQuestionType()), CELL_FORMAT_TITLE);
458  $adapter->setCellValue($startrow, 1, $this->getTitle(), CELL_FORMAT_TITLE);
459 
460  $solutionvalue = "";
461  $solutions =& $this->getSolutionValues($active_id, $pass);
462  $solutionvalue = str_replace("{::}", " ", $solutions[0]["value1"]);
463  $i = 1;
464  $adapter->setCellValue($startrow+$i, 0, $solutionvalue);
465  $i++;
466  return $startrow + $i + 1;
467  }
468 
481  public function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
482  {
483  include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assOrderingHorizontalImport.php";
484  $import = new assOrderingHorizontalImport($this);
485  $import->fromXML($item, $questionpool_id, $tst_id, $tst_object, $question_counter, $import_mapping);
486  }
487 
494  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
495  {
496  include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assOrderingHorizontalExport.php";
497  $export = new assOrderingHorizontalExport($this);
498  return $export->toXML($a_include_header, $a_include_binary, $a_shuffle, $test_output, $force_image_references);
499  }
500 
506  public function getBestSolution($active_id, $pass)
507  {
508  $user_solution = array();
509  return $user_solution;
510  }
511 
517  public function getOrderingElements()
518  {
519  $text = $this->getOrderText();
520  $result = array();
521  include_once "./Services/Utilities/classes/class.ilStr.php";
522  if (ilStr::strPos($text, $this->separator) === false)
523  {
524  $result = preg_split("/\\s+/", $text);
525  }
526  else
527  {
528  $result = split($this->separator, $text);
529  }
530  return $result;
531  }
532 
538  public function getRandomOrderingElements()
539  {
540  $elements = $this->getOrderingElements();
541  shuffle($elements);
542  return $elements;
543  }
544 
550  public function getOrderText()
551  {
552  return $this->ordertext;
553  }
554 
560  public function setOrderText($a_value)
561  {
562  $this->ordertext = $a_value;
563  }
564 
570  public function getTextSize()
571  {
572  return $this->textsize;
573  }
574 
580  public function setTextSize($a_value)
581  {
582  if ($a_value >= 10)
583  {
584  $this->textsize = $a_value;
585  }
586  }
587 
593  public function getSeparator()
594  {
595  return $this->separator;
596  }
597 
603  public function setSeparator($a_value)
604  {
605  $this->separator = $a_value;
606  }
607 
611  public function __get($value)
612  {
613  switch ($value)
614  {
615  case "ordertext":
616  return $this->getOrderText();
617  break;
618  case "textsize":
619  return $this->getTextSize();
620  break;
621  case "separator":
622  return $this->getSeparator();
623  break;
624  default:
625  return parent::__get($value);
626  break;
627  }
628  }
629 
633  public function __set($key, $value)
634  {
635  switch ($key)
636  {
637  case "ordertext":
638  $this->setOrderText($value);
639  break;
640  case "textsize":
641  $this->setTextSize($value);
642  break;
643  case "separator":
644  $this->setSeparator($value);
645  break;
646  default:
647  parent::__set($key, $value);
648  break;
649  }
650  }
651 }
652 
653 ?>