42 $this->db =
$DIC->database();
46 $this->textwidth = 50;
47 $this->textheight = 5;
53 $result =
$ilDB->queryF(
58 if ($result->numRows() === 1) {
59 return $ilDB->fetchAssoc($result);
69 $result =
$ilDB->queryF(
74 if ($result->numRows() === 1) {
77 $this->
setTitle((
string) $data[
"title"]);
78 $this->label = (string)
$data[
'label'];
80 $this->
setObjId((
int) $data[
"obj_fi"]);
81 $this->
setAuthor((
string) $data[
"author"]);
82 $this->
setOwner((
int) $data[
"owner_fi"]);
92 parent::loadFromDb($question_id);
123 if ($affectedRows === 1) {
127 array($this->
getId())
130 "INSERT INTO " . $this->
getAdditionalTableName() .
" (question_fi, maxchars, width, height) VALUES (%s, %s, %s, %s)",
131 array(
'integer',
'integer',
'integer',
'integer'),
137 return $affectedRows;
141 bool $a_include_header =
true,
142 bool $obligatory_state =
false
146 $this->
insertXML($a_xml_writer, $a_include_header);
147 $xml = $a_xml_writer->xmlDumpMem(
false);
148 if (!$a_include_header) {
149 $pos = strpos(
$xml,
"?>");
157 $a_include_header =
true
160 "id" => $this->
getId(),
161 "title" => $this->getTitle(),
162 "type" => $this->getQuestionType(),
163 "obligatory" => $this->getObligatory()
167 $a_xml_writer->
xmlElement(
"description",
null, $this->getDescription());
168 $a_xml_writer->
xmlElement(
"author",
null, $this->getAuthor());
169 if (strlen($this->label)) {
171 "label" => $this->label,
176 $a_xml_writer->
xmlStartTag(
"questiontext", $attrs);
177 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
178 $a_xml_writer->
xmlEndTag(
"questiontext");
183 "rows" => $this->getTextHeight(),
184 "columns" => $this->getTextWidth()
186 if ($this->getMaxChars() > 0) {
187 $attrs[
"maxlength"] = $this->getMaxChars();
189 $a_xml_writer->
xmlElement(
"response_text", $attrs);
192 if (count($this->material)) {
193 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"], $matches)) {
195 "label" => $this->material[
"title"]
198 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
199 if (strcmp($matches[1],
"") != 0) {
200 $intlink = $this->material[
"internal_link"];
202 $a_xml_writer->
xmlElement(
"mattext",
null, $intlink);
212 return "SurveyTextQuestion";
217 return "svy_qst_text";
223 $entered_value = $post_data[$this->
getId() .
"_text_question"] ??
"";
225 if (strlen($entered_value)) {
226 $data[] = array(
"textanswer" => $entered_value);
239 $entered_value = $post_data[$this->
getId() .
"_text_question"];
241 if ((!$this->getObligatory()) && (strlen($entered_value) == 0)) {
245 if (strlen($entered_value) == 0) {
246 return $this->
lng->txt(
"text_question_not_filled_out");
250 if ($this->getMaxChars() > 0 &&
ilStr::strLen($entered_value) > $this->getMaxChars()) {
251 return str_replace(
"%s",
ilStr::strLen($entered_value), $this->
lng->txt(
"svy_answer_too_long"));
260 bool $a_return =
false
264 $entered_value = $this->stripSlashesAddSpaceFallback($post_data[$this->
getId() .
"_text_question"]);
265 $maxchars = $this->getMaxChars();
268 $entered_value =
ilStr::subStr($entered_value, 0, $maxchars);
272 return array(array(
"value" =>
null,
"textanswer" => $entered_value));
274 if (strlen($entered_value) == 0) {
278 $next_id =
$ilDB->nextId(
'svy_answer');
281 $fields[
'answer_id'] = array(
"integer", $next_id);
282 $fields[
'question_fi'] = array(
"integer", $this->
getId());
283 $fields[
'active_fi'] = array(
"integer", $active_id);
284 $fields[
'value'] = array(
"float",
null);
285 $fields[
'textanswer'] = array(
"clob", (strlen($entered_value)) ? $entered_value :
null);
286 $fields[
'tstamp'] = array(
"integer", time());
288 $ilDB->insert(
"svy_answer", $fields);
296 if (
$data[
"maxlength"] > 0) {
297 $this->setMaxChars(
$data[
"maxlength"]);
299 if (
$data[
"rows"] > 0) {
300 $this->setTextHeight(
$data[
"rows"]);
302 if (
$data[
"columns"] > 0) {
303 $this->setTextWidth(
$data[
"columns"]);
315 return $this->textwidth;
320 return $this->textheight;
325 if ($a_textwidth < 1) {
326 $this->textwidth = 50;
328 $this->textwidth = $a_textwidth;
334 if ($a_textheight < 1) {
335 $this->textheight = 5;
337 $this->textheight = $a_textheight;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $title="")
setQuestiontext(string $questiontext="")
setDescription(string $description="")
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
setComplete(bool $a_complete)
setOriginalId(?int $original_id)
setObligatory(bool $obligatory=true)
setAuthor(string $author="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importResponses(array $a_data)
Import response data from the question import file.
toXML(bool $a_include_header=true, bool $obligatory_state=false)
setTextHeight(?int $a_textheight=null)
saveToDb(int $original_id=0)
Saves a SurveyQuestion object to a database.
usableForPrecondition()
Returns if the question is usable for preconditions.
checkUserInput(array $post_data, int $survey_id)
Checks the input of the active user for obligatory status and entered values.
getQuestionDataArray(int $id)
Returns the question data.
setMaxChars(int $maxchars=0)
insertXML(ilXmlWriter $a_xml_writer, $a_include_header=true)
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1)
loadFromDb(int $question_id)
load question data into object note: this base implementation only loads the material data
setTextWidth(?int $a_textwidth=null)
getWorkingDataFromUserInput(array $post_data)
Creates the user data of the svy_answer table from the POST data.
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static subStr(string $a_str, int $a_start, ?int $a_length=null)
static strLen(string $a_string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc