ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyNominalQuestion.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 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
27 define("SUBTYPE_MCSR", 1);
28 define("SUBTYPE_MCMR", 2);
29 
42 {
50  var $subtype;
51 
60 
73  $title = "",
74  $description = "",
75  $author = "",
76  $questiontext = "",
77  $owner = -1,
79  $orientation = 0
80  )
81 
82  {
84  $this->subtype = $subtype;
85  $this->orientation = $orientation;
86  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
87  $this->categories = new SurveyCategories();
88  }
89 
100  {
101  $this->subtype = $subtype;
102  }
103 
113  function getSubtype()
114  {
115  return $this->subtype;
116  }
117 
128  {
129  global $ilDB;
130 
131  $query = sprintf("SELECT survey_question.*, survey_question_nominal.* FROM survey_question, survey_question_nominal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_nominal.question_fi",
132  $ilDB->quote($id)
133  );
134  $result = $ilDB->query($query);
135  if ($result->numRows() == 1)
136  {
137  return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
138  }
139  else
140  {
141  return array();
142  }
143  }
144 
153  function loadFromDb($id)
154  {
155  global $ilDB;
156  $query = sprintf("SELECT survey_question.*, survey_question_nominal.* FROM survey_question, survey_question_nominal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_nominal.question_fi",
157  $ilDB->quote($id)
158  );
159  $result = $ilDB->query($query);
160  if ($result->numRows() == 1)
161  {
162  $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
163  $this->id = $data->question_id;
164  $this->title = $data->title;
165  $this->description = $data->description;
166  $this->obj_id = $data->obj_fi;
167  $this->author = $data->author;
168  $this->subtype = $data->subtype;
169  $this->orientation = $data->orientation;
170  $this->obligatory = $data->obligatory;
171  $this->owner = $data->owner_fi;
172  include_once("./Services/RTE/classes/class.ilRTE.php");
173  $this->questiontext = ilRTE::_replaceMediaObjectImageSrc($data->questiontext, 1);
174  $this->complete = $data->complete;
175  $this->original_id = $data->original_id;
176  // loads materials uris from database
177  $this->loadMaterialFromDb($id);
178 
179  $this->categories->flushCategories();
180  $query = sprintf("SELECT survey_variable.*, survey_category.title FROM survey_variable, survey_category WHERE survey_variable.question_fi = %s AND survey_variable.category_fi = survey_category.category_id ORDER BY sequence ASC",
181  $ilDB->quote($id)
182  );
183  $result = $ilDB->query($query);
184  if ($result->numRows() > 0)
185  {
186  while ($data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
187  {
188  $this->categories->addCategory($data->title);
189  }
190  }
191  }
193  }
194 
203  function isComplete()
204  {
205  if (strlen($this->title) && strlen($this->author) && strlen($this->questiontext) && $this->categories->getCategoryCount())
206  {
207  return 1;
208  }
209  else
210  {
211  return 0;
212  }
213  }
214 
222  function saveToDb($original_id = "", $withanswers = true)
223  {
224  global $ilDB;
225  $complete = 0;
226  if ($this->isComplete())
227  {
228  $complete = 1;
229  }
230  if ($original_id)
231  {
232  $original_id = $ilDB->quote($original_id);
233  }
234  else
235  {
236  $original_id = "NULL";
237  }
238  // cleanup RTE images which are not inserted into the question text
239  include_once("./Services/RTE/classes/class.ilRTE.php");
240  ilRTE::_cleanupMediaObjectUsage($this->questiontext, "spl:html",
241  $this->getId());
242 
243  if ($this->id == -1)
244  {
245  // Write new dataset
246  $now = getdate();
247  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
248  $query = sprintf("INSERT INTO survey_question (question_id, questiontype_fi, obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
249  $ilDB->quote($this->getQuestionTypeID()),
250  $ilDB->quote($this->obj_id),
251  $ilDB->quote($this->owner),
252  $ilDB->quote($this->title),
253  $ilDB->quote($this->description),
254  $ilDB->quote($this->author),
255  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
256  $ilDB->quote(sprintf("%d", $this->obligatory)),
257  $ilDB->quote("$complete"),
258  $ilDB->quote($created),
259  $original_id
260  );
261  $result = $ilDB->query($query);
262  if (PEAR::isError($result))
263  {
264  global $ilias;
265  $ilias->raiseError($result->getMessage());
266  }
267  else
268  {
269  $this->id = $ilDB->getLastInsertId();
270  $query = sprintf("INSERT INTO survey_question_nominal (question_fi, subtype, orientation) VALUES (%s, %s, %s)",
271  $ilDB->quote($this->id . ""),
272  $ilDB->quote($this->getSubType() . ""),
273  $ilDB->quote(sprintf("%d", $this->orientation))
274  );
275  $ilDB->query($query);
276  }
277  }
278  else
279  {
280  // update existing dataset
281  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
282  $ilDB->quote($this->title),
283  $ilDB->quote($this->description),
284  $ilDB->quote($this->author),
285  $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->questiontext, 0)),
286  $ilDB->quote(sprintf("%d", $this->obligatory)),
287  $ilDB->quote("$complete"),
288  $ilDB->quote($this->id)
289  );
290  $result = $ilDB->query($query);
291  $query = sprintf("UPDATE survey_question_nominal SET subtype = %s, orientation = %s WHERE question_fi = %s",
292  $ilDB->quote($this->getSubType() . ""),
293  $ilDB->quote(sprintf("%d", $this->orientation)),
294  $ilDB->quote($this->id . "")
295  );
296  $result = $ilDB->query($query);
297  }
298  if (PEAR::isError($result))
299  {
300  global $ilias;
301  $ilias->raiseError($result->getMessage());
302  }
303  else
304  {
305  // saving material uris in the database
306  $this->saveMaterialsToDb();
307  if ($withanswers)
308  {
309  $this->saveCategoriesToDb();
310  }
311  }
312  parent::saveToDb($original_id);
313  }
314 
316  {
317  // save categories
318 
319  // delete existing category relations
320  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
321  $this->ilias->db->quote($this->id)
322  );
323  $result = $this->ilias->db->query($query);
324  // create new category relations
325  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
326  {
327  $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
328  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
329  $this->ilias->db->quote($category_id . ""),
330  $this->ilias->db->quote($this->id . ""),
331  $this->ilias->db->quote(($i + 1) . ""),
332  $this->ilias->db->quote($i . "")
333  );
334  $answer_result = $this->ilias->db->query($query);
335  }
336  $this->saveCompletionStatus();
337  }
338 
347  function toXML($a_include_header = TRUE, $obligatory_state = "")
348  {
349  include_once("./classes/class.ilXmlWriter.php");
350  $a_xml_writer = new ilXmlWriter;
351  $a_xml_writer->xmlHeader();
352  $this->insertXML($a_xml_writer, $a_include_header, $obligatory_state);
353  $xml = $a_xml_writer->xmlDumpMem(FALSE);
354  if (!$a_include_header)
355  {
356  $pos = strpos($xml, "?>");
357  $xml = substr($xml, $pos + 2);
358  }
359  return $xml;
360  }
361 
372  function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = "")
373  {
374  $attrs = array(
375  "id" => $this->getId(),
376  "title" => $this->getTitle(),
377  "type" => $this->getQuestiontype(),
378  "subtype" => $this->getSubtype(),
379  "obligatory" => $this->getObligatory()
380  );
381  $a_xml_writer->xmlStartTag("question", $attrs);
382 
383  $a_xml_writer->xmlElement("description", NULL, $this->getDescription());
384  $a_xml_writer->xmlElement("author", NULL, $this->getAuthor());
385  $a_xml_writer->xmlStartTag("questiontext");
386  $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
387  $a_xml_writer->xmlEndTag("questiontext");
388 
389  $a_xml_writer->xmlStartTag("responses");
390 
391  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
392  {
393  $attrs = array(
394  "id" => $i
395  );
396  switch ($this->getSubtype())
397  {
398  case 1:
399  $a_xml_writer->xmlStartTag("response_single", $attrs);
400  break;
401  case 2:
402  $a_xml_writer->xmlStartTag("response_multiple", $attrs);
403  break;
404  }
405  $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
406  switch ($this->getSubtype())
407  {
408  case 1:
409  $a_xml_writer->xmlEndTag("response_single");
410  break;
411  case 2:
412  $a_xml_writer->xmlEndTag("response_multiple");
413  break;
414  }
415  }
416 
417  $a_xml_writer->xmlEndTag("responses");
418 
419  if (count($this->material))
420  {
421  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $this->material["internal_link"], $matches))
422  {
423  $attrs = array(
424  "label" => $this->material["title"]
425  );
426  $a_xml_writer->xmlStartTag("material", $attrs);
427  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
428  if (strcmp($matches[1], "") != 0)
429  {
430  $intlink = $this->material["internal_link"];
431  }
432  $a_xml_writer->xmlElement("mattext", NULL, $intlink);
433  $a_xml_writer->xmlEndTag("material");
434  }
435  }
436 
437  $a_xml_writer->xmlStartTag("metadata");
438  $a_xml_writer->xmlStartTag("metadatafield");
439  $a_xml_writer->xmlElement("fieldlabel", NULL, "orientation");
440  $a_xml_writer->xmlElement("fieldentry", NULL, $this->getOrientation());
441  $a_xml_writer->xmlEndTag("metadatafield");
442  $a_xml_writer->xmlEndTag("metadata");
443 
444  $a_xml_writer->xmlEndTag("question");
445  }
446 
447  function syncWithOriginal()
448  {
449  global $ilDB;
450  if ($this->original_id)
451  {
452  $complete = 0;
453  if ($this->isComplete())
454  {
455  $complete = 1;
456  }
457  $query = sprintf("UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
458  $ilDB->quote($this->title . ""),
459  $ilDB->quote($this->description . ""),
460  $ilDB->quote($this->author . ""),
461  $ilDB->quote($this->questiontext . ""),
462  $ilDB->quote(sprintf("%d", $this->obligatory) . ""),
463  $ilDB->quote($complete . ""),
464  $ilDB->quote($this->original_id . "")
465  );
466  $result = $ilDB->query($query);
467  $query = sprintf("UPDATE survey_question_nominal SET subtype = %s, orientation = %s WHERE question_fi = %s",
468  $ilDB->quote($this->getSubType() . ""),
469  $ilDB->quote($this->getOrientation() . ""),
470  $ilDB->quote($this->original_id . "")
471  );
472  $result = $ilDB->query($query);
473  if (PEAR::isError($result))
474  {
475  global $ilias;
476  $ilias->raiseError($result->getMessage());
477  }
478  else
479  {
480  // save categories
481 
482  // delete existing category relations
483  $query = sprintf("DELETE FROM survey_variable WHERE question_fi = %s",
484  $ilDB->quote($this->original_id . "")
485  );
486  $result = $ilDB->query($query);
487 
488  // create new category relations
489  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
490  {
491  $category_id = $this->saveCategoryToDb($this->categories->getCategory($i));
492  $query = sprintf("INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
493  $ilDB->quote($category_id . ""),
494  $ilDB->quote($this->original_id . ""),
495  $ilDB->quote(($i + 1) . ""),
496  $ilDB->quote($i . "")
497  );
498  $answer_result = $ilDB->query($query);
499  }
500  }
501  }
503  }
504 
513  function getQuestionType()
514  {
515  return "SurveyNominalQuestion";
516  }
517 
527  {
528  return "survey_question_nominal";
529  }
530 
539  function &getWorkingDataFromUserInput($post_data)
540  {
541  $entered_value = $post_data[$this->getId() . "_value"];
542  $data = array();
543  if ($this->getSubType() == SUBTYPE_MCMR)
544  {
545  if (is_array($entered_value))
546  {
547  foreach ($entered_value as $value)
548  {
549  array_push($data, array("value" => $value));
550  }
551  }
552  }
553  else
554  {
555  array_push($data, array("value" => $entered_value));
556  }
557  return $data;
558  }
559 
572  function checkUserInput($post_data, $survey_id)
573  {
574  // multiple response questions are always non-obligatory
575  // if ($this->getSubType() == SUBTYPE_MCMR) return "";
576  $entered_value = $post_data[$this->getId() . "_value"];
577  if ($this->getSubType() == SUBTYPE_MCMR)
578  {
579  if (!$this->getObligatory($survey_id)) return "";
580 
581  if (!is_array($entered_value))
582  {
583  return $this->lng->txt("nominal_question_mr_not_checked");
584  }
585  }
586  else
587  {
588  if ((!$this->getObligatory($survey_id)) && (strlen($entered_value) == 0)) return "";
589 
590  if (strlen($entered_value) == 0) return $this->lng->txt("nominal_question_not_checked");
591  }
592  return "";
593  }
594 
600  public function saveRandomData($active_id)
601  {
602  global $ilDB;
603  if ($this->getSubType() == SUBTYPE_MCMR)
604  {
605  // multiple responses
606  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
607  {
608  if (rand(0,1))
609  {
610  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
611  $ilDB->quote($this->getId()),
612  $ilDB->quote($active_id),
613  $ilDB->quote($i)
614  );
615  $result = $ilDB->query($query);
616  }
617  }
618  }
619  else
620  {
621  // single responses
622  $category = rand(0, $this->categories->getCategoryCount()-1);
623  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
624  $ilDB->quote($this->getId()),
625  $ilDB->quote($active_id),
626  $ilDB->quote($category)
627  );
628  $result = $ilDB->query($query);
629  }
630  }
631 
632  function saveUserInput($post_data, $active_id)
633  {
634  global $ilDB;
635 
636  if (is_array($post_data[$this->getId() . "_value"]))
637  {
638  foreach ($post_data[$this->getId() . "_value"] as $value)
639  {
640  $entered_value = $value;
641  if (strlen($entered_value) > 0)
642  {
643  $entered_value = $ilDB->quote($entered_value . "");
644  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
645  $ilDB->quote($this->getId() . ""),
646  $ilDB->quote($active_id . ""),
647  $entered_value,
648  "NULL"
649  );
650  $result = $ilDB->query($query);
651  }
652  }
653  }
654  else
655  {
656  $entered_value = $post_data[$this->getId() . "_value"];
657  if (strlen($entered_value) == 0) return;
658  $entered_value = $ilDB->quote($entered_value . "");
659  $query = sprintf("INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
660  $ilDB->quote($this->getId() . ""),
661  $ilDB->quote($active_id . ""),
662  $entered_value,
663  "NULL"
664  );
665  $result = $ilDB->query($query);
666  }
667  }
668 
669  function &getCumulatedResults($survey_id, $nr_of_users)
670  {
671  global $ilDB;
672 
673  $question_id = $this->getId();
674 
675  $result_array = array();
676  $cumulated = array();
677 
678  $query = sprintf("SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
679  $ilDB->quote($question_id),
680  $ilDB->quote($survey_id)
681  );
682  $result = $ilDB->query($query);
683  $numrows = $result->numRows();
684 
685  // count the answers for every answer value
686  while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
687  {
688  $cumulated["$row->value"]++;
689  }
690  asort($cumulated, SORT_NUMERIC);
691  end($cumulated);
692 
693  if ($this->getSubType() == SUBTYPE_MCMR)
694  {
695  $query = sprintf("SELECT survey_answer.answer_id, concat( survey_answer.question_fi, \"_\", survey_answer.active_fi) AS groupval FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi GROUP BY groupval",
696  $ilDB->quote($question_id),
697  $ilDB->quote($survey_id)
698  );
699  $mcmr_result = $ilDB->query($query);
700  $result_array["USERS_ANSWERED"] = $mcmr_result->numRows();
701  $result_array["USERS_SKIPPED"] = $nr_of_users - $mcmr_result->numRows();
702  $numrows = $mcmr_result->numRows();
703  }
704  else
705  {
706  $result_array["USERS_ANSWERED"] = $result->numRows();
707  $result_array["USERS_SKIPPED"] = $nr_of_users - $result->numRows();
708  }
709  $result_array["MEDIAN"] = "";
710  $result_array["ARITHMETIC_MEAN"] = "";
711  $prefix = "";
712  if (strcmp(key($cumulated), "") != 0)
713  {
714  $prefix = (key($cumulated)+1) . " - ";
715  }
716  $result_array["MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
717  $result_array["MODE_VALUE"] = key($cumulated)+1;
718  $result_array["MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
719  $result_array["QUESTION_TYPE"] = "SurveyNominalQuestion";
720  $maxvalues = 0;
721  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
722  {
723  $maxvalues += $cumulated[$key];
724  }
725  for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
726  {
727  $percentage = 0;
728  if ($numrows > 0)
729  {
730  if ($this->getSubType() == SUBTYPE_MCMR)
731  {
732  if ($maxvalues > 0)
733  {
734  $percentage = ($result_array["USERS_ANSWERED"] > 0) ? (float)((int)$cumulated[$key]/$result_array["USERS_ANSWERED"]) : 0;
735  }
736  }
737  else
738  {
739  $percentage = ($numrows > 0) ? (float)((int)$cumulated[$key]/$numrows) : 0;
740  }
741  }
742  $result_array["variables"][$key] = array("title" => $this->categories->getCategory($key), "selected" => (int)$cumulated[$key], "percentage" => $percentage);
743  }
744  return $result_array;
745  }
746 
758  function setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data)
759  {
760  include_once ("./classes/class.ilExcelUtils.php");
761  $worksheet =& $workbook->addWorksheet();
762  $worksheet->writeString(0, 0, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_bold);
763  $worksheet->writeString(0, 1, ilExcelUtils::_convert_text($this->getTitle()));
764  $worksheet->writeString(1, 0, ilExcelUtils::_convert_text($this->lng->txt("question")), $format_bold);
765  $worksheet->writeString(1, 1, ilExcelUtils::_convert_text($this->getQuestiontext()));
766  $worksheet->writeString(2, 0, ilExcelUtils::_convert_text($this->lng->txt("question_type")), $format_bold);
767  $worksheet->writeString(2, 1, ilExcelUtils::_convert_text($this->lng->txt($this->getQuestionType())));
768  $worksheet->writeString(3, 0, ilExcelUtils::_convert_text($this->lng->txt("users_answered")), $format_bold);
769  $worksheet->write(3, 1, $eval_data["USERS_ANSWERED"]);
770  $worksheet->writeString(4, 0, ilExcelUtils::_convert_text($this->lng->txt("users_skipped")), $format_bold);
771  $worksheet->write(4, 1, $eval_data["USERS_SKIPPED"]);
772  $rowcounter = 5;
773 
774  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode")), $format_bold);
775  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_VALUE"]));
776  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_text")), $format_bold);
777  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE"]));
778  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections")), $format_bold);
779  $worksheet->write($rowcounter++, 1, ilExcelUtils::_convert_text($eval_data["MODE_NR_OF_SELECTIONS"]));
780  $worksheet->write($rowcounter, 0, ilExcelUtils::_convert_text($this->lng->txt("categories")), $format_bold);
781  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($this->lng->txt("title")), $format_title);
782  $worksheet->write($rowcounter, 2, ilExcelUtils::_convert_text($this->lng->txt("value")), $format_title);
783  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($this->lng->txt("category_nr_selected")), $format_title);
784  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($this->lng->txt("percentage_of_selections")), $format_title);
785  foreach ($eval_data["variables"] as $key => $value)
786  {
787  $worksheet->write($rowcounter, 1, ilExcelUtils::_convert_text($value["title"]));
788  $worksheet->write($rowcounter, 2, $key+1);
789  $worksheet->write($rowcounter, 3, ilExcelUtils::_convert_text($value["selected"]));
790  $worksheet->write($rowcounter++, 4, ilExcelUtils::_convert_text($value["percentage"]), $format_percent);
791  }
792  }
793 
803  {
805  if ($this->getSubtype() == SUBTYPE_MCMR)
806  {
807  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
808  {
809  $category = $this->categories->getCategory($index);
810  array_push($a_array, ($index+1) . " - $category");
811  }
812  }
813  }
814 
824  function addUserSpecificResultsData(&$a_array, &$resultset)
825  {
826  if (count($resultset["answers"][$this->getId()]))
827  {
828  if ($this->getSubtype() == SUBTYPE_MCMR)
829  {
830  array_push($a_array, "");
831  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
832  {
833  $category = $this->categories->getCategory($index);
834  $found = 0;
835  foreach ($resultset["answers"][$this->getId()] as $answerdata)
836  {
837  if (strcmp($index, $answerdata["value"]) == 0)
838  {
839  $found = 1;
840  }
841  }
842  if ($found)
843  {
844  array_push($a_array, "1");
845  }
846  else
847  {
848  array_push($a_array, "0");
849  }
850  }
851  }
852  else
853  {
854  array_push($a_array, $resultset["answers"][$this->getId()][0]["value"]+1);
855  }
856  }
857  else
858  {
859  array_push($a_array, $this->lng->txt("skipped"));
860  if ($this->getSubtype() == SUBTYPE_MCMR)
861  {
862  for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
863  {
864  array_push($a_array, "");
865  }
866  }
867  }
868  }
869 
880  {
881  global $ilDB;
882 
883  $answers = array();
884 
885  $query = sprintf("SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_finished.survey_fi = %s AND survey_answer.question_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
886  $ilDB->quote($survey_id),
887  $ilDB->quote($this->getId())
888  );
889  $result = $ilDB->query($query);
890  while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
891  {
892  $category = $this->categories->getCategory($row["value"]);
893  if (!is_array($answers[$row["active_fi"]]))
894  {
895  $answers[$row["active_fi"]] = array();
896  }
897  array_push($answers[$row["active_fi"]], $row["value"] + 1 . " - " . $category);
898  }
899  return $answers;
900  }
901 
912  function importAdditionalMetadata($a_meta)
913  {
914  foreach ($a_meta as $key => $value)
915  {
916  switch ($value["label"])
917  {
918  case "orientation":
919  $this->setOrientation($value["entry"]);
920  break;
921  }
922  }
923  }
924 
933  function importResponses($a_data)
934  {
935  foreach ($a_data as $id => $data)
936  {
937  $categorytext = "";
938  foreach ($data["material"] as $material)
939  {
940  $categorytext .= $material["text"];
941  }
942  $this->categories->addCategory($categorytext);
943  }
944  }
945 
955  {
956  return TRUE;
957  }
958 
968  {
969  return array("=", "<>");
970  }
971 
980  function getPreconditionSelectValue($default = "")
981  {
982  global $lng;
983 
984  include_once "./classes/class.ilTemplate.php";
985  $template = new ilTemplate("tpl.il_svy_svy_precondition_select_value_combobox.html", TRUE, TRUE, "Modules/Survey");
986  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
987  {
988  $template->setCurrentBlock("option_v");
989  $template->setVariable("OPTION_VALUE", $i);
990  $template->setVariable("OPTION_TEXT", ($i+1) . " - " . $this->categories->getCategory($i));
991  if ($i == $default)
992  {
993  $template->setVariable("OPTION_CHECKED", " selected=\"selected\"");
994  }
995  $template->parseCurrentBlock();
996  }
997  $template->setVariable("SELECT_VALUE", $lng->txt("step") . " 3: " . $lng->txt("select_value"));
998  return $template->get();
999  }
1000 
1011  {
1012  return ($value + 1) . " - " . $this->categories->getCategory($value);
1013  }
1014 
1015 
1026  function outChart($survey_id, $type = "")
1027  {
1028  if (count($this->cumulated) == 0)
1029  {
1030  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
1032  $this->cumulated =& $this->getCumulatedResults($survey_id, $nr_of_users);
1033  }
1034 
1035  foreach ($this->cumulated["variables"] as $key => $value)
1036  {
1037  foreach ($value as $key2 => $value2)
1038  {
1039  $this->cumulated["variables"][$key][$key2] = utf8_decode($value2);
1040  }
1041  }
1042  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
1043  $b1 = new SurveyChart("bars",400,250,utf8_decode($this->getTitle()),utf8_decode($this->lng->txt("answers")),utf8_decode($this->lng->txt("users_answered")),$this->cumulated["variables"]);
1044  }
1045 }
1046 ?>