24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
27 define(
"SUBTYPE_MCSR", 1);
28 define(
"SUBTYPE_MCMR", 2);
86 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
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",
134 $result = $ilDB->query($query);
135 if ($result->numRows() == 1)
137 return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
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",
159 $result = $ilDB->query($query);
160 if ($result->numRows() == 1)
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");
174 $this->complete =
$data->complete;
175 $this->original_id =
$data->original_id;
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",
183 $result = $ilDB->query($query);
184 if ($result->numRows() > 0)
186 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
188 $this->categories->addCategory(
$data->title);
205 if (strlen($this->title) && strlen($this->author) && strlen($this->questiontext) && $this->categories->getCategoryCount())
222 function saveToDb($original_id =
"", $withanswers =
true)
232 $original_id = $ilDB->quote($original_id);
236 $original_id =
"NULL";
239 include_once(
"./Services/RTE/classes/class.ilRTE.php");
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),
256 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
257 $ilDB->quote(
"$complete"),
258 $ilDB->quote($created),
261 $result = $ilDB->query($query);
262 if (PEAR::isError($result))
265 $ilias->raiseError($result->getMessage());
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))
275 $ilDB->query($query);
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),
286 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
287 $ilDB->quote(
"$complete"),
288 $ilDB->quote($this->
id)
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 .
"")
296 $result = $ilDB->query($query);
301 $ilias->raiseError(
$result->getMessage());
320 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
321 $this->ilias->db->quote($this->id)
323 $result = $this->ilias->db->query($query);
325 for ($i = 0; $i < $this->categories->getCategoryCount(); $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 .
"")
334 $answer_result = $this->ilias->db->query($query);
347 function toXML($a_include_header = TRUE, $obligatory_state =
"")
349 include_once(
"./classes/class.ilXmlWriter.php");
352 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
353 $xml = $a_xml_writer->xmlDumpMem(FALSE);
354 if (!$a_include_header)
356 $pos = strpos($xml,
"?>");
357 $xml = substr($xml, $pos + 2);
372 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
375 "id" => $this->
getId(),
377 "type" => $this->getQuestiontype(),
381 $a_xml_writer->xmlStartTag(
"question", $attrs);
383 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
384 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
385 $a_xml_writer->xmlStartTag(
"questiontext");
387 $a_xml_writer->xmlEndTag(
"questiontext");
389 $a_xml_writer->xmlStartTag(
"responses");
391 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
399 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
402 $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
405 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
409 $a_xml_writer->xmlEndTag(
"response_single");
412 $a_xml_writer->xmlEndTag(
"response_multiple");
417 $a_xml_writer->xmlEndTag(
"responses");
419 if (count($this->material))
421 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
424 "label" => $this->material[
"title"]
426 $a_xml_writer->xmlStartTag(
"material", $attrs);
427 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
428 if (strcmp($matches[1],
"") != 0)
430 $intlink = $this->material[
"internal_link"];
432 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
433 $a_xml_writer->xmlEndTag(
"material");
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");
444 $a_xml_writer->xmlEndTag(
"question");
450 if ($this->original_id)
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 .
"")
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 .
"")
472 $result = $ilDB->query($query);
473 if (PEAR::isError($result))
476 $ilias->raiseError($result->getMessage());
483 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
484 $ilDB->quote($this->original_id .
"")
486 $result = $ilDB->query($query);
489 for ($i = 0; $i < $this->categories->getCategoryCount(); $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 .
"")
498 $answer_result = $ilDB->query($query);
515 return "SurveyNominalQuestion";
528 return "survey_question_nominal";
541 $entered_value = $post_data[$this->
getId() .
"_value"];
545 if (is_array($entered_value))
547 foreach ($entered_value as $value)
549 array_push(
$data, array(
"value" => $value));
555 array_push(
$data, array(
"value" => $entered_value));
576 $entered_value = $post_data[$this->
getId() .
"_value"];
581 if (!is_array($entered_value))
583 return $this->lng->txt(
"nominal_question_mr_not_checked");
590 if (strlen($entered_value) == 0)
return $this->lng->txt(
"nominal_question_not_checked");
606 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
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),
615 $result = $ilDB->query($query);
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)
628 $result = $ilDB->query($query);
636 if (is_array($post_data[$this->
getId() .
"_value"]))
638 foreach ($post_data[$this->
getId() .
"_value"] as $value)
640 $entered_value = $value;
641 if (strlen($entered_value) > 0)
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 .
""),
650 $result = $ilDB->query($query);
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 .
""),
665 $result = $ilDB->query($query);
673 $question_id = $this->
getId();
675 $result_array = array();
676 $cumulated = array();
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),
682 $result = $ilDB->query($query);
683 $numrows = $result->numRows();
686 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
688 $cumulated[
"$row->value"]++;
690 asort($cumulated, SORT_NUMERIC);
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),
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();
706 $result_array[
"USERS_ANSWERED"] = $result->numRows();
707 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
709 $result_array[
"MEDIAN"] =
"";
710 $result_array[
"ARITHMETIC_MEAN"] =
"";
712 if (strcmp(key($cumulated),
"") != 0)
714 $prefix = (key($cumulated)+1) .
" - ";
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";
721 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
723 $maxvalues += $cumulated[$key];
725 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
734 $percentage = ($result_array[
"USERS_ANSWERED"] > 0) ? (
float)((int)$cumulated[$key]/$result_array[
"USERS_ANSWERED"]) : 0;
739 $percentage = ($numrows > 0) ? (
float)((int)$cumulated[$key]/$numrows) : 0;
742 $result_array[
"variables"][$key] = array(
"title" => $this->categories->getCategory($key),
"selected" => (int)$cumulated[$key],
"percentage" => $percentage);
744 return $result_array;
760 include_once (
"./classes/class.ilExcelUtils.php");
761 $worksheet =& $workbook->addWorksheet();
769 $worksheet->write(3, 1, $eval_data[
"USERS_ANSWERED"]);
771 $worksheet->write(4, 1, $eval_data[
"USERS_SKIPPED"]);
785 foreach ($eval_data[
"variables"] as $key => $value)
788 $worksheet->write($rowcounter, 2, $key+1);
807 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
809 $category = $this->categories->getCategory($index);
810 array_push($a_array, ($index+1) .
" - $category");
826 if (count($resultset[
"answers"][$this->
getId()]))
830 array_push($a_array,
"");
831 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
833 $category = $this->categories->getCategory($index);
835 foreach ($resultset[
"answers"][$this->
getId()] as $answerdata)
837 if (strcmp($index, $answerdata[
"value"]) == 0)
844 array_push($a_array,
"1");
848 array_push($a_array,
"0");
854 array_push($a_array, $resultset[
"answers"][$this->
getId()][0][
"value"]+1);
859 array_push($a_array, $this->lng->txt(
"skipped"));
862 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
864 array_push($a_array,
"");
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",
887 $ilDB->quote($this->
getId())
889 $result = $ilDB->query($query);
890 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
892 $category = $this->categories->getCategory($row[
"value"]);
893 if (!is_array($answers[$row[
"active_fi"]]))
895 $answers[$row[
"active_fi"]] = array();
897 array_push($answers[$row[
"active_fi"]], $row[
"value"] + 1 .
" - " . $category);
914 foreach ($a_meta as $key => $value)
916 switch ($value[
"label"])
940 $categorytext .= $material[
"text"];
942 $this->categories->addCategory($categorytext);
969 return array(
"=",
"<>");
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++)
988 $template->setCurrentBlock(
"option_v");
989 $template->setVariable(
"OPTION_VALUE", $i);
990 $template->setVariable(
"OPTION_TEXT", ($i+1) .
" - " . $this->categories->getCategory($i));
993 $template->setVariable(
"OPTION_CHECKED",
" selected=\"selected\"");
995 $template->parseCurrentBlock();
997 $template->setVariable(
"SELECT_VALUE", $lng->txt(
"step") .
" 3: " . $lng->txt(
"select_value"));
998 return $template->get();
1012 return ($value + 1) .
" - " . $this->categories->getCategory($value);
1028 if (count($this->cumulated) == 0)
1030 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
1035 foreach ($this->cumulated[
"variables"] as $key => $value)
1037 foreach ($value as $key2 => $value2)
1039 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
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"]);