24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
71 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
89 $query = sprintf(
"SELECT survey_category.* FROM survey_category, survey_phrase_category WHERE survey_phrase_category.category_fi = survey_category.category_id AND survey_phrase_category.phrase_fi = %s ORDER BY survey_phrase_category.sequence",
90 $ilDB->quote($phrase_id)
93 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
95 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
97 $categories[$row->category_id] = $this->lng->txt($row->title);
120 $query = sprintf(
"SELECT survey_category.* FROM survey_category, survey_phrase_category WHERE survey_phrase_category.category_fi = survey_category.category_id AND survey_phrase_category.phrase_fi = %s AND (survey_category.owner_fi = 0 OR survey_category.owner_fi = %s) ORDER BY survey_phrase_category.sequence",
121 $ilDB->quote($phrase_id),
122 $ilDB->quote($ilUser->id)
124 $result = $ilDB->query($query);
125 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
127 if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
129 $this->categories->addCategory($this->lng->txt($row->title));
133 $this->categories->addCategory($row->title);
151 $query = sprintf(
"SELECT survey_question.*, survey_question_ordinal.* FROM survey_question, survey_question_ordinal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_ordinal.question_fi",
154 $result = $ilDB->query($query);
155 if ($result->numRows() == 1)
157 return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
176 $query = sprintf(
"SELECT survey_question.*, survey_question_ordinal.* FROM survey_question, survey_question_ordinal WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_ordinal.question_fi",
179 $result = $ilDB->query($query);
180 if ($result->numRows() == 1)
182 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
183 $this->
id =
$data->question_id;
184 $this->title =
$data->title;
185 $this->description =
$data->description;
186 $this->obj_id =
$data->obj_fi;
187 $this->orientation =
$data->orientation;
188 $this->author =
$data->author;
189 $this->owner =
$data->owner_fi;
190 include_once(
"./Services/RTE/classes/class.ilRTE.php");
192 $this->obligatory =
$data->obligatory;
193 $this->complete =
$data->complete;
194 $this->original_id =
$data->original_id;
198 $this->categories->flushCategories();
199 $query = sprintf(
"SELECT survey_variable.*, survey_category.title FROM survey_variable, survey_category WHERE survey_variable.question_fi = %s AND survey_variable.category_fi = survey_category.category_id ORDER BY sequence ASC",
202 $result = $ilDB->query($query);
203 if ($result->numRows() > 0)
205 while (
$data = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
207 $this->categories->addCategory(
$data->title);
224 if ($this->title and $this->author and $this->questiontext and $this->categories->getCategoryCount())
241 function saveToDb($original_id =
"", $withanswers =
true)
250 $original_id = $ilDB->quote($original_id);
254 $original_id =
"NULL";
258 include_once(
"./Services/RTE/classes/class.ilRTE.php");
266 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
267 $query = sprintf(
"INSERT INTO survey_question (question_id, questiontype_fi, obj_fi, owner_fi, title, description, author, questiontext, obligatory, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
268 $ilDB->quote($this->getQuestionTypeID()),
269 $ilDB->quote($this->obj_id),
270 $ilDB->quote($this->owner),
271 $ilDB->quote($this->title),
272 $ilDB->quote($this->description),
273 $ilDB->quote($this->author),
275 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
276 $ilDB->quote(
"$complete"),
277 $ilDB->quote($created),
280 $result = $ilDB->query($query);
281 if (PEAR::isError($result))
284 $ilias->raiseError($result->getMessage());
288 $this->
id = $ilDB->getLastInsertId();
289 $query = sprintf(
"INSERT INTO survey_question_ordinal (question_fi, orientation) VALUES (%s, %s)",
290 $ilDB->quote($this->id .
""),
291 $ilDB->quote(sprintf(
"%d", $this->orientation))
293 $ilDB->query($query);
299 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
300 $ilDB->quote($this->title),
301 $ilDB->quote($this->description),
302 $ilDB->quote($this->author),
304 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
305 $ilDB->quote(
"$complete"),
306 $ilDB->quote($this->
id)
308 $result = $ilDB->query($query);
309 $query = sprintf(
"UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
310 $ilDB->quote(sprintf(
"%d", $this->orientation)),
311 $ilDB->quote($this->
id .
"")
313 $result = $ilDB->query($query);
318 $ilias->raiseError(
$result->getMessage());
337 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
338 $this->ilias->db->quote($this->id)
340 $result = $this->ilias->db->query($query);
342 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
345 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
346 $this->ilias->db->quote($category_id .
""),
347 $this->ilias->db->quote($this->
id .
""),
348 $this->ilias->db->quote(($i + 1) .
""),
349 $this->ilias->db->quote($i .
"")
351 $answer_result = $this->ilias->db->query($query);
364 function toXML($a_include_header = TRUE, $obligatory_state =
"")
366 include_once(
"./classes/class.ilXmlWriter.php");
369 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
370 $xml = $a_xml_writer->xmlDumpMem(FALSE);
371 if (!$a_include_header)
373 $pos = strpos($xml,
"?>");
374 $xml = substr($xml, $pos + 2);
389 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
392 "id" => $this->
getId(),
394 "type" => $this->getQuestiontype(),
397 $a_xml_writer->xmlStartTag(
"question", $attrs);
399 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
400 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
401 $a_xml_writer->xmlStartTag(
"questiontext");
403 $a_xml_writer->xmlEndTag(
"questiontext");
405 $a_xml_writer->xmlStartTag(
"responses");
407 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
412 $a_xml_writer->xmlStartTag(
"response_single", $attrs);
413 $this->
addMaterialTag($a_xml_writer, $this->categories->getCategory($i));
414 $a_xml_writer->xmlEndTag(
"response_single");
417 $a_xml_writer->xmlEndTag(
"responses");
419 if (count($this->material))
421 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
424 "label" => $this->material[
"title"]
426 $a_xml_writer->xmlStartTag(
"material", $attrs);
427 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
428 if (strcmp($matches[1],
"") != 0)
430 $intlink = $this->material[
"internal_link"];
432 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
433 $a_xml_writer->xmlEndTag(
"material");
437 $a_xml_writer->xmlStartTag(
"metadata");
438 $a_xml_writer->xmlStartTag(
"metadatafield");
439 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"orientation");
440 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->
getOrientation());
441 $a_xml_writer->xmlEndTag(
"metadatafield");
442 $a_xml_writer->xmlEndTag(
"metadata");
444 $a_xml_writer->xmlEndTag(
"question");
450 if ($this->original_id)
456 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
457 $ilDB->quote($this->title .
""),
458 $ilDB->quote($this->description .
""),
459 $ilDB->quote($this->author .
""),
460 $ilDB->quote($this->questiontext .
""),
461 $ilDB->quote(sprintf(
"%d", $this->obligatory) .
""),
462 $ilDB->quote($complete .
""),
463 $ilDB->quote($this->original_id .
"")
465 $result = $ilDB->query($query);
466 $query = sprintf(
"UPDATE survey_question_ordinal SET orientation = %s WHERE question_fi = %s",
467 $ilDB->quote($this->getOrientation() .
""),
468 $ilDB->quote($this->original_id .
"")
470 $result = $ilDB->query($query);
471 if (PEAR::isError($result))
474 $ilias->raiseError($result->getMessage());
481 $query = sprintf(
"DELETE FROM survey_variable WHERE question_fi = %s",
482 $ilDB->quote($this->original_id .
"")
484 $result = $ilDB->query($query);
486 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
489 $query = sprintf(
"INSERT INTO survey_variable (variable_id, category_fi, question_fi, value1, sequence, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
490 $ilDB->quote($category_id .
""),
491 $ilDB->quote($this->original_id .
""),
492 $ilDB->quote(($i + 1) .
""),
493 $ilDB->quote($i .
"")
495 $answer_result = $ilDB->query($query);
513 for ($i = $lower_limit; $i <= $upper_limit; $i++)
515 $this->categories->addCategory($i);
533 $query = sprintf(
"INSERT INTO survey_phrase (phrase_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
534 $ilDB->quote(
$title .
""),
536 $ilDB->quote($ilUser->id .
"")
538 $result = $ilDB->query($query);
539 $phrase_id = $ilDB->getLastInsertId();
542 foreach ($phrases as $category)
544 $query = sprintf(
"INSERT INTO survey_category (category_id, title, defaultvalue, owner_fi, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL)",
545 $ilDB->quote($this->categories->getCategory($category) .
""),
547 $ilDB->quote($ilUser->id .
"")
549 $result = $ilDB->query($query);
550 $category_id = $ilDB->getLastInsertId();
551 $query = sprintf(
"INSERT INTO survey_phrase_category (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (NULL, %s, %s, %s)",
552 $ilDB->quote($phrase_id .
""),
553 $ilDB->quote($category_id .
""),
554 $ilDB->quote($counter .
"")
556 $result = $ilDB->query($query);
571 return "SurveyOrdinalQuestion";
584 return "survey_question_ordinal";
597 $entered_value = $post_data[$this->
getId() .
"_value"];
599 if (strlen($entered_value))
601 array_push(
$data, array(
"value" => $entered_value));
620 $entered_value = $post_data[$this->
getId() .
"_value"];
624 if (strlen($entered_value) == 0)
return $this->lng->txt(
"ordinal_question_not_checked");
638 $category = rand(0, $this->categories->getCategoryCount()-1);
639 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, NULL, NULL)",
640 $ilDB->quote($this->getId()),
641 $ilDB->quote($active_id),
642 $ilDB->quote($category)
644 $result = $ilDB->query($query);
651 $entered_value = $post_data[$this->
getId() .
"_value"];
652 if (strlen($entered_value) == 0)
return;
653 $entered_value = $ilDB->quote($entered_value .
"");
654 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
655 $ilDB->quote($this->getId() .
""),
656 $ilDB->quote($active_id .
""),
660 $result = $ilDB->query($query);
667 $question_id = $this->
getId();
669 $result_array = array();
670 $cumulated = array();
672 $query = sprintf(
"SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_answer.question_fi = %s AND survey_finished.survey_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
673 $ilDB->quote($question_id),
676 $result = $ilDB->query($query);
678 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
680 $cumulated[
"$row->value"]++;
682 asort($cumulated, SORT_NUMERIC);
684 $numrows = $result->numRows();
685 $result_array[
"USERS_ANSWERED"] = $result->numRows();
686 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
689 if (strcmp(key($cumulated),
"") != 0)
691 $prefix = (key($cumulated)+1) .
" - ";
693 $result_array[
"MODE"] = $prefix . $this->categories->getCategory(key($cumulated));
694 $result_array[
"MODE_VALUE"] = key($cumulated)+1;
695 $result_array[
"MODE_NR_OF_SELECTIONS"] = $cumulated[key($cumulated)];
696 for ($key = 0; $key < $this->categories->getCategoryCount(); $key++)
701 $percentage = (float)((
int)$cumulated[$key]/$numrows);
703 $result_array[
"variables"][$key] = array(
"title" => $this->categories->getCategory($key),
"selected" => (int)$cumulated[$key],
"percentage" => $percentage);
705 ksort($cumulated, SORT_NUMERIC);
708 foreach ($cumulated as $value => $key)
711 for ($i = 0; $i < $key; $i++)
713 array_push($median, $value+1);
720 $median_value = 0.5 * ($median[(
$total/2)-1] + $median[(
$total/2)]);
721 if (round($median_value) != $median_value)
723 $median_value = $median_value .
"<br />" .
"(" . $this->lng->txt(
"median_between") .
" " . (floor($median_value)) .
"-" . $this->categories->getCategory((
int)floor($median_value)-1) .
" " . $this->lng->txt(
"and") .
" " . (ceil($median_value)) .
"-" . $this->categories->getCategory((
int)ceil($median_value)-1) .
")";
728 $median_value = $median[((
$total+1)/2)-1];
735 $result_array[
"ARITHMETIC_MEAN"] =
"";
736 $result_array[
"MEDIAN"] = $median_value;
737 $result_array[
"QUESTION_TYPE"] =
"SurveyOrdinalQuestion";
738 return $result_array;
754 include_once (
"./classes/class.ilExcelUtils.php");
755 $worksheet =& $workbook->addWorksheet();
763 $worksheet->write(3, 1, $eval_data[
"USERS_ANSWERED"]);
765 $worksheet->write(4, 1, $eval_data[
"USERS_SKIPPED"]);
768 preg_match(
"/(.*?)\s+-\s+(.*)/", $eval_data[
"MODE"], $matches);
783 foreach ($eval_data[
"variables"] as $key => $value)
786 $worksheet->write($rowcounter, 2, $key+1);
803 if (count($resultset[
"answers"][$this->
getId()]))
805 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
807 array_push($a_array, $answer[
"value"]+1);
812 array_push($a_array, $this->lng->txt(
"skipped"));
831 $query = sprintf(
"SELECT survey_answer.* FROM survey_answer, survey_finished WHERE survey_finished.survey_fi = %s AND survey_answer.question_fi = %s AND survey_finished.finished_id = survey_answer.active_fi",
833 $ilDB->quote($this->
getId())
835 $result = $ilDB->query($query);
836 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
838 $category = $this->categories->getCategory($row[
"value"]);
839 $answers[$row[
"active_fi"]] = $row[
"value"] + 1 .
" - " . $category;
859 $categorytext .= $material[
"text"];
861 $this->categories->addCategory($categorytext);
888 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
903 include_once
"./classes/class.ilTemplate.php";
904 $template =
new ilTemplate(
"tpl.il_svy_svy_precondition_select_value_combobox.html", TRUE, TRUE,
"Modules/Survey");
905 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
907 $template->setCurrentBlock(
"option_v");
908 $template->setVariable(
"OPTION_VALUE", $i);
909 $template->setVariable(
"OPTION_TEXT", ($i+1) .
" - " . $this->categories->getCategory($i));
912 $template->setVariable(
"OPTION_CHECKED",
" selected=\"selected\"");
914 $template->parseCurrentBlock();
916 $template->setVariable(
"SELECT_VALUE", $lng->txt(
"step") .
" 3: " . $lng->txt(
"select_value"));
917 return $template->get();
931 return ($value + 1) .
" - " . $this->categories->getCategory($value);
946 if (count($this->cumulated) == 0)
948 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
953 foreach ($this->cumulated[
"variables"] as $key => $value)
955 foreach ($value as $key2 => $value2)
957 $this->cumulated[
"variables"][$key][$key2] = utf8_decode($value2);
960 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyChart.php";
961 $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"]);