24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
67 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
88 return $ilDB->fetchAssoc(
$result);
115 $this->label =
$data[
'label'];
120 include_once(
"./Services/RTE/classes/class.ilRTE.php");
126 $this->use_min_answers = (
$data[
'use_min_answers']) ?
true :
false;
127 $this->nr_min_answers =
$data[
'nr_min_answers'];
128 $this->nr_max_answers =
$data[
'nr_max_answers'];
130 $this->categories->flushCategories();
131 $result = $ilDB->queryF(
"SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
139 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"], null, (
$data[
'scale']) ?
$data[
'scale'] : (
$data[
'sequence'] + 1));
158 $this->categories->getCategoryCount()
179 if ($affectedRows == 1)
181 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
183 array($this->
getId())
185 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, orientation, use_min_answers, nr_min_answers, nr_max_answers) VALUES (%s, %s, %s, %s, %s)",
186 array(
'integer',
'text',
'integer',
'integer',
'integer'),
190 ($this->use_min_answers) ? 1 : 0,
191 ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
192 ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
206 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
208 array($this->
getId())
211 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
213 $cat = $this->categories->getCategory($i);
215 $next_id = $ilDB->nextId(
'svy_variable');
216 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
217 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
218 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
230 function toXML($a_include_header = TRUE, $obligatory_state =
"")
232 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
235 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
236 $xml = $a_xml_writer->xmlDumpMem(FALSE);
237 if (!$a_include_header)
239 $pos = strpos($xml,
"?>");
240 $xml = substr($xml, $pos + 2);
253 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
256 "id" => $this->
getId(),
258 "type" => $this->getQuestiontype(),
261 $a_xml_writer->xmlStartTag(
"question", $attrs);
263 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
264 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
265 if (strlen($this->label))
268 "label" => $this->label,
275 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
277 $a_xml_writer->xmlEndTag(
"questiontext");
279 $a_xml_writer->xmlStartTag(
"responses");
281 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
286 if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
287 if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
288 if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
289 if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
290 $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
291 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
292 $a_xml_writer->xmlEndTag(
"response_multiple");
295 $a_xml_writer->xmlEndTag(
"responses");
297 if (count($this->material))
299 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
302 "label" => $this->material[
"title"]
304 $a_xml_writer->xmlStartTag(
"material", $attrs);
305 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
306 if (strcmp($matches[1],
"") != 0)
308 $intlink = $this->material[
"internal_link"];
310 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
311 $a_xml_writer->xmlEndTag(
"material");
315 $a_xml_writer->xmlStartTag(
"metadata");
316 $a_xml_writer->xmlStartTag(
"metadatafield");
317 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"orientation");
318 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
319 $a_xml_writer->xmlEndTag(
"metadatafield");
320 $a_xml_writer->xmlStartTag(
"metadatafield");
321 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"use_min_answers");
322 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->use_min_answers);
323 $a_xml_writer->xmlEndTag(
"metadatafield");
324 $a_xml_writer->xmlStartTag(
"metadatafield");
325 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"nr_min_answers");
326 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_min_answers);
327 $a_xml_writer->xmlEndTag(
"metadatafield");
328 $a_xml_writer->xmlStartTag(
"metadatafield");
329 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"nr_max_answers");
330 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_max_answers);
331 $a_xml_writer->xmlEndTag(
"metadatafield");
332 $a_xml_writer->xmlEndTag(
"metadata");
334 $a_xml_writer->xmlEndTag(
"question");
345 return "SurveyMultipleChoiceQuestion";
367 $entered_value = $post_data[$this->
getId() .
"_value"];
369 if (is_array($entered_value))
371 foreach ($entered_value as $idx => $value)
373 array_push(
$data, array(
"value" => $value,
"textanswer" => $post_data[$this->
getId() .
'_' . $value .
'_other']));
376 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
378 $cat = $this->categories->getCategory($i);
381 if (!in_array($i, $entered_value))
383 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
385 array_push(
$data, array(
"value" => $i,
"textanswer" => $post_data[$this->
getId() .
'_' . $i .
'_other'],
"uncheck" =>
true));
404 $entered_value = $post_data[$this->
getId() .
"_value"];
407 if ($this->use_min_answers && $this->nr_min_answers > 0 && $this->nr_max_answers > 0 && $this->nr_min_answers == $this->nr_max_answers && count($entered_value) != $this->nr_max_answers)
409 return sprintf($this->lng->txt(
"err_no_exact_answers"), $this->nr_min_answers);
411 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers)
413 return sprintf($this->lng->txt(
"err_no_min_answers"), $this->nr_min_answers);
415 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers)
417 return sprintf($this->lng->txt(
"err_no_max_answers"), $this->nr_max_answers);
419 if (!is_array($entered_value))
421 return $this->lng->txt(
"question_mr_not_checked");
423 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
425 $cat = $this->categories->getCategory($i);
428 if (in_array($i, $entered_value))
430 if (array_key_exists($this->
getId() .
"_" . $i .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
432 return $this->lng->txt(
"question_mr_no_other_answer");
437 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
439 return $this->lng->txt(
"question_mr_no_other_answer_checked");
456 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
460 $cat = $this->categories->getCategory($i);
461 $next_id = $ilDB->nextId(
'svy_answer');
462 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
463 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
464 array($next_id, $this->
getId(), $active_id, $i, ($cat->other) ?
"Random Data" : null, time())
476 $return_data = array();
478 if (is_array($post_data[$this->
getId() .
"_value"]))
480 foreach ($post_data[$this->
getId() .
"_value"] as $entered_value)
482 if (strlen($entered_value) > 0)
486 $next_id = $ilDB->nextId(
'svy_answer');
487 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
488 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
489 array($next_id, $this->
getId(), $active_id, (strlen($entered_value)) ? $entered_value : NULL, ($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ? $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] : null, time())
494 $return_data[] = array(
"value"=>$entered_value,
495 "textanswer"=>$post_data[$this->
getId() .
"_" . $entered_value .
"_other"]);
510 $question_id = $this->
getId();
512 $result_array = array();
515 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
516 array(
'integer',
'integer'),
522 $textanswers = array();
528 if ($row[
"textanswer"])
530 $textanswers[$row[
"value"]][] = $row[
"textanswer"];
534 if (is_array($textanswers))
536 ksort($textanswers, SORT_NUMERIC);
541 $mcmr_result = $ilDB->queryF(
"SELECT svy_answer.answer_id, svy_answer.question_fi, svy_answer.active_fi FROM svy_answer, svy_finished WHERE svy_answer.question_fi = %s AND svy_finished.survey_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
542 array(
'integer',
'integer'),
546 while (
$row = $ilDB->fetchAssoc($mcmr_result))
548 $found[
$row[
"question_fi"] .
"_" .
$row[
"active_fi"]] = 1;
550 $result_array[
"USERS_ANSWERED"] = count($found);
551 $result_array[
"USERS_SKIPPED"] = $nr_of_users - count($found);
552 $numrows = count($found);
554 $result_array[
"MEDIAN"] =
"";
555 $result_array[
"ARITHMETIC_MEAN"] =
"";
561 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
562 $result_array[
"MODE"] = $prefix . $category->title;
563 $result_array[
"MODE_VALUE"] = key(
$cumulated)+1;
565 $result_array[
"QUESTION_TYPE"] =
"SurveyMultipleChoiceQuestion";
567 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
569 $cat = $this->categories->getCategory($key);
572 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
574 $cat = $this->categories->getCategory($key);
580 $percentage = ($maxvalues > 0) ? (
float)((int)
$cumulated[$cat->scale-1]/$maxvalues) : 0;
583 if(isset($textanswers[$cat->scale-1]))
586 $result_array[
"textanswers"][$key] = $textanswers[$cat->scale-1];
588 $result_array[
"variables"][$key] = array(
"title" => $cat->title,
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
590 return $result_array;
604 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
605 $worksheet =& $workbook->addWorksheet();
607 switch ($export_label)
633 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
636 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
650 foreach ($eval_data[
"variables"] as $key => $value)
653 $category = $this->categories->getCategory($key);
654 $worksheet->write($rowcounter, 2, $category->scale);
660 if (is_array($eval_data[
"textanswers"]))
666 foreach ($eval_data[
"textanswers"] as $key => $answers)
668 $title = $eval_data[
"variables"][$key][
"title"];
669 foreach ($answers as $answer)
688 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
690 $category = $this->categories->getCategory($index);
691 $title = $category->title;
693 if(!$a_use_label || $a_substitute)
695 array_push($a_array,
$title);
699 array_push($a_array,
"");
703 if ($category->other)
705 if(!$a_use_label || $a_substitute)
707 array_push($a_array,
$title .
" - ". $this->lng->txt(
"other"));
711 array_push($a_array,
"");
726 if (count($resultset[
"answers"][$this->
getId()]))
728 array_push($a_array,
"");
729 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
731 $category = $this->categories->getCategory($index);
732 $incoming_value = $category->scale ? $category->scale-1 : $index;
736 foreach ($resultset[
"answers"][$this->
getId()] as $answerdata)
738 if (strcmp($incoming_value, $answerdata[
"value"]) == 0)
740 $found = $answerdata[
"value"]+1;
741 $textanswer = $answerdata[
"textanswer"];
746 array_push($a_array, $found);
750 array_push($a_array,
"0");
752 if ($category->other)
754 array_push($a_array, $textanswer);
760 array_push($a_array, $this->lng->txt(
"skipped"));
761 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
763 array_push($a_array,
"");
766 $category = $this->categories->getCategory($index);
767 if ($category->other)
769 array_push($a_array,
"");
788 $result = $ilDB->queryF(
"SELECT svy_answer.* FROM svy_answer, svy_finished WHERE svy_finished.survey_fi = %s AND svy_answer.question_fi = %s AND svy_finished.finished_id = svy_answer.active_fi",
789 array(
'integer',
'integer'),
794 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
795 if (!is_array($answers[
$row[
"active_fi"]]))
797 $answers[$row[
"active_fi"]] = array();
799 $title = $row[
"value"] + 1 .
" - " . $category->title;
800 if ($category->other)
$title .=
": " . $row[
"textanswer"];
801 $catindex = $this->categories->getIndex($category);
802 if ($catindex !== null)
804 $answers[$row[
"active_fi"]][$catindex] =
$title;
808 array_push($answers[$row[
"active_fi"]],
$title);
810 ksort($answers[$row[
"active_fi"]], SORT_NUMERIC);
825 foreach ($a_meta as $key => $value)
827 switch ($value[
"label"])
832 case "use_min_answers":
833 $this->use_min_answers = $value[
"entry"];
835 case "nr_min_answers":
836 $this->nr_min_answers = $value[
"entry"];
838 case "nr_max_answers":
839 $this->nr_max_answers = $value[
"entry"];
858 $categorytext .= $material[
"text"];
860 $this->categories->addCategory(
863 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
864 strlen($data[
'label']) ? $data[
'label'] : null,
865 strlen($data[
'scale']) ? $data[
'scale'] : null
889 return array(
"=",
"<>");
902 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
904 $category = $this->categories->getCategory($i);
905 $options[$category->scale-1] = $category->scale .
" - " . $category->title;
918 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
921 $step3->setOptions($options);
922 $step3->setValue($default);
935 $category = $this->categories->getCategory($value);
936 return ($value + 1) .
" - " . ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));