24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
63 $this->textwidth = 50;
64 $this->textheight = 5;
81 if ($result->numRows() == 1)
83 return $ilDB->fetchAssoc($result);
105 if ($result->numRows() == 1)
107 $data = $ilDB->fetchAssoc($result);
110 $this->label =
$data[
'label'];
115 include_once(
"./Services/RTE/classes/class.ilRTE.php");
137 if ($this->title and $this->author and $this->questiontext)
164 return ($this->maxchars) ? $this->maxchars : NULL;
177 if ($affectedRows == 1)
179 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
181 array($this->
getId())
183 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)",
184 array(
'integer',
'integer',
'integer',
'integer'),
198 function toXML($a_include_header = TRUE, $obligatory_state =
"")
200 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
203 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
204 $xml = $a_xml_writer->xmlDumpMem(FALSE);
205 if (!$a_include_header)
207 $pos = strpos($xml,
"?>");
208 $xml = substr($xml,
$pos + 2);
221 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
224 "id" => $this->
getId(),
226 "type" => $this->getQuestiontype(),
229 $a_xml_writer->xmlStartTag(
"question", $attrs);
231 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
232 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
233 if (strlen($this->label))
236 "label" => $this->label,
243 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
245 $a_xml_writer->xmlEndTag(
"questiontext");
247 $a_xml_writer->xmlStartTag(
"responses");
257 $a_xml_writer->xmlElement(
"response_text", $attrs);
258 $a_xml_writer->xmlEndTag(
"responses");
260 if (count($this->material))
262 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
265 "label" => $this->material[
"title"]
267 $a_xml_writer->xmlStartTag(
"material", $attrs);
268 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
269 if (strcmp($matches[1],
"") != 0)
271 $intlink = $this->material[
"internal_link"];
273 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
274 $a_xml_writer->xmlEndTag(
"material");
278 $a_xml_writer->xmlEndTag(
"question");
290 $result = $ilDB->queryF(
"SELECT maxchars FROM svy_question WHERE question_id = %s",
294 if ($result->numRows())
296 $row = $ilDB->fetchAssoc($result);
297 return $row[
"maxchars"];
310 return "SurveyTextQuestion";
321 return "svy_qst_text";
332 $entered_value = $post_data[$this->
getId() .
"_text_question"];
334 if (strlen($entered_value))
336 array_push(
$data, array(
"textanswer" => $entered_value));
352 $entered_value = $post_data[$this->
getId() .
"_text_question"];
356 if (strlen($entered_value) == 0)
return $this->lng->txt(
"text_question_not_filled_out");
364 $char_list =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
365 $char_list .=
"abcdefghijklmnopqrstuvwxyz";
366 $char_list .=
"1234567890";
367 for($i = 0; $i < $length; $i++)
369 $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
370 if (!rand(0,5)) $random .=
' ';
384 $randomtext = $this->
randomText(rand(25,100));
385 $next_id = $ilDB->nextId(
'svy_answer');
386 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
387 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
388 array($next_id, $this->
getId(), $active_id, NULL, $randomtext, time())
396 include_once
"./Services/Utilities/classes/class.ilUtil.php";
401 $entered_value = substr($entered_value, 0,
$maxchars);
403 if (strlen($entered_value) == 0)
return;
404 $next_id = $ilDB->nextId(
'svy_answer');
405 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
406 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
407 array($next_id, $this->
getId(), $active_id, NULL, (strlen($entered_value)) ? $entered_value : NULL, time())
415 $question_id = $this->
getId();
417 $result_array = array();
419 $textvalues = array();
421 $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",
422 array(
'integer',
'integer'),
426 while (
$row = $ilDB->fetchAssoc($result))
429 array_push($textvalues, $row[
"textanswer"]);
433 $numrows = $result->numRows();
434 $result_array[
"USERS_ANSWERED"] = $result->numRows();
435 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
436 $result_array[
"QUESTION_TYPE"] =
"SurveyTextQuestion";
437 $result_array[
"textvalues"] = $textvalues;
438 return $result_array;
450 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
451 $adapter->addWorksheet($this->
getTitle());
452 $adapter->setActiveWorksheet($adapter->getWorksheetCount()-1);
454 switch ($export_label)
458 $adapter->setCellValue(0, 1, $this->label);
462 $adapter->setCellValue(0, 1, $this->
getTitle());
466 $adapter->setCellValue(0, 1, $this->
getTitle());
468 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"label"),
CELL_FORMAT_BOLD);
469 $adapter->setCellValue($rowcounter, 1, $this->label);
473 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question"),
CELL_FORMAT_BOLD);
476 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"question_type"),
CELL_FORMAT_BOLD);
477 $adapter->setCellValue($rowcounter, 1, $this->lng->txt($this->getQuestionType()));
479 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_answered"),
CELL_FORMAT_BOLD);
480 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_ANSWERED"]);
482 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"users_skipped"),
CELL_FORMAT_BOLD);
483 $adapter->setCellValue($rowcounter, 1, $eval_data[
"TOTAL"][
"USERS_SKIPPED"]);
486 $adapter->setCellValue($rowcounter, 0, $this->lng->txt(
"given_answers"),
CELL_FORMAT_BOLD);
488 if (is_array($eval_data[
"textvalues"]))
490 foreach ($eval_data[
"textvalues"] as $textvalue)
492 $adapter->setCellValue($rowcounter++, 1, $textvalue);
506 if (count($resultset[
"answers"][$this->
getId()]))
508 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
510 array_push($a_array, $answer[
"textanswer"]);
515 array_push($a_array, $this->lng->txt(
"skipped"));
532 $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",
533 array(
'integer',
'integer'),
536 while (
$row = $ilDB->fetchAssoc($result))
538 $answers[
$row[
"active_fi"]] = $row[
"textanswer"];
553 if (
$data[
"maxlength"] > 0)
557 if (
$data[
"rows"] > 0)
561 if (
$data[
"columns"] > 0)
587 return ($this->textwidth) ? $this->textwidth : NULL;
598 return ($this->textheight) ? $this->textheight : NULL;
609 if ($a_textwidth < 1)
611 $this->textwidth = 50;
615 $this->textwidth = $a_textwidth;
627 if ($a_textheight < 1)
629 $this->textheight = 5;
633 $this->textheight = $a_textheight;