26 protected \ILIAS\SurveyQuestionPool\Export\ImportSessionRepository
$session_repo;
82 ?
string $a_xml_file =
'',
83 bool $spl_exists =
false,
89 $this->activequestion = null;
90 $this->spl_id = $a_spl_id;
91 $this->has_error =
false;
92 $this->characterbuffer =
"";
93 $this->survey_status =
false;
94 $this->activetag =
"";
97 $this->path = array();
98 $this->metadata = array();
99 $this->responses = array();
100 $this->variables = array();
101 $this->response_id =
"";
102 $this->matrix = array();
103 $this->is_matrix =
false;
104 $this->adjectives = array();
106 $this->survey = null;
107 $this->in_survey =
false;
108 $this->anonymisation = 0;
109 $this->surveyaccess =
"restricted";
110 $this->questions = array();
111 $this->original_question_id =
"";
112 $this->constraints = array();
113 $this->textblock =
"";
114 $this->textblocks = array();
115 $this->in_questionblock =
false;
116 $this->questionblocks = array();
117 $this->questionblock = array();
118 $this->showQuestiontext = 1;
119 $this->showBlocktitle = 0;
120 $this->compressView = 0;
121 $this->questionblocktitle =
"";
122 $this->mapping = $a_mapping;
123 $this->session_repo = $DIC->surveyQuestionPool()->internal()
129 $this->survey = $a_svy;
134 xml_set_object($a_xml_parser, $this);
135 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
136 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
143 public function parse($a_xml_parser, $a_fp = null): void
148 while (
$data = fread($a_fp, 4096)) {
149 $parseOk = xml_parse($a_xml_parser,
$data, feof($a_fp));
158 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
159 $this->error_code = xml_get_error_code($a_xml_parser);
160 $this->error_line = xml_get_current_line_number($a_xml_parser);
161 $this->error_col = xml_get_current_column_number($a_xml_parser);
162 $this->error_msg = xml_error_string($this->error_code);
163 $this->has_error =
true;
169 if ($this->depth > 0) {
170 return $this->path[$this->depth - 1];
179 public function handlerBeginTag($a_xml_parser,
string $a_name, array $a_attribs): void
184 $this->characterbuffer =
"";
185 $this->activetag = $a_name;
187 $this->attributes += count($a_attribs);
189 case "questionblock":
190 $this->in_questionblock =
true;
191 $this->questionblock = array();
192 $this->questionblocktitle =
"";
193 $this->showQuestiontext = 1;
194 $this->showBlocktitle = 0;
195 $this->compressView = 0;
196 foreach ($a_attribs as
$attrib => $value) {
198 case "showQuestiontext":
199 $this->showQuestiontext = (
int) $value;
201 case "showBlocktitle":
202 $this->showBlocktitle = (
int) $value;
205 $this->compressView = (
int) $value;
210 case "surveyquestions":
211 foreach ($a_attribs as
$attrib => $value) {
214 if ($this->spl_id > 0) {
216 $spl->setOfflineStatus(!$value);
222 $spl->setTitle($value);
229 $this->in_survey =
true;
230 foreach ($a_attribs as
$attrib => $value) {
233 if (is_object($this->survey)) {
234 $this->survey->setTitle($value);
235 $this->survey->update(
true);
241 case "anonymisation":
242 foreach ($a_attribs as
$attrib => $value) {
245 $this->anonymisation = $value;
251 foreach ($a_attribs as
$attrib => $value) {
254 $this->surveyaccess = $value;
260 $this->constraints[] = array(
261 "sourceref" => $a_attribs[
"sourceref"],
262 "destref" => $a_attribs[
"destref"],
263 "relation" => $a_attribs[
"relation"],
264 "value" => $a_attribs[
"value"],
267 "conjunction" => (
int) ($a_attribs[
"conjuction"] ?? 0)
272 $type = $a_attribs[
"type"];
275 case 'SurveyNominalQuestion':
276 $type =
'SurveyMultipleChoiceQuestion';
277 foreach ($a_attribs as $key => $value) {
281 $type =
'SurveySingleChoiceQuestion';
283 $type =
'SurveyMultipleChoiceQuestion';
289 case 'SurveyOrdinalQuestion':
290 $type =
'SurveySingleChoiceQuestion';
293 if (strlen($type ??
"")) {
294 $this->activequestion =
new $type();
297 if ($this->spl_id < 0) {
298 $q_obj_id = $this->survey->getId();
300 $this->activequestion->setObjId($q_obj_id);
302 $this->activequestion = null;
304 $this->original_question_id = $a_attribs[
"id"];
305 if ($this->in_questionblock) {
308 if (is_object($this->activequestion)) {
309 foreach ($a_attribs as $key => $value) {
312 $this->activequestion->setTitle($value);
315 $this->activequestion->setSubtype($value);
318 $this->activequestion->setObligatory($value);
328 $this->material = [];
331 $this->material[] = array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"] ??
"");
335 if (array_key_exists(
"label", $a_attribs)) {
336 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"] ??
"", $matches)) {
338 $this->session_repo->addMob(
339 $a_attribs[
"label"] ??
"",
348 $this->metadata = array();
350 case "metadatafield":
351 $this->metadata[] = array(
"label" =>
"",
"entry" =>
"");
354 $this->is_matrix =
true;
355 $this->matrix = array();
358 $this->material = [];
359 $this->matrix[] =
"";
360 $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"] ??
"",
"other" => $a_attribs[
"other"] ??
"");
363 $this->material = [];
364 $this->responses = array();
367 $this->variables = array();
369 case "response_single":
370 $this->material = [];
371 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"single",
372 "id" => $a_attribs[
"id"],
373 "label" => $a_attribs[
"label"] ??
"",
374 "other" => $a_attribs[
"other"] ??
"",
375 "neutral" => $a_attribs[
"neutral"] ??
"",
376 "scale" => $a_attribs[
"scale"] ??
"");
377 $this->response_id = $a_attribs[
"id"];
379 case "response_multiple":
380 $this->material = [];
381 $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"] ??
"");
382 $this->response_id = $a_attribs[
"id"];
384 case "response_text":
385 $this->material = [];
386 $this->responses[$a_attribs[
"id"]] = array(
"type" =>
"text",
"id" => $a_attribs[
"id"],
"columns" => $a_attribs[
"columns"] ?? null,
"maxlength" => $a_attribs[
"maxlength"] ?? null,
"rows" => $a_attribs[
"rows"] ?? null,
"label" => $a_attribs[
"label"] ??
"");
387 $this->response_id = $a_attribs[
"id"];
390 $this->material = [];
391 $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"] ??
"");
392 $this->response_id = $a_attribs[
"id"];
394 case "response_time":
395 $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"] ??
"");
396 $this->response_id = $a_attribs[
"id"];
398 case "bipolar_adjectives":
399 $this->adjectives = array();
402 $this->adjectives[] = array(
"label" => $a_attribs[
"label"] ??
"",
"text" =>
"");
413 $this->text_size += strlen($a_data ??
"");
414 $this->characterbuffer .= $a_data;
422 return $purifier->purify((
string) $this->characterbuffer);
424 return $this->
trimAndStrip((
string) $this->characterbuffer);
434 if (is_object($this->survey)) {
435 $this->survey->setOfflineStatus(!$this->survey_status);
436 $this->survey->saveToDb();
439 if (count($this->questionblocks)) {
440 foreach ($this->questionblocks as
$data) {
441 $questionblock = $data[
"questions"];
442 $title = $data[
"title"];
444 foreach ($questionblock as $question_id) {
445 $qblock[] = $this->questions[$question_id];
447 $this->survey->createQuestionblock(
449 $this->showQuestiontext,
450 $this->showBlocktitle,
458 if (count($this->constraints)) {
459 $relations = $this->survey->getAllRelations(
true);
460 foreach ($this->constraints as $constraint) {
461 $constraint_id = $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
462 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
467 if (count($this->textblocks)) {
468 foreach ($this->textblocks as $original_id => $textblock) {
469 $this->survey->saveHeading($textblock, $this->questions[$original_id]);
475 $this->in_survey =
false;
476 if (is_object($this->survey)) {
477 if (strcmp($this->surveyaccess,
"free") == 0) {
478 $this->survey->setAnonymize(2);
480 if ($this->anonymisation == 0) {
481 $this->survey->setAnonymize(0);
483 $this->survey->setAnonymize(1);
489 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
490 if (is_object($this->survey)) {
491 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
496 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
497 if (is_object($this->survey)) {
498 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
503 if ($this->in_survey) {
504 if (is_object($this->survey)) {
506 $this->survey->update(
true);
509 if (is_object($this->activequestion)) {
515 if (is_object($this->activequestion)) {
516 if (strlen($this->textblock ??
"")) {
519 $this->activequestion->saveToDb();
521 if (is_object($this->survey) &&
523 $question_id = $this->activequestion->duplicate(
true,
"",
"", 0, $this->survey->getId());
525 $question_id = $this->activequestion->getId();
527 if (is_object($this->survey)) {
528 $this->survey->addQuestion($question_id);
531 if ($this->mapping) {
532 $this->mapping->addMapping(
"components/ILIAS/Survey",
"svy_q", $this->original_question_id, $question_id);
534 $this->activequestion = null;
536 $this->textblock =
"";
539 if ($this->in_survey) {
540 if (is_object($this->survey)) {
544 if (is_object($this->activequestion)) {
550 $this->material[count($this->material) - 1][
"text"] = $this->
getCharacterBuffer(
true);
556 if ($this->in_survey) {
557 if (strcmp($this->
getParent(),
"objectives") == 0) {
558 if (isset($this->material[0]) && strcmp($this->material[0][
"label"],
"introduction") == 0) {
559 if (is_object($this->survey)) {
560 $this->survey->setIntroduction($this->material[0][
"text"]);
563 if (isset($this->material[0]) && strcmp($this->material[0][
"label"],
"outro") == 0) {
564 if (is_object($this->survey)) {
565 $this->survey->setOutro($this->material[0][
"text"]);
568 $this->material = array();
571 if (strcmp($this->
getParent(),
"question") == 0) {
578 if (is_object($this->activequestion)) {
580 foreach ($this->material as $matarray) {
581 $questiontext .= $matarray[
"text"];
583 $this->activequestion->setQuestiontext($questiontext);
585 $this->material = array();
594 if (strcmp($this->
getParent(),
"question") == 0) {
595 if (is_object($this->activequestion)) {
596 $this->activequestion->importAdditionalMetadata($this->metadata);
599 if (strcmp($this->
getParent(),
"survey") == 0) {
600 foreach ($this->metadata as $key => $value) {
601 switch ($value[
"label"]) {
603 if (strlen($value[
"entry"] ??
"")) {
604 if (is_object($this->survey)) {
606 $md_sax_parser->setXMLContent($value[
"entry"]);
607 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
608 $md_sax_parser->enableMDParsing(
true);
609 $md_sax_parser->startParsing();
610 $this->survey->MDUpdateListener(
"General");
614 case "display_question_titles":
615 if ($value[
"entry"] == 1) {
616 $this->survey->setShowQuestionTitles(
true);
618 $this->survey->setShowQuestionTitles(
false);
622 $this->survey_status = (bool) $value[
"entry"];
624 case "evaluation_access":
625 $this->survey->setEvaluationAccess($value[
"entry"]);
628 $this->survey->setPoolUsage($value[
"entry"]);
630 case "own_results_mail":
631 $this->survey->setMailOwnResults($value[
"entry"]);
633 case "confirmation_mail":
634 $this->survey->setMailConfirmation($value[
"entry"]);
636 case "anon_user_list":
637 $this->survey->setAnonymousUserList($value[
"entry"]);
640 $this->survey->setMode($value[
"entry"]);
642 case "mode_360_self_eval":
643 $this->survey->set360SelfEvaluation($value[
"entry"]);
645 case "mode_360_self_rate":
646 $this->survey->set360SelfRaters($value[
"entry"]);
648 case "mode_360_self_appr":
649 $this->survey->set360SelfAppraisee($value[
"entry"]);
651 case "mode_360_results":
652 $this->survey->set360Results($value[
"entry"]);
654 case "mode_self_eval_results":
655 $this->survey->setSelfEvaluationResults($value[
"entry"]);
657 case "mode_skill_service":
658 $this->survey->setSkillService($value[
"entry"]);
663 if (!$this->spl_exists) {
664 if (strcmp($this->
getParent(),
"surveyquestions") == 0) {
665 foreach ($this->metadata as $key => $value) {
666 if (strcmp($value[
"label"],
"SCORM") == 0) {
667 if (strlen($value[
"entry"] ??
"")) {
668 if ($this->spl_id > 0) {
670 $md_sax_parser->setXMLContent($value[
"entry"]);
671 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id, 0,
"spl"));
672 $md_sax_parser->enableMDParsing(
true);
673 $md_sax_parser->startParsing();
675 $spl->MDUpdateListener(
"General");
684 if (is_object($this->activequestion)) {
685 $this->activequestion->importResponses($this->responses);
687 $this->is_matrix =
false;
693 if (is_object($this->activequestion)) {
694 $this->activequestion->importVariables($this->variables);
697 case "response_single":
698 case "response_multiple":
699 case "response_text":
701 case "response_time":
705 $this->adjectives[count($this->adjectives) - 1][
"text"] = $this->
getCharacterBuffer();
707 case "bipolar_adjectives":
708 if (is_object($this->activequestion)) {
709 $this->activequestion->importAdjectives($this->adjectives);
714 foreach ($this->material as $material) {
715 $row .= $material[
"text"];
717 $this->matrix[count($this->matrix) - 1] = array(
'title' => $row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
720 if (is_object($this->activequestion)) {
721 $this->activequestion->importMatrix($this->matrix);
727 case "questionblocktitle":
730 case "questionblock":
731 $this->in_questionblock =
false;
732 $this->questionblocks[] = array(
"title" => $this->questionblocktitle,
733 "questions" => $this->questionblock
762 return "Error: " . $this->error_msg .
" at line:" . $this->error_line .
" column:" .
$this->error_col;
793 foreach ($attribs as $k => $v) {
794 $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)
Class ilObjSurveyQuestionPool.
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
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)