41 $this->db =
$DIC->database();
42 $this->
user = $DIC->user();
43 $this->
lng = $DIC->language();
57 $result =
$ilDB->queryF(
58 "SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
62 while ($row =
$ilDB->fetchAssoc($result)) {
63 if ((
int) $row[
"defaultvalue"] === 1 && (
int) $row[
"owner_fi"] === 0) {
80 $result =
$ilDB->queryF(
81 "SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s AND (svy_category.owner_fi = 0 OR svy_category.owner_fi = %s) ORDER BY svy_phrase_cat.sequence",
82 array(
'integer',
'integer'),
83 array($phrase_id,
$ilUser->getId())
85 while ($row =
$ilDB->fetchAssoc($result)) {
86 $neutral = $row[
"neutral"];
87 if ((
int) $row[
"defaultvalue"] === 1 && (
int) $row[
"owner_fi"] === 0) {
88 $this->categories->addCategory($this->
lng->txt($row[
"title"]), 0, $neutral);
90 $this->categories->addCategory($row[
"title"], 0, $neutral);
99 $result =
$ilDB->queryF(
104 if ($result->numRows() === 1) {
105 return $ilDB->fetchAssoc($result);
115 $result =
$ilDB->queryF(
120 if ($result->numRows() === 1) {
123 $this->
setTitle((
string) $data[
"title"]);
124 $this->label = (string)
$data[
'label'];
126 $this->
setObjId((
int) $data[
"obj_fi"]);
127 $this->
setAuthor((
string) $data[
"author"]);
128 $this->
setOwner((
int) $data[
"owner_fi"]);
135 $this->categories->flushCategories();
136 $result =
$ilDB->queryF(
137 "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",
141 if ($result->numRows() > 0) {
143 $this->categories->addCategory((
string)
$data[
"title"], (
int)
$data[
"other"], (
int)
$data[
"neutral"],
null, (
$data[
'scale']) ?: (
$data[
'sequence'] + 1));
147 parent::loadFromDb($question_id);
156 $this->categories->getCategoryCount()
169 if ($affectedRows === 1) {
170 $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");
174 array($this->
getId())
178 array(
'integer',
'text'),
188 return $affectedRows;
195 $this->log->debug(
"DELETE from svy_variable before the INSERT into svy_variable. if scale > 0 we get scale value else we get null");
197 $affectedRows =
$ilDB->manipulateF(
198 "DELETE FROM svy_variable WHERE question_fi = %s",
200 array($this->
getId())
203 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
204 $cat = $this->categories->getCategory(
$i);
206 $next_id =
$ilDB->nextId(
'svy_variable');
207 $affectedRows =
$ilDB->manipulateF(
208 "INSERT INTO svy_variable (variable_id, category_fi, question_fi, value1, other, sequence, scale, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
209 array(
'integer',
'integer',
'integer',
'float',
'integer',
'integer',
'integer',
'integer'),
210 array($next_id, $category_id, $this->
getId(), (
$i + 1), $cat->other,
$i, ($cat->scale > 0) ? $cat->scale :
null, time())
213 $debug_scale = ($cat->scale > 0) ? $cat->scale :
null;
214 $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);
220 bool $a_include_header =
true,
221 bool $obligatory_state =
false
225 $this->
insertXML($a_xml_writer, $a_include_header);
226 $xml = $a_xml_writer->xmlDumpMem(
false);
227 if (!$a_include_header) {
228 $pos = strpos(
$xml,
"?>");
236 bool $a_include_header =
true
239 "id" => $this->
getId(),
240 "title" => $this->getTitle(),
241 "type" => $this->getQuestionType(),
242 "obligatory" => $this->getObligatory()
246 $a_xml_writer->
xmlElement(
"description",
null, $this->getDescription());
247 $a_xml_writer->
xmlElement(
"author",
null, $this->getAuthor());
248 if (strlen($this->label)) {
250 "label" => $this->label,
255 $a_xml_writer->
xmlStartTag(
"questiontext", $attrs);
256 $this->addMaterialTag($a_xml_writer, $this->getQuestiontext());
257 $a_xml_writer->
xmlEndTag(
"questiontext");
261 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
265 if (strlen($this->categories->getCategory(
$i)->other)) {
266 $attrs[
'other'] = $this->categories->getCategory(
$i)->other;
268 if (strlen($this->categories->getCategory(
$i)->neutral)) {
269 $attrs[
'neutral'] = $this->categories->getCategory(
$i)->neutral;
271 if (strlen($this->categories->getCategory(
$i)->label)) {
272 $attrs[
'label'] = $this->categories->getCategory(
$i)->label;
274 if (strlen($this->categories->getCategory(
$i)->scale)) {
275 $attrs[
'scale'] = $this->categories->getCategory(
$i)->scale;
277 $a_xml_writer->
xmlStartTag(
"response_single", $attrs);
278 $this->addMaterialTag($a_xml_writer, $this->categories->getCategory(
$i)->title);
279 $a_xml_writer->
xmlEndTag(
"response_single");
284 if (count($this->material)) {
285 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $this->material[
"internal_link"] ??
"", $matches)) {
287 "label" => $this->material[
"title"]
290 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
291 if (strcmp($matches[1],
"") != 0) {
292 $intlink = $this->material[
"internal_link"];
294 $a_xml_writer->
xmlElement(
"mattext",
null, $intlink);
301 $a_xml_writer->
xmlElement(
"fieldlabel",
null,
"orientation");
302 $a_xml_writer->
xmlElement(
"fieldentry",
null, $this->getOrientation());
303 $a_xml_writer->
xmlEndTag(
"metadatafield");
311 foreach ($a_meta as
$key => $value) {
312 switch ($value[
"label"]) {
314 $this->setOrientation($value[
"entry"]);
327 for (
$i = $lower_limit;
$i <= $upper_limit;
$i++) {
328 $this->categories->addCategory(
$i);
341 $next_id =
$ilDB->nextId(
'svy_phrase');
342 $affectedRows =
$ilDB->manipulateF(
343 "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
344 array(
'integer',
'text',
'text',
'integer',
'integer'),
345 array($next_id, $title, 1,
$ilUser->getId(), time())
347 $phrase_id = $next_id;
350 $phrase_data = $this->edit_manager->getPhraseData();
351 foreach ($phrase_data as
$data) {
352 $next_id =
$ilDB->nextId(
'svy_category');
353 $affectedRows =
$ilDB->manipulateF(
354 "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
355 array(
'integer',
'text',
'text',
'integer',
'integer',
'text'),
358 $category_id = $next_id;
359 $next_id =
$ilDB->nextId(
'svy_phrase_cat');
360 $affectedRows =
$ilDB->manipulateF(
361 "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence, other, scale) VALUES (%s, %s, %s, %s, %s, %s)",
362 array(
'integer',
'integer',
'integer',
'integer',
'integer',
'integer'),
363 array($next_id, $phrase_id, $category_id, $counter, (
$data[
'other']) ? 1 : 0,
$data[
'scale'])
371 return "SurveySingleChoiceQuestion";
382 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
384 if (strlen($entered_value)) {
385 $data[] = array(
"value" => $entered_value,
386 "textanswer" => $post_data[$this->
getId() .
'_' . $entered_value .
'_other'] ??
""
389 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
390 $cat = $this->categories->getCategory(
$i);
392 if (
$i != $entered_value) {
393 if (strlen($post_data[$this->
getId() .
"_" .
$i .
"_other"] ??
"")) {
395 "textanswer" => $post_data[$this->
getId() .
'_' .
$i .
'_other'] ??
"",
413 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
415 $this->log->debug(
"Entered value = " . $entered_value);
417 if ((!$this->getObligatory()) && (strlen($entered_value) == 0)) {
421 if (strlen($entered_value) == 0) {
422 return $this->
lng->txt(
"question_not_checked");
425 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
426 $cat = $this->categories->getCategory(
$i);
428 if (
$i == $entered_value) {
429 if (array_key_exists($this->
getId() .
"_" . $entered_value .
"_other", $post_data) && !strlen($post_data[$this->
getId() .
"_" . $entered_value .
"_other"])) {
430 return $this->
lng->txt(
"question_mr_no_other_answer");
432 } elseif (strlen($post_data[$this->
getId() .
"_" .
$i .
"_other"] ??
"")) {
433 return $this->
lng->txt(
"question_sr_no_other_answer_checked");
444 bool $a_return =
false
448 $entered_value = $post_data[$this->
getId() .
"_value"] ??
"";
451 return array(array(
"value" => $entered_value,
452 "textanswer" => $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] ??
""));
454 if (strlen($entered_value) == 0) {
458 $next_id =
$ilDB->nextId(
'svy_answer');
461 $fields[
'answer_id'] = array(
"integer", $next_id);
462 $fields[
'question_fi'] = array(
"integer", $this->
getId());
463 $fields[
'active_fi'] = array(
"integer", $active_id);
464 $fields[
'value'] = array(
"float", (strlen($entered_value)) ? $entered_value :
null);
465 $fields[
'textanswer'] = array(
"clob", isset($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) ?
466 $this->stripSlashesAddSpaceFallback($post_data[$this->
getId() .
"_" . $entered_value .
"_other"]) :
null);
467 $fields[
'tstamp'] = array(
"integer", time());
469 $affectedRows =
$ilDB->insert(
"svy_answer", $fields);
471 $debug_value = (strlen($entered_value)) ? $entered_value :
"NULL";
472 $debug_answer = $post_data[$this->
getId() .
"_" . $entered_value .
"_other"] ??
"NULL";
473 $this->log->debug(
"INSERT svy_answer answer_id=" . $next_id .
" question_fi=" . $this->
getId() .
" active_fi=" . $active_id .
" value=" . $debug_value .
" textanswer=" . $debug_answer);
481 foreach (
$data[
"material"] as $material) {
482 $categorytext .= $material[
"text"];
484 $this->categories->addCategory(
487 strlen(
$data[
'neutral']) ?
$data[
'neutral'] : 0,
488 strlen(
$data[
'label']) ?
$data[
'label'] :
null,
489 strlen(
$data[
'scale']) ?
$data[
'scale'] :
null
501 return array(
"<",
"<=",
"=",
"<>",
">=",
">");
507 for (
$i = 0;
$i < $this->categories->getCategoryCount();
$i++) {
508 $category = $this->categories->getCategory(
$i);
509 $options[$category->scale - 1] = $category->scale .
" - " . $category->title;
520 $options = $this->getPreconditionOptions();
521 $step3->setOptions($options);
522 $step3->setValue($default);
530 $category = $this->categories->getCategoryForScale((
int) $value + 1);
535 $scale = $category->scale;
536 $title = $category->title;
542 ((strlen($title)) ? $title : $this->
lng->txt(
'other_answer'));
547 return $this->categories;
555 $db =
$DIC->database();
557 "SELECT SUM(max_sum_score) sum_sum_score FROM (SELECT MAX(scale) max_sum_score FROM svy_svy_qst sq " .
558 "JOIN svy_question q ON (sq.question_fi = q.question_id) " .
559 "JOIN svy_variable v ON (v.question_fi = q.question_id) " .
560 "WHERE sq.survey_fi = %s AND q.questiontype_fi = %s " .
561 "GROUP BY (q.question_id)) x",
562 [
"integer",
"integer"],
565 $rec = $db->fetchAssoc($set);
566 return (
int) $rec[
"sum_sum_score"];
571 if ($nr_answer_records == 1) {
577 public static function compressable(
585 if ($q1->getOrientation() !== 1 || $q2->getOrientation() !== 1) {
588 if (self::getCompressCompareString($q1) === self::getCompressCompareString($q2)) {
598 for (
$i = 0;
$i < $q->categories->getCategoryCount();
$i++) {
599 $cat = $q->categories->getCategory(
$i);
600 $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)
savePhrase(string $title)
Saves a set of categories to a default phrase note: data comes from session.
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)
addPhrase(int $phrase_id)
Adds a phrase to the question.
getCategoriesForPhrase(int $phrase_id)
Gets the available categories for a given phrase.
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