24 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
   66                 include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
 
   87                         return $ilDB->fetchAssoc(
$result);
 
  111                         $data = $ilDB->fetchAssoc(
$result);
 
  112                         $this->
setId($data[
"question_id"]);
 
  114                         $this->label = $data[
'label'];
 
  119                         include_once(
"./Services/RTE/classes/class.ilRTE.php");
 
  125                         $this->use_min_answers = ($data[
'use_min_answers']) ? 
true : 
false;
 
  126                         $this->nr_min_answers = $data[
'nr_min_answers'];
 
  127                         $this->nr_max_answers = $data[
'nr_max_answers'];
 
  129                         $this->categories->flushCategories();
 
  130                         $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",
 
  136                                 while ($data = $ilDB->fetchAssoc(
$result)) 
 
  138                                         $this->categories->addCategory($data[
"title"], $data[
"other"], $data[
"neutral"], null, ($data[
'scale']) ? $data[
'scale'] : ($data[
'sequence'] + 1));
 
  157                         $this->categories->getCategoryCount()
 
  178                 if ($affectedRows == 1) 
 
  180                         $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() . 
" WHERE question_fi = %s",
 
  182                                 array($this->
getId())
 
  184                         $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)",
 
  185                                 array(
'integer', 
'text', 
'integer', 
'integer', 
'integer'),
 
  189                                         ($this->use_min_answers) ? 1 : 0,
 
  190                                         ($this->nr_min_answers > 0) ? $this->nr_min_answers : null,
 
  191                                         ($this->nr_max_answers > 0) ? $this->nr_max_answers : null
 
  205                 $affectedRows = $ilDB->manipulateF(
"DELETE FROM svy_variable WHERE question_fi = %s",
 
  207                         array($this->
getId())
 
  210                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  212                         $cat = $this->categories->getCategory($i);
 
  214                         $next_id = $ilDB->nextId(
'svy_variable');
 
  215                         $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)",
 
  216                                 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer', 
'integer',
'integer'),
 
  217                                 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale : null, time())
 
  229         function toXML($a_include_header = TRUE, $obligatory_state = 
"")
 
  231                 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
 
  234                 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
 
  235                 $xml = $a_xml_writer->xmlDumpMem(FALSE);
 
  236                 if (!$a_include_header)
 
  238                         $pos = strpos($xml, 
"?>");
 
  239                         $xml = substr($xml, $pos + 2);
 
  252         function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state = 
"")
 
  255                         "id" => $this->
getId(),
 
  257                         "type" => $this->getQuestiontype(),
 
  260                 $a_xml_writer->xmlStartTag(
"question", $attrs);
 
  262                 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
 
  263                 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
 
  264                 if (strlen($this->label))
 
  267                                 "label" => $this->label,
 
  274                 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
 
  276                 $a_xml_writer->xmlEndTag(
"questiontext");
 
  278                 $a_xml_writer->xmlStartTag(
"responses");
 
  280                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  285                         if (strlen($this->categories->getCategory($i)->other)) $attrs[
'other'] = $this->categories->getCategory($i)->other;
 
  286                         if (strlen($this->categories->getCategory($i)->neutral)) $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
 
  287                         if (strlen($this->categories->getCategory($i)->label)) $attrs[
'label'] = $this->categories->getCategory($i)->label;
 
  288                         if (strlen($this->categories->getCategory($i)->scale)) $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
 
  289                         $a_xml_writer->xmlStartTag(
"response_multiple", $attrs);
 
  290                         $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
 
  291                         $a_xml_writer->xmlEndTag(
"response_multiple");
 
  294                 $a_xml_writer->xmlEndTag(
"responses");
 
  296                 if (count($this->material))
 
  298                         if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
 
  301                                         "label" => $this->material[
"title"]
 
  303                                 $a_xml_writer->xmlStartTag(
"material", $attrs);
 
  304                                 $intlink = 
"il_" . IL_INST_ID . 
"_" . $matches[2] . 
"_" . $matches[3];
 
  305                                 if (strcmp($matches[1], 
"") != 0)
 
  307                                         $intlink = $this->material[
"internal_link"];
 
  309                                 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
 
  310                                 $a_xml_writer->xmlEndTag(
"material");
 
  314                 $a_xml_writer->xmlStartTag(
"metadata");
 
  315                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  316                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"orientation");
 
  317                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
 
  318                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  319                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  320                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"use_min_answers");
 
  321                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->use_min_answers);
 
  322                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  323                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  324                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"nr_min_answers");
 
  325                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_min_answers);
 
  326                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  327                 $a_xml_writer->xmlStartTag(
"metadatafield");
 
  328                 $a_xml_writer->xmlElement(
"fieldlabel", NULL, 
"nr_max_answers");
 
  329                 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->nr_max_answers);
 
  330                 $a_xml_writer->xmlEndTag(
"metadatafield");
 
  331                 $a_xml_writer->xmlEndTag(
"metadata");
 
  333                 $a_xml_writer->xmlEndTag(
"question");
 
  344                 return "SurveyMultipleChoiceQuestion";
 
  366                 $entered_value = $post_data[$this->
getId() . 
"_value"];
 
  368                 if (is_array($entered_value))
 
  370                         foreach ($entered_value as $idx => $value)
 
  372                                 array_push($data, array(
"value" => $value, 
"textanswer" => $post_data[$this->
getId() . 
'_' . $value . 
'_other']));
 
  375                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  377                         $cat = $this->categories->getCategory($i);
 
  380                                 if (!in_array($i, $entered_value))
 
  382                                         if (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  384                                                 array_push($data, array(
"value" => $i, 
"textanswer" => $post_data[$this->
getId() . 
'_' . $i . 
'_other'], 
"uncheck" => 
true));
 
  403                 $entered_value = $post_data[$this->
getId() . 
"_value"];
 
  406                 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)
 
  408                         return sprintf($this->lng->txt(
"err_no_exact_answers"), $this->nr_min_answers);
 
  410                 if ($this->use_min_answers && $this->nr_min_answers > 0 && count($entered_value) < $this->nr_min_answers)
 
  412                         return sprintf($this->lng->txt(
"err_no_min_answers"), $this->nr_min_answers);
 
  414                 if ($this->use_min_answers && $this->nr_max_answers > 0 && count($entered_value) > $this->nr_max_answers)
 
  416                         return sprintf($this->lng->txt(
"err_no_max_answers"), $this->nr_max_answers);
 
  418                 if (!is_array($entered_value))
 
  420                         return $this->lng->txt(
"question_mr_not_checked");
 
  422                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  424                         $cat = $this->categories->getCategory($i);
 
  427                                 if (in_array($i, $entered_value))
 
  429                                         if (array_key_exists($this->
getId() . 
"_" . $i . 
"_other", $post_data) && !strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  431                                                 return $this->lng->txt(
"question_mr_no_other_answer");
 
  436                                         if (strlen($post_data[$this->
getId() . 
"_" . $i . 
"_other"]))
 
  438                                                 return $this->lng->txt(
"question_mr_no_other_answer_checked");
 
  455                 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
 
  459                                 $cat = $this->categories->getCategory($i);
 
  460                                 $next_id = $ilDB->nextId(
'svy_answer');
 
  461                                 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
 
  462                                         array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
 
  463                                         array($next_id, $this->
getId(), $active_id, $i, ($cat->other) ? 
"Random Data" : null, time())
 
  475                         $return_data = array();
 
  477                 if (is_array($post_data[$this->
getId() . 
"_value"]))
 
  479                         foreach ($post_data[$this->
getId() . 
"_value"] as $entered_value)
 
  481                                 if (strlen($entered_value) > 0)
 
  485                                                 $next_id = $ilDB->nextId(
'svy_answer');
 
  486                                                 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
 
  487                                                         array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
 
  488                                                         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())
 
  493                                                 $return_data[] = array(
"value"=>$entered_value, 
 
  494                                                                 "textanswer"=>$post_data[$this->
getId() . 
"_" . $entered_value . 
"_other"]);
 
  509                 $question_id = $this->
getId();
 
  511                 $result_array = array();
 
  514                 $sql = 
"SELECT svy_answer.* FROM svy_answer".
 
  515                         " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
 
  516                         " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, 
"integer").
 
  517                         " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id, 
"integer");           
 
  520                         $sql .= 
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids, 
"", 
"integer");
 
  527                 $textanswers = array();
 
  533                         if ($row[
"textanswer"])
 
  535                                 $textanswers[$row[
"value"]][] = $row[
"textanswer"];
 
  539                 if (is_array($textanswers))
 
  541                         ksort($textanswers, SORT_NUMERIC);
 
  546                 $sql = 
"SELECT svy_answer.answer_id, svy_answer.question_fi, svy_answer.active_fi".
 
  548                         " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
 
  549                         " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id, 
"integer").
 
  550                         " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id, 
"integer");           
 
  553                         $sql .= 
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids, 
"", 
"integer");
 
  556                 $mcmr_result = $ilDB->query($sql);      
 
  558                 while (
$row = $ilDB->fetchAssoc($mcmr_result))
 
  560                         $found[
$row[
"question_fi"] . 
"_" . 
$row[
"active_fi"]] = 1;
 
  562                 $result_array[
"USERS_ANSWERED"] = count($found);
 
  563                 $result_array[
"USERS_SKIPPED"] = $nr_of_users - count($found);
 
  564                 $numrows = count($found);
 
  566                 $result_array[
"MEDIAN"] = 
"";
 
  567                 $result_array[
"ARITHMETIC_MEAN"] = 
"";
 
  575                         $category = $this->categories->getCategoryForScale(key(
$cumulated)+1);
 
  576                         $result_array[
"MODE"] =  $prefix . $category->title;
 
  577                         $result_array[
"MODE_VALUE"] =  key(
$cumulated)+1;
 
  580                 $result_array[
"QUESTION_TYPE"] = 
"SurveyMultipleChoiceQuestion";
 
  582                 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
 
  584                         $cat = $this->categories->getCategory($key);
 
  587                 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
 
  589                         $cat = $this->categories->getCategory($key);
 
  595                                         $percentage = ($maxvalues > 0) ? (
float)((int)
$cumulated[$cat->scale-1]/$maxvalues) : 0;
 
  598                         if(isset($textanswers[$cat->scale-1]))
 
  601                                 $result_array[
"textanswers"][$key] = $textanswers[$cat->scale-1];
 
  603                         $result_array[
"variables"][$key] = array(
"title" => $cat->title, 
"selected" => (
int)
$cumulated[$cat->scale-1], 
"percentage" => $percentage);
 
  605                 return $result_array;
 
  619                 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
 
  620                 $worksheet =& $workbook->addWorksheet();
 
  622                 switch ($export_label)
 
  648                 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
 
  651                 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
 
  665                 foreach ($eval_data[
"variables"] as $key => $value)
 
  668                         $category = $this->categories->getCategory($key);
 
  669                         $worksheet->write($rowcounter, 2, $category->scale);
 
  675                 if (is_array($eval_data[
"textanswers"]))
 
  681                         foreach ($eval_data[
"textanswers"] as $key => $answers)
 
  683                                 $title = $eval_data[
"variables"][$key][
"title"];
 
  684                                 foreach ($answers as $answer)
 
  703                 for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  705                         $category = $this->categories->getCategory($index);
 
  706                         $title = $category->title;
 
  708                         if(!$a_use_label || $a_substitute)
 
  710                                 array_push($a_array, 
$title);
 
  714                                 array_push($a_array, 
"");
 
  718                         if ($category->other)
 
  720                                 if(!$a_use_label || $a_substitute)
 
  722                                         array_push($a_array, 
$title . 
" - ". $this->lng->txt(
"other"));
 
  726                                         array_push($a_array, 
"");
 
  741                 if (count($resultset[
"answers"][$this->
getId()]))
 
  743                         array_push($a_array, 
"");
 
  744                         for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  746                                 $category = $this->categories->getCategory($index);             
 
  747                                 $incoming_value = $category->scale ? $category->scale-1 : $index;               
 
  751                                 foreach ($resultset[
"answers"][$this->
getId()] as $answerdata)
 
  753                                         if (strcmp($incoming_value, $answerdata[
"value"]) == 0)
 
  755                                                 $found = $answerdata[
"value"]+1;
 
  756                                                 $textanswer = $answerdata[
"textanswer"];
 
  761                                         array_push($a_array, $found);
 
  765                                         array_push($a_array, 
"0");
 
  767                                 if ($category->other)
 
  769                                         array_push($a_array, $textanswer);
 
  776                         for ($index = 0; $index < $this->categories->getCategoryCount(); $index++)
 
  778                                 array_push($a_array, 
"");
 
  781                                 $category = $this->categories->getCategory($index);
 
  782                                 if ($category->other)
 
  784                                         array_push($a_array, 
"");
 
  803                 $sql = 
"SELECT svy_answer.* FROM svy_answer".
 
  804                         " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
 
  805                         " WHERE svy_answer.question_fi = ".$ilDB->quote($this->
getId(), 
"integer").
 
  806                         " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id, 
"integer");           
 
  809                         $sql .= 
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids, 
"", 
"integer");
 
  815                         $category = $this->categories->getCategoryForScale(
$row[
"value"]+1);
 
  816                         if (!is_array($answers[
$row[
"active_fi"]]))
 
  818                                 $answers[$row[
"active_fi"]] = array();
 
  820                         $title = $row[
"value"] + 1 . 
" - " . $category->title;
 
  821                         if ($category->other) 
$title .= 
": " . $row[
"textanswer"];
 
  822                         $catindex = $this->categories->getIndex($category);
 
  823                         if ($catindex !== null)
 
  825                                 $answers[$row[
"active_fi"]][$catindex] = 
$title;
 
  829                                 array_push($answers[$row[
"active_fi"]], 
$title);
 
  831                         ksort($answers[$row[
"active_fi"]], SORT_NUMERIC);
 
  846                 foreach ($a_meta as $key => $value)
 
  848                         switch ($value[
"label"])
 
  853                                 case "use_min_answers":
 
  854                                         $this->use_min_answers = $value[
"entry"];
 
  856                                 case "nr_min_answers":
 
  857                                         $this->nr_min_answers = $value[
"entry"];
 
  859                                 case "nr_max_answers":
 
  860                                         $this->nr_max_answers = $value[
"entry"];
 
  874                 foreach ($a_data as 
$id => $data)
 
  879                                 $categorytext .= $material[
"text"];
 
  881                         $this->categories->addCategory(
 
  883                                 strlen($data[
'other']) ? $data[
'other'] : 0, 
 
  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[$category->scale-1] = $category->scale . 
" - " . $category->title;
 
  939                 include_once 
"./Services/Form/classes/class.ilSelectInputGUI.php";
 
  943                 $step3->setValue($default);
 
  957                 $category = $this->categories->getCategoryForScale($value+1);
 
  960                 return $category->scale . 
 
  962                         ((strlen($category->title)) ? $category->title : $this->lng->txt(
'other_answer'));