24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
68 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
84 $result = $ilDB->queryF(
"SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
88 while (
$row = $ilDB->fetchAssoc($result))
90 if ((
$row[
"defaultvalue"] == 1) and (
$row[
"owner_fi"] == 0))
113 $result = $ilDB->queryF(
"SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = 0 OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
114 array(
'integer',
'integer'),
115 array($phrase_id, $ilUser->getId())
117 while (
$row = $ilDB->fetchAssoc($result))
119 if ((
$row[
"defaultvalue"] == 1) and (
$row[
"owner_fi"] == 0))
121 $this->categories->addCategory($this->lng->txt(
$row[
"title"]));
125 $this->categories->addCategory(
$row[
"title"]);
145 if ($result->numRows() == 1)
147 return $ilDB->fetchAssoc($result);
169 if ($result->numRows() == 1)
171 $data = $ilDB->fetchAssoc($result);
174 $this->label =
$data[
'label'];
179 include_once(
"./Services/RTE/classes/class.ilRTE.php");
186 $this->categories->flushCategories();
187 $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",
191 if ($result->numRows() > 0)
193 while (
$data = $ilDB->fetchAssoc($result))
195 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"], null, (
$data[
'scale']) ?
$data[
'scale'] : (
$data[
'sequence'] + 1));
210 if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
230 if ($affectedRows == 1)
232 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
234 array($this->
getId())
236 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, orientation) VALUES (%s, %s)",
237 array(
'integer',
'text'),
253 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
255 array($this->
getId())
258 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
260 $cat = $this->categories->getCategory($i);
262 $next_id = $ilDB->nextId(
'svy_variable');
263 $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)",
264 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
265 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
277 function toXML($a_include_header = TRUE, $obligatory_state =
"")
279 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
282 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
283 $xml = $a_xml_writer->xmlDumpMem(FALSE);
284 if (!$a_include_header)
286 $pos = strpos($xml,
"?>");
287 $xml = substr($xml,
$pos + 2);
300 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
303 "id" => $this->
getId(),
305 "type" => $this->getQuestiontype(),
308 $a_xml_writer->xmlStartTag(
"question", $attrs);
310 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
311 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
312 if (strlen($this->label))
315 "label" => $this->label,
322 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
324 $a_xml_writer->xmlEndTag(
"questiontext");
326 $a_xml_writer->xmlStartTag(
"responses");
328 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
333 if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
334 if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
335 if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
336 if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
337 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
338 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
339 $a_xml_writer->xmlEndTag(
"response_single");
342 $a_xml_writer->xmlEndTag(
"responses");
344 if (count($this->material))
346 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
349 "label" => $this->material[
"title"]
351 $a_xml_writer->xmlStartTag(
"material", $attrs);
352 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
353 if (strcmp($matches[1],
"") != 0)
355 $intlink = $this->material[
"internal_link"];
357 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
358 $a_xml_writer->xmlEndTag(
"material");
362 $a_xml_writer->xmlStartTag(
"metadata");
363 $a_xml_writer->xmlStartTag(
"metadatafield");
364 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"orientation");
365 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
366 $a_xml_writer->xmlEndTag(
"metadatafield");
367 $a_xml_writer->xmlEndTag(
"metadata");
369 $a_xml_writer->xmlEndTag(
"question");
382 foreach ($a_meta as $key => $value)
384 switch ($value[
"label"])
402 for ($i = $lower_limit; $i <= $upper_limit; $i++)
404 $this->categories->addCategory($i);
420 $next_id = $ilDB->nextId(
'svy_phrase');
421 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
422 array(
'integer',
'text',
'text',
'integer',
'integer'),
423 array($next_id,
$title, 1, $ilUser->getId(), time())
425 $phrase_id = $next_id;
430 $next_id = $ilDB->nextId(
'svy_category');
431 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
432 array(
'integer',
'text',
'text',
'integer',
'integer'),
433 array($next_id, $data[
'answer'], 1, $ilUser->getId(), time())
435 $category_id = $next_id;
436 $next_id = $ilDB->nextId(
'svy_phrase_cat');
437 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
438 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
439 array($next_id, $phrase_id, $category_id, $counter, ($data[
'other']) ? 1 : 0, $data[
'scale'])
453 return "SurveySingleChoiceQuestion";
475 $entered_value = $post_data[$this->
getId() .
"_value"];
477 if (strlen($entered_value))
479 array_push(
$data, array(
"value" => $entered_value,
"textanswer" => $post_data[$this->
getId() .
'_' . $entered_value .
'_other']));
481 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
483 $cat = $this->categories->getCategory($i);
486 if ($i != $entered_value)
488 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
490 array_push(
$data, array(
"value" => $i,
"textanswer" => $post_data[$this->
getId() .
'_' . $i .
'_other'],
"uncheck" =>
true));
509 $entered_value = $post_data[$this->
getId() .
"_value"];
513 if (strlen($entered_value) == 0)
return $this->lng->txt(
"question_not_checked");
515 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
517 $cat = $this->categories->getCategory($i);
520 if ($i == $entered_value)
522 if (array_key_exists($this->
getId() .
"_" . $entered_value .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]))
524 return $this->lng->txt(
"question_mr_no_other_answer");
529 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
531 return $this->lng->txt(
"question_sr_no_other_answer_checked");
549 $category = rand(0, $this->categories->getCategoryCount()-1);
550 $cat = $this->categories->getCategory($category);
551 $next_id = $ilDB->nextId(
'svy_answer');
552 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
553 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
554 array($next_id, $this->
getId(), $active_id, $category, ($cat->other) ?
"Random Data" : null, time())
562 $entered_value = $post_data[$this->
getId() .
"_value"];
563 if (strlen($entered_value) == 0)
return;
564 $next_id = $ilDB->nextId(
'svy_answer');
565 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
566 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
567 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())
575 $question_id = $this->
getId();
577 $result_array = array();
580 $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",
581 array(
'integer',
'integer'),
585 while (
$row = $ilDB->fetchAssoc($result))
590 if ($row[
"textanswer"])
592 $result_array[
"textanswers"][$row[
"value"]][] = $row[
"textanswer"];
596 if (is_array($result_array[
"textanswers"]))
598 ksort($result_array[
"textanswers"], SORT_NUMERIC);
602 $numrows = $result->numRows();
603 $result_array[
"USERS_ANSWERED"] = $result->numRows();
604 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
611 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
612 $result_array[
"MODE"] = $prefix . $category->title;
613 $result_array[
"MODE_VALUE"] = key(
$cumulated)+1;
615 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
617 $cat = $this->categories->getCategory($key);
621 $percentage = (float)((
int)
$cumulated[$cat->scale-1]/$numrows);
625 $result_array[
"variables"][$key] = array(
"title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt(
'other_answer'),
"selected" => (int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
629 $result_array[
"variables"][$key] = array(
"title" => $cat->title,
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
638 for ($i = 0; $i < $key; $i++)
640 array_push($median, $value+1);
647 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
648 if (round($median_value) != $median_value)
650 $median_value = $median_value .
"<br />" .
"(" . $this->lng->txt(
"median_between") .
" " . (floor($median_value)) .
"-" . $this->categories->getCategory((
int)floor($median_value)-1)->title .
" " . $this->lng->txt(
"and") .
" " . (ceil($median_value)) .
"-" . $this->categories->getCategory((
int)ceil($median_value)-1)->title .
")";
655 $median_value = $median[((
$total+1)/2)-1];
662 $result_array[
"ARITHMETIC_MEAN"] =
"";
663 $result_array[
"MEDIAN"] = $median_value;
664 $result_array[
"QUESTION_TYPE"] =
"SurveySingleChoiceQuestion";
665 return $result_array;
677 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
678 $adapter->addWorksheet($this->
getTitle());
679 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
681 switch ($export_label)
685 $adapter->setCellValue(0, 1, $this->label);
689 $adapter->setCellValue(0, 1, $this->
getTitle());
693 $adapter->setCellValue(0, 1, $this->
getTitle());
695 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"label"),
CELL_FORMAT_BOLD);
696 $adapter->setCellValue($rowcounter, 1, $this->label);
700 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question"),
CELL_FORMAT_BOLD);
703 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question_type"),
CELL_FORMAT_BOLD);
704 $adapter->setCellValue($rowcounter, 1, $this->lng->txt($this->getQuestionType()));
706 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_answered"),
CELL_FORMAT_BOLD);
707 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_ANSWERED"]);
709 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_skipped"),
CELL_FORMAT_BOLD);
710 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_SKIPPED"]);
713 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
714 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode"),
CELL_FORMAT_BOLD);
715 $adapter->setCellValue($rowcounter++, 1, $matches[1]);
716 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode_text"),
CELL_FORMAT_BOLD);
717 $adapter->setCellValue($rowcounter++, 1, $matches[2]);
718 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"mode_nr_of_selections"),
CELL_FORMAT_BOLD);
719 $adapter->setCellValue($rowcounter++, 1, $eval_data[
"MODE_NR_OF_SELECTIONS"]);
720 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"median"),
CELL_FORMAT_BOLD);
721 $adapter->setCellValue($rowcounter++, 1, str_replace(
"<br />",
" ", $eval_data[
"MEDIAN"]));
722 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"categories"),
CELL_FORMAT_BOLD);
723 $adapter->setCellValue($rowcounter, 1, $this->lng->txt(
"title"),
CELL_FORMAT_TITLE);
724 $adapter->setCellValue($rowcounter, 2, $this->lng->txt(
"value"),
CELL_FORMAT_TITLE);
725 $adapter->setCellValue($rowcounter, 3, $this->lng->txt(
"category_nr_selected"),
CELL_FORMAT_TITLE);
726 $adapter->setCellValue($rowcounter++, 4, $this->lng->txt(
"percentage_of_selections"),
CELL_FORMAT_TITLE);
728 foreach ($eval_data[
"variables"] as $key => $value)
730 $adapter->setCellValue($rowcounter, 1, $value[
"title"]);
731 $category = $this->categories->getCategory($key);
732 $adapter->setCellValue($rowcounter, 2, $category->scale);
733 $adapter->setCellValue($rowcounter, 3, $value[
"selected"]);
738 if (is_array($eval_data[
"textanswers"]))
740 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"freetext_answers"),
CELL_FORMAT_BOLD);
741 $adapter->setCellValue($rowcounter, 1, $this->lng->txt(
"title"),
CELL_FORMAT_TITLE);
742 $adapter->setCellValue($rowcounter++, 2, $this->lng->txt(
"answer"),
CELL_FORMAT_TITLE);
744 foreach ($eval_data[
"textanswers"] as $key => $answers)
746 $title = $eval_data[
"variables"][$key][
"title"];
747 foreach ($answers as $answer)
749 $adapter->setCellValue($rowcounter, 1,
$title);
750 $adapter->setCellValue($rowcounter++, 2, $answer);
767 switch($a_export_label)
781 array_push($a_array,
$title);
784 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
786 $cat = $this->categories->getCategory($i);
789 array_push($a_array,
$title.
' - '. $this->lng->txt(
'other'));
806 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
808 $cat = $this->categories->getCategory($i);
817 if (count($resultset[
"answers"][$this->
getId()]))
819 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
821 array_push($a_array, $answer[
"value"]+1);
824 array_push($a_array, $answer[
"textanswer"]);
830 array_push($a_array, $this->lng->txt(
"skipped"));
833 array_push($a_array,
"");
851 $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",
852 array(
'integer',
'integer'),
855 while (
$row = $ilDB->fetchAssoc($result))
857 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
858 $title =
$row[
"value"] + 1 .
" - " . $category->title;
859 if ($category->other)
$title .=
": " .
$row[
"textanswer"];
878 $categorytext .= $material[
"text"];
880 $this->categories->addCategory(
883 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
884 strlen($data[
'label']) ? $data[
'label'] : null,
885 strlen($data[
'scale']) ? $data[
'scale'] : null
909 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
922 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
924 $category = $this->categories->getCategory($i);
925 $options[$i] = ($i+1) .
" - " . $category->title;
938 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
941 $step3->setOptions($options);
942 $step3->setValue($default);
955 $category = $this->categories->getCategory($value);
956 return ($value + 1) .
" - " . ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
969 if (count($this->cumulated) == 0)
971 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
976 foreach ($this->cumulated[
"variables"] as $key => $value)
978 foreach ($value as $key2 => $value2)
980 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
983 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
984 $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"]);