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 $neutral =
$row[
"neutral"];
120 if ((
$row[
"defaultvalue"] == 1) and (
$row[
"owner_fi"] == 0))
122 $this->categories->addCategory($this->lng->txt(
$row[
"title"]), 0, $neutral);
126 $this->categories->addCategory(
$row[
"title"], 0, $neutral);
148 return $ilDB->fetchAssoc(
$result);
175 $this->label =
$data[
'label'];
180 include_once(
"./Services/RTE/classes/class.ilRTE.php");
187 $this->categories->flushCategories();
188 $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",
196 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"], null, (
$data[
'scale']) ?
$data[
'scale'] : (
$data[
'sequence'] + 1));
215 $this->categories->getCategoryCount()
236 if ($affectedRows == 1)
238 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
240 array($this->
getId())
242 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, orientation) VALUES (%s, %s)",
243 array(
'integer',
'text'),
259 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
261 array($this->
getId())
264 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
266 $cat = $this->categories->getCategory($i);
268 $next_id = $ilDB->nextId(
'svy_variable');
269 $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)",
270 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
271 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
283 function toXML($a_include_header = TRUE, $obligatory_state =
"")
285 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
288 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
289 $xml = $a_xml_writer->xmlDumpMem(FALSE);
290 if (!$a_include_header)
292 $pos = strpos($xml,
"?>");
293 $xml = substr($xml, $pos + 2);
306 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
309 "id" => $this->
getId(),
311 "type" => $this->getQuestiontype(),
314 $a_xml_writer->xmlStartTag(
"question", $attrs);
316 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
317 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
318 if (strlen($this->label))
321 "label" => $this->label,
328 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
330 $a_xml_writer->xmlEndTag(
"questiontext");
332 $a_xml_writer->xmlStartTag(
"responses");
334 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
339 if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
340 if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
341 if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
342 if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
343 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
344 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
345 $a_xml_writer->xmlEndTag(
"response_single");
348 $a_xml_writer->xmlEndTag(
"responses");
350 if (count($this->material))
352 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
355 "label" => $this->material[
"title"]
357 $a_xml_writer->xmlStartTag(
"material", $attrs);
358 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
359 if (strcmp($matches[1],
"") != 0)
361 $intlink = $this->material[
"internal_link"];
363 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
364 $a_xml_writer->xmlEndTag(
"material");
368 $a_xml_writer->xmlStartTag(
"metadata");
369 $a_xml_writer->xmlStartTag(
"metadatafield");
370 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"orientation");
371 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
372 $a_xml_writer->xmlEndTag(
"metadatafield");
373 $a_xml_writer->xmlEndTag(
"metadata");
375 $a_xml_writer->xmlEndTag(
"question");
388 foreach ($a_meta as $key => $value)
390 switch ($value[
"label"])
408 for ($i = $lower_limit; $i <= $upper_limit; $i++)
410 $this->categories->addCategory($i);
426 $next_id = $ilDB->nextId(
'svy_phrase');
427 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
428 array(
'integer',
'text',
'text',
'integer',
'integer'),
429 array($next_id,
$title, 1, $ilUser->getId(), time())
431 $phrase_id = $next_id;
436 $next_id = $ilDB->nextId(
'svy_category');
437 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
438 array(
'integer',
'text',
'text',
'integer',
'integer',
'text'),
439 array($next_id, $data[
'answer'], 1, $ilUser->getId(), time(), $data[
'neutral'])
441 $category_id = $next_id;
442 $next_id = $ilDB->nextId(
'svy_phrase_cat');
443 $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)",
444 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
445 array($next_id, $phrase_id, $category_id, $counter, ($data[
'other']) ? 1 : 0, $data[
'scale'])
459 return "SurveySingleChoiceQuestion";
481 $entered_value = $post_data[$this->
getId() .
"_value"];
483 if (strlen($entered_value))
485 array_push(
$data, array(
"value" => $entered_value,
"textanswer" => $post_data[$this->
getId() .
'_' . $entered_value .
'_other']));
487 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
489 $cat = $this->categories->getCategory($i);
492 if ($i != $entered_value)
494 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
496 array_push(
$data, array(
"value" => $i,
"textanswer" => $post_data[$this->
getId() .
'_' . $i .
'_other'],
"uncheck" =>
true));
515 $entered_value = $post_data[$this->
getId() .
"_value"];
519 if (strlen($entered_value) == 0)
return $this->lng->txt(
"question_not_checked");
521 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
523 $cat = $this->categories->getCategory($i);
526 if ($i == $entered_value)
528 if (array_key_exists($this->
getId() .
"_" . $entered_value .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]))
530 return $this->lng->txt(
"question_mr_no_other_answer");
535 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"]))
537 return $this->lng->txt(
"question_sr_no_other_answer_checked");
555 $category = rand(0, $this->categories->getCategoryCount()-1);
556 $cat = $this->categories->getCategory($category);
557 $next_id = $ilDB->nextId(
'svy_answer');
558 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
559 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
560 array($next_id, $this->
getId(), $active_id, $category, ($cat->other) ?
"Random Data" : null, time())
568 $entered_value = $post_data[$this->
getId() .
"_value"];
572 return array(array(
"value"=>$entered_value,
573 "textanswer"=>$post_data[$this->
getId() .
"_" . $entered_value .
"_other"]));
575 if (strlen($entered_value) == 0)
return;
577 $next_id = $ilDB->nextId(
'svy_answer');
578 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
579 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
580 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())
588 $question_id = $this->
getId();
590 $result_array = array();
593 $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",
594 array(
'integer',
'integer'),
603 if ($row[
"textanswer"])
605 $result_array[
"textanswers"][$row[
"value"]][] = $row[
"textanswer"];
609 if (is_array($result_array[
"textanswers"]))
611 ksort($result_array[
"textanswers"], SORT_NUMERIC);
616 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
617 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
624 $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
625 $result_array[
"MODE"] = $prefix . $category->title;
626 $result_array[
"MODE_VALUE"] = key(
$cumulated)+1;
628 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
630 $cat = $this->categories->getCategory($key);
634 $percentage = (float)((
int)
$cumulated[$cat->scale-1]/$numrows);
638 $result_array[
"variables"][$key] = array(
"title" => (strlen($cat->title)) ? $cat->title : $this->lng->txt(
'other_answer'),
"selected" => (int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
642 $result_array[
"variables"][$key] = array(
"title" => $cat->title,
"selected" => (
int)
$cumulated[$cat->scale-1],
"percentage" => $percentage);
651 for ($i = 0; $i < $key; $i++)
653 array_push($median, $value+1);
660 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
661 if (round($median_value) != $median_value)
663 $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 .
")";
668 $median_value = $median[((
$total+1)/2)-1];
675 $result_array[
"ARITHMETIC_MEAN"] =
"";
676 $result_array[
"MEDIAN"] = $median_value;
677 $result_array[
"QUESTION_TYPE"] =
"SurveySingleChoiceQuestion";
678 return $result_array;
692 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
693 $worksheet =& $workbook->addWorksheet();
695 switch ($export_label)
721 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
724 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
727 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
742 foreach ($eval_data[
"variables"] as $key => $value)
745 $category = $this->categories->getCategory($key);
746 $worksheet->write($rowcounter, 2, $category->scale);
752 if (is_array($eval_data[
"textanswers"]))
758 foreach ($eval_data[
"textanswers"] as $key => $answers)
760 $title = $eval_data[
"variables"][$key][
"title"];
761 foreach ($answers as $answer)
781 switch($a_export_label)
795 array_push($a_array,
$title);
798 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
800 $cat = $this->categories->getCategory($i);
803 array_push($a_array,
$title.
' - '. $this->lng->txt(
'other'));
820 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
822 $cat = $this->categories->getCategory($i);
830 if (count($resultset[
"answers"][$this->
getId()]))
832 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
834 array_push($a_array, $answer[
"value"]+1);
839 array_push($a_array, $answer[
"textanswer"]);
845 array_push($a_array, $this->lng->txt(
"skipped"));
849 array_push($a_array,
"");
867 $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",
868 array(
'integer',
'integer'),
873 $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
874 $title =
$row[
"value"] + 1 .
" - " . $category->title;
875 if ($category->other)
$title .=
": " .
$row[
"textanswer"];
894 $categorytext .= $material[
"text"];
896 $this->categories->addCategory(
899 strlen($data[
'neutral']) ? $data[
'neutral'] : 0,
900 strlen($data[
'label']) ? $data[
'label'] : null,
901 strlen($data[
'scale']) ? $data[
'scale'] : null
925 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
938 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
940 $category = $this->categories->getCategory($i);
941 $options[$category->scale-1] = $category->scale .
" - " . $category->title;
954 include_once
"./Services/Form/classes/class.ilSelectInputGUI.php";
957 $step3->setOptions($options);
958 $step3->setValue($default);
971 $category = $this->categories->getCategory($value);
972 return ($value + 1) .
" - " . ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));