24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
66 $this->textwidth = 50;
67 $this->textheight = 5;
83 $query = sprintf(
"SELECT survey_question.*, survey_question_text.* FROM survey_question, survey_question_text WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_text.question_fi",
87 if ($result->numRows() == 1)
89 return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
108 $query = sprintf(
"SELECT survey_question.*, survey_question_text.* FROM survey_question, survey_question_text WHERE survey_question.question_id = %s AND survey_question.question_id = survey_question_text.question_fi",
111 $result = $ilDB->query($query);
112 if ($result->numRows() == 1)
114 $data = $result->fetchRow(MDB2_FETCHMODE_OBJECT);
115 $this->
id =
$data->question_id;
116 $this->title =
$data->title;
117 $this->description =
$data->description;
118 $this->obj_id =
$data->obj_fi;
119 $this->author =
$data->author;
120 $this->obligatory =
$data->obligatory;
121 $this->owner =
$data->owner_fi;
122 $this->original_id =
$data->original_id;
123 $this->maxchars =
$data->maxchars;
124 $this->textwidth =
$data->width;
125 $this->textheight =
$data->height;
126 include_once(
"./Services/RTE/classes/class.ilRTE.php");
128 $this->complete =
$data->complete;
145 if ($this->title and $this->author and $this->questiontext)
192 $maxchars = $ilDB->quote($this->maxchars .
"");
200 $original_id = $ilDB->quote($original_id);
204 $original_id =
"NULL";
208 include_once(
"./Services/RTE/classes/class.ilRTE.php");
216 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
217 $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)",
218 $ilDB->quote($this->getQuestionTypeID() .
""),
219 $ilDB->quote($this->obj_id),
220 $ilDB->quote($this->owner),
221 $ilDB->quote($this->title),
222 $ilDB->quote($this->description),
223 $ilDB->quote($this->author),
225 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
226 $ilDB->quote(
"$complete"),
227 $ilDB->quote($created),
230 $result = $ilDB->query($query);
231 if (PEAR::isError($result))
234 $ilias->raiseError($result->getMessage());
238 $this->
id = $ilDB->getLastInsertId();
239 $query = sprintf(
"INSERT INTO survey_question_text (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)",
240 $ilDB->quote($this->id .
""),
246 $ilDB->query($query);
252 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
253 $ilDB->quote($this->title),
254 $ilDB->quote($this->description),
255 $ilDB->quote($this->author),
257 $ilDB->quote(sprintf(
"%d", $this->obligatory)),
258 $ilDB->quote(
"$complete"),
259 $ilDB->quote($this->
id)
261 $result = $ilDB->query($query);
262 $query = sprintf(
"UPDATE survey_question_text SET maxchars = %s, width = %s, height = %s WHERE question_fi = %s",
264 $ilDB->quote($this->getTextWidth() .
""),
265 $ilDB->quote($this->getTextHeight() .
""),
266 $ilDB->quote($this->id .
"")
268 $result = $ilDB->query($query);
273 $ilias->raiseError(
$result->getMessage());
291 function toXML($a_include_header = TRUE, $obligatory_state =
"")
293 include_once(
"./classes/class.ilXmlWriter.php");
296 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
297 $xml = $a_xml_writer->xmlDumpMem(FALSE);
298 if (!$a_include_header)
300 $pos = strpos($xml,
"?>");
301 $xml = substr($xml, $pos + 2);
316 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
319 "id" => $this->
getId(),
321 "type" => $this->getQuestiontype(),
324 $a_xml_writer->xmlStartTag(
"question", $attrs);
326 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
327 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
328 $a_xml_writer->xmlStartTag(
"questiontext");
330 $a_xml_writer->xmlEndTag(
"questiontext");
332 $a_xml_writer->xmlStartTag(
"responses");
342 $a_xml_writer->xmlElement(
"response_text", $attrs);
343 $a_xml_writer->xmlEndTag(
"responses");
345 if (count($this->material))
347 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
350 "label" => $this->material[
"title"]
352 $a_xml_writer->xmlStartTag(
"material", $attrs);
353 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
354 if (strcmp($matches[1],
"") != 0)
356 $intlink = $this->material[
"internal_link"];
358 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
359 $a_xml_writer->xmlEndTag(
"material");
363 $a_xml_writer->xmlEndTag(
"question");
369 if ($this->original_id)
376 $query = sprintf(
"UPDATE survey_question SET title = %s, description = %s, author = %s, questiontext = %s, obligatory = %s, complete = %s WHERE question_id = %s",
377 $ilDB->quote($this->title .
""),
378 $ilDB->quote($this->description .
""),
379 $ilDB->quote($this->author .
""),
380 $ilDB->quote($this->questiontext .
""),
381 $ilDB->quote(sprintf(
"%d", $this->obligatory) .
""),
382 $ilDB->quote($complete .
""),
383 $ilDB->quote($this->original_id .
"")
385 $result = $ilDB->query($query);
386 $query = sprintf(
"UPDATE survey_question_text SET maxchars = %s, width = %s, height = %s WHERE question_fi = %s",
387 $ilDB->quote($this->getMaxChars() .
""),
388 $ilDB->quote($this->getTextWidth() .
""),
389 $ilDB->quote($this->getTextHeight() .
""),
390 $ilDB->quote($this->original_id .
"")
392 $result = $ilDB->query($query);
408 $query = sprintf(
"SELECT maxchars FROM survey_question WHERE question_id = %s",
409 $ilDB->quote($question_id .
"")
411 $result = $ilDB->query($query);
412 if ($result->numRows())
414 $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
415 return $row[
"maxchars"];
430 return "SurveyTextQuestion";
443 return "survey_question_text";
456 $entered_value = $post_data[$this->
getId() .
"_text_question"];
458 if (strlen($entered_value))
460 array_push(
$data, array(
"textanswer" => $entered_value));
479 $entered_value = $post_data[$this->
getId() .
"_text_question"];
483 if (strlen($entered_value) == 0)
return $this->lng->txt(
"text_question_not_filled_out");
491 $char_list =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
492 $char_list .=
"abcdefghijklmnopqrstuvwxyz";
493 $char_list .=
"1234567890";
494 for($i = 0; $i < $length; $i++)
496 $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
497 if (!rand(0,5)) $random .=
' ';
511 $randomtext = $this->
randomText(rand(25,100));
512 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, NULL, %s, NULL)",
513 $ilDB->quote($this->getId()),
514 $ilDB->quote($active_id),
515 $ilDB->quote($randomtext)
517 $result = $ilDB->query($query);
524 include_once
"./Services/Utilities/classes/class.ilUtil.php";
529 $entered_value = substr($entered_value, 0,
$maxchars);
531 if (strlen($entered_value) == 0)
return;
532 $entered_value = $ilDB->quote($entered_value .
"");
533 $query = sprintf(
"INSERT INTO survey_answer (answer_id, question_fi, active_fi, value, textanswer, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, NULL)",
534 $ilDB->quote($this->getId() .
""),
535 $ilDB->quote($active_id .
""),
539 $result = $ilDB->query($query);
546 $question_id = $this->
getId();
548 $result_array = array();
549 $cumulated = array();
550 $textvalues = array();
552 $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",
553 $ilDB->quote($question_id),
556 $result = $ilDB->query($query);
558 while ($row = $result->fetchRow(MDB2_FETCHMODE_OBJECT))
560 $cumulated[
"$row->value"]++;
561 array_push($textvalues, $row->textanswer);
563 asort($cumulated, SORT_NUMERIC);
565 $numrows = $result->numRows();
566 $result_array[
"USERS_ANSWERED"] = $result->numRows();
567 $result_array[
"USERS_SKIPPED"] = $nr_of_users - $result->numRows();
568 $result_array[
"QUESTION_TYPE"] =
"SurveyTextQuestion";
569 $result_array[
"textvalues"] = $textvalues;
570 return $result_array;
586 include_once (
"./classes/class.ilExcelUtils.php");
587 $worksheet =& $workbook->addWorksheet();
595 $worksheet->write(3, 1, $eval_data[
"USERS_ANSWERED"]);
597 $worksheet->write(4, 1, $eval_data[
"USERS_SKIPPED"]);
602 if (is_array($eval_data[
"textvalues"]))
604 foreach ($eval_data[
"textvalues"] as $textvalue)
622 if (count($resultset[
"answers"][$this->
getId()]))
624 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
626 array_push($a_array, $answer[
"textanswer"]);
631 array_push($a_array, $this->lng->txt(
"skipped"));
650 $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",
652 $ilDB->quote($this->
getId())
654 $result = $ilDB->query($query);
655 while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))
657 $answers[$row[
"active_fi"]] = $row[
"textanswer"];
674 if (
$data[
"maxlength"] > 0)
678 if (
$data[
"rows"] > 0)
682 if (
$data[
"columns"] > 0)
738 if ($a_textwidth < 1)
740 $this->textwidth = 50;
744 $this->textwidth = $a_textwidth;
758 if ($a_textheight < 1)
760 $this->textheight = 5;
764 $this->textheight = $a_textheight;