41 $this->db =
$DIC->database();
42 $this->
user = $DIC->user();
43 $this->
lng = $DIC->language();
55 $result =
$ilDB->queryF(
60 if ($result->numRows() === 1) {
61 return $ilDB->fetchAssoc($result);
71 $result =
$ilDB->queryF(
76 if ($result->numRows() === 1) {
79 $this->
setTitle((
string) $data[
"title"]);
80 $this->label = (string)
$data[
'label'];
82 $this->
setObjId((
int) $data[
"obj_fi"]);
83 $this->
setAuthor((
string) $data[
"author"]);
84 $this->
setOwner((
int) $data[
"owner_fi"]);
91 $this->categories->flushCategories();
92 $result =
$ilDB->queryF(
93 "SELECT svy_variable.*, svy_category.title, svy_category.neutral FROM svy_variable, svy_category WHERE svy_variable.question_fi = %s AND svy_variable.category_fi = svy_category.category_id ORDER BY sequence ASC",
97 if ($result->numRows() > 0) {
99 $this->categories->addCategory(
$data[
"title"],
$data[
"other"],
$data[
"neutral"],
null, (
$data[
'scale']) ?: (
$data[
'sequence'] + 1));
103 parent::loadFromDb($question_id);
112 $this->categories->getCategoryCount()
125 if ($affectedRows === 1) {
126 $this->log->debug(
"Before save Category-> DELETE from svy_qst_sc WHERE question_fi = " . $this->
getId() .
" AND INSERT again the same id and orientation in svy_qst_sc");
130 array($this->
getId())
134 array(
'integer',
'text'),
143 return $affectedRows;
150 $this->log->debug(
"DELETE from svy_variable before the INSERT into svy_variable. if scale > 0 we get scale value else we get null");
152 $affectedRows =
$ilDB->manipulateF(
153 "DELETE FROM svy_variable WHERE question_fi = %s",
155 array($this->
getId())
158 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
159 $cat = $this->categories->getCategory($i);
161 $next_id =
$ilDB->nextId(
'svy_variable');
162 $affectedRows =
$ilDB->manipulateF(
163 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
164 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
165 array($next_id, $category_id, $this->
getId(), ($i + 1), $cat->other, $i, ($cat->scale > 0) ? $cat->scale :
null, time())
168 $debug_scale = ($cat->scale > 0) ? $cat->scale :
null;
169 $this->log->debug(
"INSERT INTO svy_variable category_fi= " . $category_id .
" question_fi= " . $this->getId() .
" value1= " . ($i + 1) .
" other= " . $cat->other .
" sequence= " . $i .
" scale =" . $debug_scale);
175 bool $a_include_header =
true,
176 bool $obligatory_state =
false
180 $this->
insertXML($a_xml_writer, $a_include_header);
181 $xml = $a_xml_writer->xmlDumpMem(
false);
182 if (!$a_include_header) {
183 $pos = strpos($xml,
"?>");
184 $xml = substr($xml, $pos + 2);
191 bool $a_include_header =
true
194 "id" => $this->
getId(),
196 "type" => $this->getQuestionType(),
197 "obligatory" => $this->getObligatory()
201 $a_xml_writer->
xmlElement(
"description",
null, $this->getDescription());
202 $a_xml_writer->
xmlElement(
"author",
null, $this->getAuthor());
203 if (strlen($this->label ??
"")) {
205 "label" => $this->label,
210 $a_xml_writer->
xmlStartTag(
"questiontext", $attrs);
211 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
212 $a_xml_writer->
xmlEndTag(
"questiontext");
216 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
220 if (strlen($this->categories->getCategory($i)->other ??
"")) {
221 $attrs[
'other'] = $this->categories->getCategory($i)->other;
223 if (strlen($this->categories->getCategory($i)->neutral ??
"")) {
224 $attrs[
'neutral'] = $this->categories->getCategory($i)->neutral;
226 if (strlen($this->categories->getCategory($i)->label ??
"")) {
227 $attrs[
'label'] = $this->categories->getCategory($i)->label;
229 if (strlen($this->categories->getCategory($i)->scale ??
"")) {
230 $attrs[
'scale'] = $this->categories->getCategory($i)->scale;
232 $a_xml_writer->
xmlStartTag(
"response_single", $attrs);
233 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory($i)->title);
234 $a_xml_writer->
xmlEndTag(
"response_single");
239 if (count($this->material)) {
240 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"] ??
"", $matches)) {
242 "label" => $this->material[
"title"]
245 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
246 if (strcmp($matches[1],
"") != 0) {
247 $intlink = $this->material[
"internal_link"];
249 $a_xml_writer->
xmlElement(
"mattext",
null, $intlink);
256 $a_xml_writer->
xmlElement(
"fieldlabel",
null,
"orientation");
257 $a_xml_writer->
xmlElement(
"fieldentry",
null, $this->getOrientation());
258 $a_xml_writer->
xmlEndTag(
"metadatafield");
266 foreach ($a_meta as $key => $value) {
267 switch ($value[
"label"]) {
269 $this->setOrientation($value[
"entry"]);
282 for ($i = $lower_limit; $i <= $upper_limit; $i++) {
283 $this->categories->addCategory($i);
289 return "SurveySingleChoiceQuestion";
300 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
302 if (strlen($entered_value ??
"")) {
303 $data[] = array(
"value" => $entered_value,
304 "textanswer" => $post_data[$this->
getId() .
'_' . $entered_value .
'_other'] ??
""
307 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
308 $cat = $this->categories->getCategory($i);
310 if ($i != $entered_value) {
311 if (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"] ??
"")) {
312 $data[] = array(
"value" => $i,
313 "textanswer" => $post_data[$this->
getId() .
'_' . $i .
'_other'] ??
"",
331 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
333 $this->log->debug(
"Entered value = " . $entered_value);
335 if ((!$this->getObligatory()) && (strlen($entered_value ??
"") == 0)) {
339 if (strlen($entered_value ??
"") == 0) {
340 return $this->
lng->txt(
"question_not_checked");
343 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
344 $cat = $this->categories->getCategory($i);
346 if ($i == $entered_value) {
347 if (array_key_exists($this->
getId() .
"_" . $entered_value .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $entered_value .
"_other"] ??
"")) {
348 return $this->
lng->txt(
"question_mr_no_other_answer");
350 } elseif (strlen($post_data[$this->
getId() .
"_" . $i .
"_other"] ??
"")) {
351 return $this->
lng->txt(
"question_sr_no_other_answer_checked");
362 bool $a_return =
false
366 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
369 return array(array(
"value" => $entered_value,
370 "textanswer" => $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] ??
""));
372 if (strlen($entered_value ??
"") == 0) {
376 $next_id =
$ilDB->nextId(
'svy_answer');
379 $fields[
'answer_id'] = array(
"integer", $next_id);
380 $fields[
'question_fi'] = array(
"integer", $this->
getId());
381 $fields[
'active_fi'] = array(
"integer", $active_id);
382 $fields[
'value'] = array(
"float", (strlen($entered_value ??
"")) ? $entered_value :
null);
383 $fields[
'textanswer'] = array(
"clob", isset($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ?
384 $this->stripSlashesAddSpaceFallback($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) :
null);
385 $fields[
'tstamp'] = array(
"integer", time());
387 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
389 $debug_value = (strlen($entered_value ??
"")) ? $entered_value :
"NULL";
390 $debug_answer = $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] ??
"NULL";
391 $this->log->debug(
"INSERT svy_answer answer_id=" . $next_id .
" question_fi=" . $this->
getId() .
" active_fi=" . $active_id .
" value=" . $debug_value .
" textanswer=" . $debug_answer);
399 foreach (
$data[
"material"] as $material) {
400 $categorytext .= $material[
"text"];
402 $this->categories->addCategory(
404 strlen(
$data[
'other'] ??
"") ?
$data[
'other'] : 0,
405 strlen(
$data[
'neutral'] ??
"") ?
$data[
'neutral'] : 0,
406 strlen(
$data[
'label'] ??
"") ?
$data[
'label'] :
null,
407 strlen(
$data[
'scale'] ??
"") ?
$data[
'scale'] :
null
419 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
425 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
426 $category = $this->categories->getCategory($i);
427 $options[$category->scale - 1] = $category->scale .
" - " . $category->title;
438 $options = $this->getPreconditionOptions();
439 $step3->setOptions($options);
440 $step3->setValue($default);
448 $category = $this->categories->getCategoryForScale((
int) $value + 1);
453 $scale = $category->scale;
454 $title = $category->title;
460 ((strlen($title)) ? $title : $this->
lng->txt(
'other_answer'));
465 return $this->categories;
473 $db =
$DIC->database();
475 "SELECT SUM(max_sum_score) sum_sum_score FROM (SELECT MAX(scale) max_sum_score FROM svy_svy_qst sq " .
476 "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
477 "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
478 "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s " .
479 "GROUP BY (q.question_id)) x",
480 [
"integer",
"integer"],
483 $rec = $db->fetchAssoc($set);
484 return (
int) $rec[
"sum_sum_score"];
489 if ($nr_answer_records == 1) {
495 public static function compressable(
503 if ($q1->getOrientation() !== 1 || $q2->getOrientation() !== 1) {
506 if (self::getCompressCompareString($q1) === self::getCompressCompareString($q2)) {
516 for ($i = 0; $i <
$q->categories->getCategoryCount(); $i++) {
517 $cat =
$q->categories->getCategory($i);
518 $str .=
":" . $cat->scale .
":" . $cat->title;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $title="")
saveCategoryToDb(string $categorytext, int $neutral=0)
Saves a category to the database.
setQuestiontext(string $questiontext="")
setDescription(string $description="")
setObjId(int $obj_id=0)
Set the reference(?) id of the container object.
setOrientation(int $orientation=0)
static _instanciateQuestion(int $question_id)
Get question object.
setComplete(bool $a_complete)
setOriginalId(?int $original_id)
saveCompletionStatus(int $original_id=0)
Saves the complete flag to the database.
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...
insertXML(ilXmlWriter $a_xml_writer, bool $a_include_header=true)
saveToDb(int $original_id=0)
Saves a SurveyQuestion object to a database.
saveUserInput(array $post_data, int $active_id, bool $a_return=false)
getPreconditionOptions()
Returns the options for preconditions.
checkUserInput(array $post_data, int $survey_id)
Checks the input of the active user for obligatory status and entered values.
isSumScoreValid(int $nr_answer_records)
loadFromDb(int $question_id)
load question data into object note: this base implementation only loads the material data
__construct(string $title="", string $description="", string $author="", string $questiontext="", int $owner=-1, int $orientation=1)
getQuestionDataArray(int $id)
Returns the question data.
usableForPrecondition()
Returns if the question is usable for preconditions.
SurveyCategories $categories
importResponses(array $a_data)
Import response data from the question import file.
static getCompressCompareString(SurveySingleChoiceQuestion $q)
getPreconditionValueOutput(string $value)
Returns the output for a precondition value.
getPreconditionSelectValue(string $default, string $title, string $variable)
Creates a form property for the precondition value.
getAvailableRelations()
Returns the available relations for the question.
toXML(bool $a_include_header=true, bool $obligatory_state=false)
importAdditionalMetadata(array $a_meta)
Import additional meta data from the question import file.
addStandardNumbers(int $lower_limit, int $upper_limit)
Adds standard numbers as categories.
getWorkingDataFromUserInput(array $post_data)
Creates the user data of the svy_answer table from the POST data.
static getMaxSumScore(int $survey_id)
Get max sum score for specific survey (and this question type)
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...
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