24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
62 $this->textwidth = 50;
63 $this->textheight = 5;
82 return $ilDB->fetchAssoc(
$result);
109 $this->label =
$data[
'label'];
114 include_once(
"./Services/RTE/classes/class.ilRTE.php");
125 parent::loadFromDb(
$id);
167 return ($this->maxchars) ? $this->maxchars : NULL;
179 $affectedRows = parent::saveToDb($original_id);
180 if ($affectedRows == 1)
182 $affectedRows = $ilDB->manipulateF(
"DELETE FROM " . $this->
getAdditionalTableName() .
" WHERE question_fi = %s",
184 array($this->
getId())
186 $affectedRows = $ilDB->manipulateF(
"INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)",
187 array(
'integer',
'integer',
'integer',
'integer'),
201 function toXML($a_include_header = TRUE, $obligatory_state =
"")
203 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
206 $this->
insertXML($a_xml_writer, $a_include_header, $obligatory_state);
207 $xml = $a_xml_writer->xmlDumpMem(FALSE);
208 if (!$a_include_header)
210 $pos = strpos($xml,
"?>");
211 $xml = substr($xml, $pos + 2);
224 function insertXML(&$a_xml_writer, $a_include_header = TRUE, $obligatory_state =
"")
227 "id" => $this->
getId(),
229 "type" => $this->getQuestiontype(),
232 $a_xml_writer->xmlStartTag(
"question", $attrs);
234 $a_xml_writer->xmlElement(
"description", NULL, $this->
getDescription());
235 $a_xml_writer->xmlElement(
"author", NULL, $this->
getAuthor());
236 if (strlen($this->label))
239 "label" => $this->label,
246 $a_xml_writer->xmlStartTag(
"questiontext", $attrs);
248 $a_xml_writer->xmlEndTag(
"questiontext");
250 $a_xml_writer->xmlStartTag(
"responses");
260 $a_xml_writer->xmlElement(
"response_text", $attrs);
261 $a_xml_writer->xmlEndTag(
"responses");
263 if (count($this->material))
265 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches))
268 "label" => $this->material[
"title"]
270 $a_xml_writer->xmlStartTag(
"material", $attrs);
271 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
272 if (strcmp($matches[1],
"") != 0)
274 $intlink = $this->material[
"internal_link"];
276 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
277 $a_xml_writer->xmlEndTag(
"material");
281 $a_xml_writer->xmlEndTag(
"question");
293 $result = $ilDB->queryF(
"SELECT maxchars FROM svy_question WHERE question_id = %s",
300 return $row[
"maxchars"];
313 return "SurveyTextQuestion";
324 return "svy_qst_text";
335 $entered_value = $post_data[$this->
getId() .
"_text_question"];
337 if (strlen($entered_value))
339 array_push(
$data, array(
"textanswer" => $entered_value));
355 $entered_value = $post_data[$this->
getId() .
"_text_question"];
359 if (strlen($entered_value) == 0)
return $this->lng->txt(
"text_question_not_filled_out");
367 $char_list =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
368 $char_list .=
"abcdefghijklmnopqrstuvwxyz";
369 $char_list .=
"1234567890";
370 for($i = 0; $i < $length; $i++)
372 $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
373 if (!rand(0,5)) $random .=
' ';
387 $randomtext = $this->
randomText(rand(25,100));
388 $next_id = $ilDB->nextId(
'svy_answer');
389 $affectedRows = $ilDB->manipulateF(
"INSERT INTO svy_answer (answer_id, question_fi, active_fi, value, textanswer, tstamp) VALUES (%s, %s, %s, %s, %s, %s)",
390 array(
'integer',
'integer',
'integer',
'float',
'text',
'integer'),
391 array($next_id, $this->
getId(), $active_id, NULL, $randomtext, time())
399 include_once
"./Services/Utilities/classes/class.ilUtil.php";
404 $entered_value = substr($entered_value, 0, $maxchars);
409 return array(array(
"value"=>null,
"textanswer"=>$entered_value));
411 if (strlen($entered_value) == 0)
return;
413 $next_id = $ilDB->nextId(
'svy_answer');
416 $fields[
'answer_id'] = array(
"integer", $next_id);
417 $fields[
'question_fi'] = array(
"integer", $this->
getId());
418 $fields[
'active_fi'] = array(
"integer", $active_id);
419 $fields[
'value'] = array(
"float", NULL);
420 $fields[
'textanswer'] = array(
"clob", (strlen($entered_value)) ? $entered_value : NULL);
421 $fields[
'tstamp'] = array(
"integer", time());
423 $affectedRows = $ilDB->insert(
"svy_answer", $fields);
431 $question_id = $this->
getId();
433 $result_array = array();
435 $textvalues = array();
437 $sql =
"SELECT svy_answer.* FROM svy_answer".
438 " JOIN svy_finished ON (svy_finished.finished_id = svy_answer.active_fi)".
439 " WHERE svy_answer.question_fi = ".$ilDB->quote($question_id,
"integer").
440 " AND svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer");
443 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
450 array_push($textvalues, $row[
"textanswer"]);
455 $result_array[
"USERS_ANSWERED"] =
$result->numRows();
456 $result_array[
"USERS_SKIPPED"] = $nr_of_users -
$result->numRows();
457 $result_array[
"QUESTION_TYPE"] =
"SurveyTextQuestion";
458 $result_array[
"textvalues"] = $textvalues;
459 return $result_array;
473 include_once (
"./Services/Excel/classes/class.ilExcelUtils.php");
474 $worksheet =& $workbook->addWorksheet();
476 switch ($export_label)
502 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_ANSWERED"]);
505 $worksheet->write($rowcounter, 1, $eval_data[
"USERS_SKIPPED"]);
510 if (is_array($eval_data[
"textvalues"]))
512 foreach ($eval_data[
"textvalues"] as $textvalue)
528 if (count($resultset[
"answers"][$this->
getId()]))
530 foreach ($resultset[
"answers"][$this->
getId()] as $key => $answer)
532 array_push($a_array, $answer[
"textanswer"]);
554 $sql =
"SELECT svy_answer.* FROM svy_answer, svy_finished".
555 " WHERE svy_finished.survey_fi = ".$ilDB->quote(
$survey_id,
"integer").
556 " AND svy_answer.question_fi = ".$ilDB->quote($this->
getId(),
"integer").
557 " AND svy_finished.finished_id = svy_answer.active_fi";
560 $sql .=
" AND ".$ilDB->in(
"svy_finished.finished_id", $finished_ids,
"",
"integer");
565 $answers[
$row[
"active_fi"]] = $row[
"textanswer"];
580 if (
$data[
"maxlength"] > 0)
584 if (
$data[
"rows"] > 0)
588 if (
$data[
"columns"] > 0)
614 return ($this->textwidth) ? $this->textwidth : NULL;
625 return ($this->textheight) ? $this->textheight : NULL;
636 if ($a_textwidth < 1)
638 $this->textwidth = 50;
642 $this->textwidth = $a_textwidth;
654 if ($a_textheight < 1)
656 $this->textheight = 5;
660 $this->textheight = $a_textheight;
setTextHeight($a_textheight)
Sets the height of the answer field.
getTextWidth()
Returns the width of the answer field.
insertXML(&$a_xml_writer, $a_include_header=TRUE, $obligatory_state="")
Adds the question XML to a given XMLWriter object.
getAuthor()
Gets the authors name of the SurveyQuestion object.
$cumulated
An array containing the cumulated results of the question for a given survey.
getTitle()
Gets the title string of the SurveyQuestion object.
_getQuestionDataArray($id)
Returns the question data fields from the database.
getObligatory($survey_id="")
Gets the obligatory state of the question.
setObligatory($obligatory=1)
Sets the obligatory state of the question.
toXML($a_include_header=TRUE, $obligatory_state="")
Returns an xml representation of the question.
_convert_text($a_text, $a_target="has been removed")
saveToDb($original_id="")
Saves a SurveyTextQuestion object to a database.
& getCumulatedResults($survey_id, $nr_of_users, $finished_ids)
setId($id=-1)
Sets the id of the SurveyQuestion object.
saveRandomData($active_id)
Saves random answers for a given active user in the database.
isComplete()
Returns true if the question is complete for use.
getQuestiontext()
Gets the questiontext of the SurveyQuestion object.
getQuestionType()
Returns the question type of the question.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
setOwner($owner="")
Sets the creator/owner ID of the SurveyQuestion object.
SurveyTextQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
The constructor takes possible arguments an creates an instance of the SurveyTextQuestion object...
setComplete($a_complete)
Sets the complete state of the question.
setMaxChars($maxchars=0)
Sets the maximum number of allowed characters for the text answer.
setOriginalId($original_id)
_getMaxChars($question_id)
Returns the maxium number of allowed characters for the text answer.
checkUserInput($post_data, $survey_id)
Checks the input of the active user for obligatory status and entered values.
SurveyQuestion( $title="", $description="", $author="", $questiontext="", $owner=-1)
SurveyQuestion constructor The constructor takes possible arguments an creates an instance of the Sur...
setQuestiontext($questiontext="")
Sets the questiontext of the SurveyQuestion object.
addUserSpecificResultsData(&$a_array, &$resultset)
Adds the values for the user specific results export for a given user.
saveUserInput($post_data, $active_id, $a_return=false)
getId()
Gets the id of the SurveyQuestion object.
importResponses($a_data)
Import response data from the question import file.
Basic class for all survey question types.
saveMaterial()
save material to db
loadFromDb($id)
Loads a SurveyTextQuestion object from the database.
xmlHeader()
Writes xml header public.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
usableForPrecondition()
Returns if the question is usable for preconditions.
setAuthor($author="")
Sets the authors name of the SurveyQuestion object.
addMaterialTag(&$a_xml_writer, $a_material, $close_material_tag=TRUE, $add_mobs=TRUE, $a_attrs=null)
Creates an XML material tag from a plain text or xhtml text.
setExportDetailsXLS(&$workbook, &$format_title, &$format_bold, &$eval_data, $export_label)
Creates an Excel worksheet for the detailed cumulated results of this question.
setDescription($description="")
Sets the description string of the SurveyQuestion object.
& getWorkingDataFromUserInput($post_data)
Creates the user data of the svy_answer table from the POST data.
getAdditionalTableName()
Returns the name of the additional question data table in the database.
getDescription()
Gets the description string of the SurveyQuestion object.
setObjId($obj_id=0)
Set the reference id of the container object.
getMaxChars()
Returns the maximum number of allowed characters for the text answer.
getTextHeight()
Returns the height of the answer field.
setTextWidth($a_textwidth)
Sets the width of the answer field.
& getUserAnswers($survey_id, $finished_ids)
Returns an array containing all answers to this question in a given survey.
setTitle($title="")
Sets the title string of the SurveyQuestion object.