38 $this->lng = $DIC->language();
39 $this->db = $DIC->database();
40 $this->question = $a_question;
41 $this->finished_ids = $a_finished_ids;
62 method_exists($this->question,
"getCategories")
63 ? $this->question->getCategories()
81 $sql =
"SELECT svy_answer.* FROM svy_answer" .
82 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)" .
83 " WHERE svy_answer.question_fi = " .
$ilDB->quote($this->question->getId(),
"integer") .
84 " AND svy_finished.survey_fi = " .
$ilDB->quote($this->getSurveyId(),
"integer");
85 if (is_array($this->finished_ids)) {
86 $sql .=
" AND " .
$ilDB->in(
"svy_finished.finished_id", $this->finished_ids,
"",
"integer");
88 $set =
$ilDB->query($sql);
89 $cnt_answer_records = [];
90 while ($row =
$ilDB->fetchAssoc($set)) {
91 $cnt_answer_records[(int) $row[
"active_fi"]] += 1;
93 $res[(int) $row[
"active_fi"]] += $row[
"value"] + 1;
95 $res[(int) $row[
"active_fi"]] = 0;
99 foreach (
$res as $active_id => $sum_score) {
101 $res[$active_id] = null;
135 $num_users_answered =
sizeof($a_answers);
142 $selections = array();
143 foreach ($a_answers as $active_id => $answers) {
145 if (
sizeof($answers) > 1) {
148 foreach ($answers as $answer) {
151 $answer[
"value"] !=
"") {
152 $scale = $a_categories->getCategoryForScale($answer[
"value"] + 1);
154 $answer[
"value"] = $scale->scale;
165 if ($answer[
"value"] !=
"") {
166 $selections[$answer[
"value"]]++;
171 $total = array_sum($selections);
175 $mode_nr = max($selections);
176 $tmp_mode = $selections;
177 asort($tmp_mode, SORT_NUMERIC);
178 $mode = array_keys($tmp_mode, $mode_nr);
179 $a_results->
setMode($mode, $mode_nr);
183 ksort($selections, SORT_NUMERIC);
185 foreach ($selections as $value => $count) {
186 for (
$i = 0;
$i < $count;
$i++) {
191 $lower = $median[(
$total / 2) - 1];
192 $upper = $median[(
$total / 2)];
193 $median_value = 0.5 * ($lower + $upper);
195 round($median_value) != $median_value) {
197 $median_value = array($lower, $upper);
200 $median_value = $median[((
$total + 1) / 2) - 1];
208 for (
$c = 0;
$c < $a_categories->getCategoryCount();
$c++) {
209 $cat = $a_categories->getCategory(
$c);
210 $scale = $cat->scale;
216 ? $selections[$scale] /
$total 226 $parsed_results = array();
228 if (is_array($a_qres)) {
229 foreach ($a_qres as $row_idx => $row_results) {
230 $row_title = $row_results[0];
231 $user_results = $row_results[1]->getUserResults($a_user_id);
233 foreach ($user_results as $item) {
235 $tmp = $row_title .
": ";
236 if ($item[0] !==
"") {
239 if ($item[1] && $item[0]) {
240 $tmp .=
", \"" . nl2br($item[1]) .
"\"";
241 } elseif ($item[1]) {
242 $tmp .=
"\"" . nl2br($item[1]) .
"\"";
244 $parsed_results[$row_idx .
"-" . $item[2]] = $tmp;
249 $user_results = $a_qres->getUserResults($a_user_id);
251 foreach ($user_results as $item) {
253 if ($item[0] !==
"") {
256 if ($item[1] && $item[0]) {
257 $tmp .=
", \"" . nl2br($item[1]) .
"\"";
258 } elseif ($item[1]) {
259 $tmp =
"\"" . nl2br($item[1]) .
"\"";
261 $parsed_results[$item[2]] = $tmp;
266 return $parsed_results;
282 public function getGrid($a_results, $a_abs =
true, $a_perc =
true)
286 if ((
bool) $a_abs && (
bool) $a_perc) {
288 $lng->txt(
"category_nr_selected"),
289 $lng->txt(
"svy_fraction_of_selections")
291 } elseif ((
bool) $a_abs) {
293 $lng->txt(
"category_nr_selected")
297 $lng->txt(
"svy_fraction_of_selections")
306 $vars = $a_results->getVariables();
308 foreach ($vars as $var) {
310 ? sprintf(
"%.2f", $var->perc * 100) .
"%" 313 if ((
bool) $a_abs && (
bool) $a_perc) {
314 $res[
"rows"][] = array(
319 } elseif ((
bool) $a_abs) {
320 $res[
"rows"][] = array(
325 $res[
"rows"][] = array(
344 return $a_results->getMappedTextAnswers();
351 "#edc240",
"#afd8f8",
"#cb4b4b",
"#4da74d",
"#9440ed",
353 "#1CE6FF",
"#FF34FF",
"#FF4A46",
"#008941",
"#006FA6",
"#A30059",
354 "#FFDBE5",
"#7A4900",
"#0000A6",
"#63FFAC",
"#B79762",
"#004D43",
"#8FB0FF",
"#997D87",
355 "#5A0007",
"#809693",
"#FEFFE6",
"#1B4400",
"#4FC601",
"#3B5DFF",
"#4A3B53",
"#FF2F80",
356 "#61615A",
"#BA0900",
"#6B7900",
"#00C2A0",
"#FFAA92",
"#FF90C9",
"#B903AA",
"#D16100",
357 "#DDEFFF",
"#000035",
"#7B4F4B",
"#A1C299",
"#300018",
"#0AA6D8",
"#013349",
"#00846F",
358 "#372101",
"#FFB500",
"#C2FFED",
"#A079BF",
"#CC0744",
"#C0B9B2",
"#C2FF99",
"#001E09",
359 "#00489C",
"#6F0062",
"#0CBD66",
"#EEC3FF",
"#456D75",
"#B77B68",
"#7A87A1",
"#788D66",
360 "#885578",
"#FAD09F",
"#FF8A9A",
"#D157A0",
"#BEC459",
"#456648",
"#0086ED",
"#886F4C",
361 "#34362D",
"#B4A8BD",
"#00A6AA",
"#452C2C",
"#636375",
"#A3C8C9",
"#FF913F",
"#938A81",
362 "#575329",
"#00FECF",
"#B05B6F",
"#8CD0FF",
"#3B9700",
"#04F757",
"#C8A1A1",
"#1E6E00",
363 "#7900D7",
"#A77500",
"#6367A9",
"#A05837",
"#6B002C",
"#772600",
"#D790FF",
"#9B9700",
364 "#549E79",
"#FFF69F",
"#201625",
"#72418F",
"#BC23FF",
"#99ADC0",
"#3A2465",
"#922329",
365 "#5B4534",
"#FDE8DC",
"#404E55",
"#0089A3",
"#CB7E98",
"#A4E804",
"#324E72",
"#6A3A4C" 378 $chart->setYAxisToInteger(
true);
381 $chart->setColors($colors);
384 $chart->setsize($this->chart_width, $this->chart_height);
386 $vars = $a_results->getVariables();
388 $legend = $labels = array();
389 foreach ($vars as $idx => $var) {
391 $data->setBarOptions(0.5,
"center");
393 $chart->addData(
$data);
401 $data->setLabel($var->cat->title);
403 $data->addPoint($idx, $var->abs);
406 $chart->setTicks($labels,
false,
true);
439 $set =
$ilDB->query(
"SELECT survey_fi" .
440 " FROM svy_svy_qst" .
441 " WHERE question_fi = " .
$ilDB->quote($this->question->getId(),
"integer"));
442 $row =
$ilDB->fetchAssoc($set);
443 return $row[
"survey_fi"];
456 if (is_array($this->finished_ids)) {
460 $set =
$ilDB->query(
"SELECT finished_id FROM svy_finished" .
461 " WHERE survey_fi = " .
$ilDB->quote($this->getSurveyId(),
"integer"));
462 return $set->numRows();
471 $sql =
"SELECT svy_answer.* FROM svy_answer" .
472 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)" .
473 " WHERE svy_answer.question_fi = " .
$ilDB->quote($this->question->getId(),
"integer") .
474 " AND svy_finished.survey_fi = " .
$ilDB->quote($this->getSurveyId(),
"integer");
475 if (is_array($this->finished_ids)) {
476 $sql .=
" AND " .
$ilDB->in(
"svy_finished.finished_id", $this->finished_ids,
"",
"integer");
478 $set =
$ilDB->query($sql);
479 while ($row =
$ilDB->fetchAssoc($set)) {
480 $res[(int) $row[
"rowvalue"]][(
int) $row[
"active_fi"]][] = array(
481 "value" => $row[
"value"],
482 "text" => $row[
"textanswer"]
510 $res[] = (int) $a_results->getUsersAnswered();
511 $res[] = (int) $a_results->getUsersSkipped();
514 $res[] = is_array($a_results->getModeValue())
515 ? implode(
", ", $a_results->getModeValue())
516 : $a_results->getModeValue();
518 $res[] = $a_results->getModeValueAsText();
519 $res[] = (int) $a_results->getModeNrOfSelections();
522 $res[] = $a_results->getMedianAsText();
524 $res[] = $a_results->getMean();
543 $lng->txt(
"category_nr_selected"),
544 $lng->txt(
"svy_fraction_of_selections")
549 $vars = $a_results->getVariables();
551 foreach ($vars as $var) {
552 $res[
"rows"][] = array(
557 ? sprintf(
"%.2f", $var->perc * 100) .
"%" parseUserSpecificResults($a_qres, $a_user_id)
getExportGrid($a_results)
Get grid data.
static getSurveySkippedValue()
exportResults($a_results, $a_do_title, $a_do_label)
Survey question evaluation.
static _getQuestionTypeName($type_tag)
Return the translation for a given question type tag.
getUserSpecificVariableTitles(array &$a_title_row, array &$a_title_row2, $a_do_title, $a_do_label)
Get title columns for user-specific export.
getNrOfParticipants()
Returns the number of participants for a survey.
Survey evaluation answers.
getGrid($a_results, $a_abs=true, $a_perc=true)
Get grid data.
foreach($_POST as $key=> $value) $res
Basic class for all survey question types.
supportsSumScore()
Supports sum score?
addVariable(ilSurveyEvaluationResultsVariable $a_variable)
setMode($a_value, $a_nr_of_selections)
setUsersAnswered($a_value)
parseResults(ilSurveyEvaluationResults $a_results, array $a_answers, SurveyCategories $a_categories=null)
Parse answer data into results instance.
__construct(SurveyQuestion $a_question, array $a_finished_ids=null)
Constructor.
getSkippedValue()
Get caption for skipped value.
addUserSpecificResults(array &$a_row, $a_user_id, $a_results)
isSumScoreValid(int $nr_answer_records)
Is sum score ok (question needs to be fully answered)
addAnswer(ilSurveyEvaluationResultsAnswer $a_answer)
setUsersSkipped($a_value)
static getInstanceByType($a_type, $a_id)
Get type instance.
getChart($a_results)
Get chart.
getSumScores()
Get sum score for this question for all active ids of run.
getTextAnswers($a_results)
Get text answers.