26 protected \ILIAS\SurveyQuestionPool\Export\ImportSessionRepository
$session_repo;
82 ?
string $a_xml_file =
'',
83 bool $spl_exists =
false,
89 $this->spl_id = $a_spl_id;
90 $this->has_error =
false;
91 $this->characterbuffer =
"";
92 $this->survey_status =
false;
93 $this->activetag =
"";
94 $this->material = array();
96 $this->path = array();
97 $this->metadata = array();
98 $this->responses = array();
99 $this->variables = array();
100 $this->response_id =
"";
101 $this->matrix = array();
102 $this->is_matrix =
false;
103 $this->adjectives = array();
105 $this->survey = null;
106 $this->in_survey =
false;
107 $this->anonymisation = 0;
108 $this->surveyaccess =
"restricted";
109 $this->questions = array();
110 $this->original_question_id =
"";
111 $this->constraints = array();
112 $this->textblock =
"";
113 $this->textblocks = array();
114 $this->in_questionblock =
false;
115 $this->questionblocks = array();
116 $this->questionblock = array();
117 $this->showQuestiontext = 1;
118 $this->showBlocktitle = 0;
119 $this->compressView = 0;
120 $this->questionblocktitle =
"";
121 $this->mapping = $a_mapping;
122 $this->session_repo = $DIC->surveyQuestionPool()->internal()
128 $this->survey = $a_svy;
133 xml_set_object($a_xml_parser, $this);
134 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
135 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
142 public function parse($a_xml_parser, $a_fp = null): void
147 while (
$data = fread($a_fp, 4096)) {
148 $parseOk = xml_parse($a_xml_parser,
$data, feof($a_fp));
157 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
158 $this->error_code = xml_get_error_code($a_xml_parser);
159 $this->error_line = xml_get_current_line_number($a_xml_parser);
160 $this->error_col = xml_get_current_column_number($a_xml_parser);
161 $this->error_msg = xml_error_string($this->error_code);
162 $this->has_error =
true;
168 if ($this->depth > 0) {
169 return $this->path[$this->depth - 1];
178 public function handlerBeginTag($a_xml_parser,
string $a_name, array $a_attribs): void
183 $this->characterbuffer =
"";
184 $this->activetag = $a_name;
186 $this->attributes += count($a_attribs);
188 case "questionblock":
189 $this->in_questionblock =
true;
190 $this->questionblock = array();
191 $this->questionblocktitle =
"";
192 $this->showQuestiontext = 1;
193 $this->showBlocktitle = 0;
194 $this->compressView = 0;
195 foreach ($a_attribs as
$attrib => $value) {
197 case "showQuestiontext":
198 $this->showQuestiontext = (
int) $value;
200 case "showBlocktitle":
201 $this->showBlocktitle = (
int) $value;
204 $this->compressView = (
int) $value;
209 case "surveyquestions":
210 foreach ($a_attribs as
$attrib => $value) {
213 if ($this->spl_id > 0) {
215 $spl->setOnline($value);
223 $this->in_survey =
true;
224 foreach ($a_attribs as
$attrib => $value) {
227 if (is_object($this->survey)) {
228 $this->survey->setTitle($value);
229 $this->survey->update(
true);
235 case "anonymisation":
236 foreach ($a_attribs as
$attrib => $value) {
239 $this->anonymisation = $value;
245 foreach ($a_attribs as
$attrib => $value) {
248 $this->surveyaccess = $value;
254 $this->constraints[] = array(
255 "sourceref" => $a_attribs[
"sourceref"],
256 "destref" => $a_attribs[
"destref"],
257 "relation" => $a_attribs[
"relation"],
258 "value" => $a_attribs[
"value"],
261 "conjunction" => (
int) ($a_attribs[
"conjuction"] ?? 0)
266 $type = $a_attribs[
"type"];
269 case 'SurveyNominalQuestion':
270 $type =
'SurveyMultipleChoiceQuestion';
271 foreach ($a_attribs as
$key => $value) {
275 $type =
'SurveySingleChoiceQuestion';
277 $type =
'SurveyMultipleChoiceQuestion';
283 case 'SurveyOrdinalQuestion':
284 $type =
'SurveySingleChoiceQuestion';
289 $this->activequestion =
new $type();
293 if ($this->spl_id < 0) {
294 $q_obj_id = $this->survey->getId();
297 $this->activequestion->setObjId($q_obj_id);
300 $this->activequestion = null;
302 $this->original_question_id = $a_attribs[
"id"];
303 if ($this->in_questionblock) {
306 if (is_object($this->activequestion)) {
307 foreach ($a_attribs as
$key => $value) {
310 $this->activequestion->setTitle($value);
313 $this->activequestion->setSubtype($value);
316 $this->activequestion->setObligatory($value);
326 $this->material = array();
329 $this->material[] = array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"] ??
"");
333 if (array_key_exists(
"label", $a_attribs)) {
334 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"] ??
"", $matches)) {
336 $this->session_repo->addMob(
337 $a_attribs[
"label"] ??
"",
346 $this->metadata = array();
348 case "metadatafield":
349 $this->metadata[] = array(
"label" =>
"",
"entry" =>
"");
352 $this->is_matrix =
true;
353 $this->matrix = array();
356 $this->material = array();
357 $this->matrix[] =
"";
358 $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"] ??
"",
"other" => $a_attribs[
"other"] ??
"");
361 $this->material = array();
362 $this->responses = array();
365 $this->variables = array();
367 case "response_single":
368 $this->material = array();
369 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"single",
370 "id" => $a_attribs[
"id"],
371 "label" => $a_attribs[
"label"] ??
"",
372 "other" => $a_attribs[
"other"] ??
"",
373 "neutral" => $a_attribs[
"neutral"] ??
"",
374 "scale" => $a_attribs[
"scale"] ??
"");
375 $this->response_id = $a_attribs[
"id"];
377 case "response_multiple":
378 $this->material = array();
379 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"multiple",
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"] ??
"",
"other" => $a_attribs[
"other"] ??
"",
"neutral" => $a_attribs[
"neutral"] ??
"",
"scale" => $a_attribs[
"scale"] ??
"");
380 $this->response_id = $a_attribs[
"id"];
382 case "response_text":
383 $this->material = array();
384 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"text",
"id" => $a_attribs[
"id"],
"columns" => $a_attribs[
"columns"],
"maxlength" => $a_attribs[
"maxlength"] ?? null,
"rows" => $a_attribs[
"rows"],
"label" => $a_attribs[
"label"] ??
"");
385 $this->response_id = $a_attribs[
"id"];
388 $this->material = array();
389 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"num",
"id" => $a_attribs[
"id"],
"format" => $a_attribs[
"format"],
"max" => $a_attribs[
"max"] ?? null,
"min" => $a_attribs[
"min"] ?? null,
"size" => $a_attribs[
"size"] ?? null,
"label" => $a_attribs[
"label"] ??
"");
390 $this->response_id = $a_attribs[
"id"];
392 case "response_time":
393 $this->material = array();
394 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"time",
"id" => $a_attribs[
"id"],
"format" => $a_attribs[
"format"],
"max" => $a_attribs[
"max"],
"min" => $a_attribs[
"min"],
"label" => $a_attribs[
"label"] ??
"");
395 $this->response_id = $a_attribs[
"id"];
397 case "bipolar_adjectives":
398 $this->adjectives = array();
401 $this->adjectives[] = array(
"label" => $a_attribs[
"label"] ??
"",
"text" =>
"");
412 $this->text_size += strlen($a_data);
413 $this->characterbuffer .= $a_data;
421 return $purifier->purify((
string) $this->characterbuffer);
423 return $this->
trimAndStrip((
string) $this->characterbuffer);
433 if (is_object($this->survey)) {
434 $this->survey->setOfflineStatus(!$this->survey_status);
435 $this->survey->saveToDb();
438 if (count($this->questionblocks)) {
439 foreach ($this->questionblocks as
$data) {
440 $questionblock = $data[
"questions"];
441 $title = $data[
"title"];
443 foreach ($questionblock as $question_id) {
444 $qblock[] = $this->questions[$question_id];
446 $this->survey->createQuestionblock(
448 $this->showQuestiontext,
449 $this->showBlocktitle,
457 if (count($this->constraints)) {
458 $relations = $this->survey->getAllRelations(
true);
459 foreach ($this->constraints as $constraint) {
460 $constraint_id = $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
461 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
466 if (count($this->textblocks)) {
467 foreach ($this->textblocks as $original_id => $textblock) {
468 $this->survey->saveHeading($textblock, $this->questions[$original_id]);
474 $this->in_survey =
false;
475 if (is_object($this->survey)) {
476 if (strcmp($this->surveyaccess,
"free") == 0) {
477 $this->survey->setAnonymize(2);
479 if ($this->anonymisation == 0) {
480 $this->survey->setAnonymize(0);
482 $this->survey->setAnonymize(1);
488 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
489 if (is_object($this->survey)) {
490 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
495 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
496 if (is_object($this->survey)) {
497 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
502 if ($this->in_survey) {
503 if (is_object($this->survey)) {
505 $this->survey->update(
true);
508 if (is_object($this->activequestion)) {
514 if (is_object($this->activequestion)) {
515 if (strlen($this->textblock)) {
518 $this->activequestion->saveToDb();
520 if (is_object($this->survey) &&
522 $question_id = $this->activequestion->duplicate(
true,
"",
"", 0, $this->survey->getId());
524 $question_id = $this->activequestion->getId();
526 if (is_object($this->survey)) {
527 $this->survey->addQuestion($question_id);
530 if ($this->mapping) {
531 $this->mapping->addMapping(
"Modules/Survey",
"svy_q", $this->original_question_id, $question_id);
533 $this->activequestion = null;
535 $this->textblock =
"";
538 if ($this->in_survey) {
539 if (is_object($this->survey)) {
543 if (is_object($this->activequestion)) {
549 $this->material[count($this->material) - 1][
"text"] = $this->
getCharacterBuffer(
true);
555 if ($this->in_survey) {
556 if (strcmp($this->
getParent(),
"objectives") == 0) {
557 if (strcmp($this->material[0][
"label"],
"introduction") == 0) {
558 if (is_object($this->survey)) {
559 $this->survey->setIntroduction($this->material[0][
"text"]);
562 if (strcmp($this->material[0][
"label"],
"outro") == 0) {
563 if (is_object($this->survey)) {
564 $this->survey->setOutro($this->material[0][
"text"]);
567 $this->material = array();
570 if (strcmp($this->
getParent(),
"question") == 0) {
571 $this->activequestion->setMaterial($this->material[0][
"text"],
true, $this->material[0][
"label"]);
576 if (is_object($this->activequestion)) {
578 foreach ($this->material as $matarray) {
579 $questiontext .= $matarray[
"text"];
581 $this->activequestion->setQuestiontext($questiontext);
583 $this->material = array();
592 if (strcmp($this->
getParent(),
"question") == 0) {
593 if (is_object($this->activequestion)) {
594 $this->activequestion->importAdditionalMetadata($this->metadata);
597 if (strcmp($this->
getParent(),
"survey") == 0) {
598 foreach ($this->metadata as
$key => $value) {
599 switch ($value[
"label"]) {
601 if (strlen($value[
"entry"])) {
602 if (is_object($this->survey)) {
604 $md_sax_parser->setXMLContent($value[
"entry"]);
605 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
606 $md_sax_parser->enableMDParsing(
true);
607 $md_sax_parser->startParsing();
608 $this->survey->MDUpdateListener(
"General");
612 case "display_question_titles":
613 if ($value[
"entry"] == 1) {
614 $this->survey->setShowQuestionTitles(
true);
616 $this->survey->setShowQuestionTitles(
false);
620 $this->survey_status = (bool) $value[
"entry"];
622 case "evaluation_access":
623 $this->survey->setEvaluationAccess($value[
"entry"]);
626 $this->survey->setPoolUsage($value[
"entry"]);
628 case "own_results_view":
629 $this->survey->setViewOwnResults($value[
"entry"]);
631 case "own_results_mail":
632 $this->survey->setMailOwnResults($value[
"entry"]);
634 case "confirmation_mail":
635 $this->survey->setMailConfirmation($value[
"entry"]);
637 case "anon_user_list":
638 $this->survey->setAnonymousUserList($value[
"entry"]);
641 $this->survey->setMode($value[
"entry"]);
643 case "mode_360_self_eval":
644 $this->survey->set360SelfEvaluation($value[
"entry"]);
646 case "mode_360_self_rate":
647 $this->survey->set360SelfRaters($value[
"entry"]);
649 case "mode_360_self_appr":
650 $this->survey->set360SelfAppraisee($value[
"entry"]);
652 case "mode_360_results":
653 $this->survey->set360Results($value[
"entry"]);
655 case "mode_self_eval_results":
656 $this->survey->setSelfEvaluationResults($value[
"entry"]);
658 case "mode_skill_service":
659 $this->survey->setSkillService($value[
"entry"]);
664 if (!$this->spl_exists) {
665 if (strcmp($this->
getParent(),
"surveyquestions") == 0) {
666 foreach ($this->metadata as
$key => $value) {
667 if (strcmp($value[
"label"],
"SCORM") == 0) {
668 if (strlen($value[
"entry"])) {
669 if ($this->spl_id > 0) {
671 $md_sax_parser->setXMLContent($value[
"entry"]);
672 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id, 0,
"spl"));
673 $md_sax_parser->enableMDParsing(
true);
674 $md_sax_parser->startParsing();
676 $spl->MDUpdateListener(
"General");
685 if (is_object($this->activequestion)) {
686 $this->activequestion->importResponses($this->responses);
688 $this->is_matrix =
false;
694 if (is_object($this->activequestion)) {
695 $this->activequestion->importVariables($this->variables);
698 case "response_single":
699 case "response_multiple":
700 case "response_text":
702 case "response_time":
706 $this->adjectives[count($this->adjectives) - 1][
"text"] = $this->
getCharacterBuffer();
708 case "bipolar_adjectives":
709 if (is_object($this->activequestion)) {
710 $this->activequestion->importAdjectives($this->adjectives);
715 foreach ($this->material as $material) {
716 $row .= $material[
"text"];
718 $this->matrix[count($this->matrix) - 1] = array(
'title' => $row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
721 if (is_object($this->activequestion)) {
722 $this->activequestion->importMatrix($this->matrix);
728 case "questionblocktitle":
731 case "questionblock":
732 $this->in_questionblock =
false;
733 $this->questionblocks[] = array(
"title" => $this->questionblocktitle,
734 "questions" => $this->questionblock
763 return "Error: " . $this->error_msg .
" at line:" . $this->error_line .
" column:" .
$this->error_col;
794 foreach ($attribs as $k => $v) {
795 $ret[$k] = ((string) $v !==
"<>")
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
trimAndStrip(string $input)
ILIAS SurveyQuestionPool Export ImportSessionRepository $session_repo
handlerEndTag($a_xml_parser, string $a_name)
parse($a_xml_parser, $a_fp=null)
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...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
SurveyQuestion $activequestion
static _includeClass(string $question_type, int $gui=0)
Include the php class file for a given question type.
string $original_question_id
__construct(int $a_spl_id, ?string $a_xml_file='', bool $spl_exists=false, ?ilImportMapping $a_mapping=null)
trimAndStripAttribs(array $attribs)
string $questionblocktitle
__construct(Container $dic, ilPlugin $plugin)
handlerCharacterData($a_xml_parser, string $a_data)
setHandlers($a_xml_parser)
getCharacterBuffer($use_purifier=false)
$attrib
Regular expression to match HTML/XML attribute pairs within a tag.
setSurveyObject(ilObjSurvey $a_svy)