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",
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())
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"]);
147 return $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",
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'),
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);
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;
679 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
680 $worksheet =& $workbook->addWorksheet();
682 switch ($export_label)
708 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
711 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
714 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
729 foreach ($eval_data[
"variables"] as $key => $value)
732 $category = $this->categories->getCategory($key);
733 $worksheet->write($rowcounter, 2, $category->scale);
739 if (is_array($eval_data[
"textanswers"]))
745 foreach ($eval_data[
"textanswers"] as $key => $answers)
747 $title = $eval_data[
"variables"][$key][
"title"];
748 foreach ($answers as $answer)
768 switch($a_export_label)
782 array_push($a_array,
$title);
785 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
787 $cat = $this->categories->getCategory($i);
790 array_push($a_array,
$title.
' - '. $this->lng->txt(
'other'));
807 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
809 $cat = $this->categories->getCategory($i);
818 if (count($resultset[
"answers"][$this->
getId()]))
820 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
822 array_push($a_array, $answer[
"value"]+1);
825 array_push($a_array, $answer[
"textanswer"]);
831 array_push($a_array, $this->lng->txt(
"skipped"));
834 array_push($a_array,
"");
852 $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",
853 array(
'integer',
'integer'),
858 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
859 $title =
$row[
"value"] + 1 .
" - " . $category->title;
860 if ($category->other)
$title .=
": " .
$row[
"textanswer"];
879 $categorytext .= $material[
"text"];
881 $this->categories->addCategory(
884 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
885 strlen($data[
'label']) ? $data[
'label'] : null,
886 strlen($data[
'scale']) ? $data[
'scale'] : null
910 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
923 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
925 $category = $this->categories->getCategory($i);
926 $options[$i] = ($i+1) .
" - " . $category->title;
939 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
942 $step3->setOptions($options);
943 $step3->setValue($default);
956 $category = $this->categories->getCategory($value);
957 return ($value + 1) .
" - " . ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));
970 if (count($this->cumulated) == 0)
972 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
977 foreach ($this->cumulated[
"variables"] as $key => $value)
979 foreach ($value as $key2 => $value2)
981 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
984 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
985 $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"]);