24 require_once(
"./Services/Xml/classes/class.ilSaxParser.php");
87 parent::__construct($a_xml_file);
88 $this->spl_id = $a_spl_id;
89 $this->has_error =
false;
90 $this->characterbuffer =
"";
91 $this->survey_status = 0;
92 $this->activetag =
"";
93 $this->material =
array();
94 $this->depth =
array();
95 $this->path =
array();
96 $this->metadata =
array();
97 $this->responses =
array();
98 $this->variables =
array();
99 $this->response_id =
"";
100 $this->matrix =
array();
101 $this->is_matrix =
false;
102 $this->adjectives =
array();
104 $this->survey = null;
105 $this->in_survey =
false;
106 $this->anonymisation = 0;
107 $this->surveyaccess =
"restricted";
108 $this->questions =
array();
109 $this->original_question_id =
"";
110 $this->constraints =
array();
111 $this->textblock =
"";
112 $this->textblocks =
array();
113 $this->in_questionblock =
false;
114 $this->questionblocks =
array();
115 $this->questionblock =
array();
116 $this->showQuestiontext = 1;
117 $this->questionblocktitle =
"";
118 $this->mapping = $a_mapping;
127 $this->survey = $a_svy;
137 xml_set_object($a_xml_parser, $this);
138 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
139 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
147 parent::startParsing();
155 public function parse($a_xml_parser, $a_fp = null)
160 while (
$data = fread($a_fp, 4096)) {
161 $parseOk = xml_parse($a_xml_parser,
$data, feof($a_fp));
170 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
171 $this->error_code = xml_get_error_code($a_xml_parser);
172 $this->error_line = xml_get_current_line_number($a_xml_parser);
173 $this->error_col = xml_get_current_column_number($a_xml_parser);
174 $this->error_msg = xml_error_string($a_xml_parser);
175 $this->has_error =
true;
183 if ($this->depth[$a_xml_parser] > 0) {
184 return $this->path[$this->depth[$a_xml_parser]-1];
195 $this->depth[$a_xml_parser]++;
196 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
197 $this->characterbuffer =
"";
198 $this->activetag = $a_name;
200 $this->attributes+=count($a_attribs);
202 case "questionblock":
203 $this->in_questionblock =
true;
204 $this->questionblock =
array();
205 $this->questionblocktitle =
"";
206 $this->showQuestiontext = 1;
207 foreach ($a_attribs as
$attrib => $value) {
209 case "showQuestiontext":
210 $this->showQuestiontext = $value;
215 case "surveyquestions":
216 foreach ($a_attribs as
$attrib => $value) {
219 if ($this->spl_id > 0) {
220 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
222 $spl->setOnline($value);
230 $this->in_survey =
true;
231 foreach ($a_attribs as
$attrib => $value) {
234 if (is_object($this->survey)) {
235 $this->survey->setTitle($value);
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;
263 "sourceref" => $a_attribs[
"sourceref"],
264 "destref" => $a_attribs[
"destref"],
265 "relation" => $a_attribs[
"relation"],
266 "value" => $a_attribs[
"value"],
269 "conjunction" => (
int) $a_attribs[
"conjuction"]
275 $type = $a_attribs[
"type"];
278 case 'SurveyNominalQuestion':
279 $type =
'SurveyMultipleChoiceQuestion';
280 foreach ($a_attribs as
$key => $value) {
284 $type =
'SurveySingleChoiceQuestion';
286 $type =
'SurveyMultipleChoiceQuestion';
292 case 'SurveyOrdinalQuestion':
293 $type =
'SurveySingleChoiceQuestion';
297 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
299 $this->activequestion =
new $type();
302 $q_obj_id = $this->spl_id;
303 if ($this->spl_id < 0) {
304 $q_obj_id = $this->survey->getId();
307 $this->activequestion->setObjId($q_obj_id);
310 $this->activequestion = null;
312 $this->original_question_id = $a_attribs[
"id"];
313 if ($this->in_questionblock) {
314 array_push($this->questionblock, $this->original_question_id);
316 if (is_object($this->activequestion)) {
317 foreach ($a_attribs as
$key => $value) {
320 $this->activequestion->setTitle($value);
323 $this->activequestion->setSubtype($value);
326 $this->activequestion->setObligatory($value);
333 switch ($this->
getParent($a_xml_parser)) {
336 $this->material =
array();
339 array_push($this->material,
array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
343 if (array_key_exists(
"label", $a_attribs)) {
344 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches)) {
346 if (!is_array(
$_SESSION[
"import_mob_xhtml"])) {
349 array_push(
$_SESSION[
"import_mob_xhtml"],
array(
"mob" => $a_attribs[
"label"],
"uri" => $a_attribs[
"uri"],
"type" => $a_attribs[
"type"],
"id" => $a_attribs[
"id"]));
354 $this->metadata =
array();
356 case "metadatafield":
357 array_push($this->metadata,
array(
"label" =>
"",
"entry" =>
""));
360 $this->is_matrix =
true;
361 $this->matrix =
array();
364 $this->material =
array();
365 array_push($this->matrix,
"");
366 $this->matrixrowattribs =
array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"]);
369 $this->material =
array();
370 $this->responses =
array();
373 $this->variables =
array();
375 case "response_single":
376 $this->material =
array();
377 $this->responses[$a_attribs[
"id"]] =
array(
"type" =>
"single",
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"],
"neutral" => $a_attribs[
"neutral"],
"scale" => $a_attribs[
"scale"]);
378 $this->response_id = $a_attribs[
"id"];
380 case "response_multiple":
381 $this->material =
array();
382 $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"]);
383 $this->response_id = $a_attribs[
"id"];
385 case "response_text":
386 $this->material =
array();
387 $this->responses[$a_attribs[
"id"]] =
array(
"type" =>
"text",
"id" => $a_attribs[
"id"],
"columns" => $a_attribs[
"columns"],
"maxlength" => $a_attribs[
"maxlength"],
"rows" => $a_attribs[
"rows"],
"label" => $a_attribs[
"label"]);
388 $this->response_id = $a_attribs[
"id"];
391 $this->material =
array();
392 $this->responses[$a_attribs[
"id"]] =
array(
"type" =>
"num",
"id" => $a_attribs[
"id"],
"format" => $a_attribs[
"format"],
"max" => $a_attribs[
"max"],
"min" => $a_attribs[
"min"],
"size" => $a_attribs[
"size"],
"label" => $a_attribs[
"label"]);
393 $this->response_id = $a_attribs[
"id"];
395 case "response_time":
396 $this->material =
array();
397 $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"]);
398 $this->response_id = $a_attribs[
"id"];
400 case "bipolar_adjectives":
401 $this->adjectives =
array();
404 array_push($this->adjectives,
array(
"label" => $a_attribs[
"label"],
"text" =>
""));
415 $this->text_size+=strlen($a_data);
416 $this->characterbuffer .= $a_data;
427 if (is_object($this->survey)) {
428 $this->survey->setStatus($this->survey_status);
429 $this->survey->saveToDb();
432 if (count($this->questionblocks)) {
433 foreach ($this->questionblocks as
$data) {
438 array_push($qblock, $this->questions[$question_id]);
440 $this->survey->createQuestionblock(
$title, $this->showQuestiontext,
false, $qblock);
445 if (count($this->constraints)) {
446 $relations = $this->survey->getAllRelations(
true);
447 foreach ($this->constraints as $constraint) {
448 $constraint_id= $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
449 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
454 if (count($this->textblocks)) {
455 foreach ($this->textblocks as $original_id =>
$textblock) {
456 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
462 $this->in_survey =
false;
463 if (is_object($this->survey)) {
464 if (strcmp($this->surveyaccess,
"free") == 0) {
465 $this->survey->setAnonymize(2);
467 if ($this->anonymisation == 0) {
468 $this->survey->setAnonymize(0);
470 $this->survey->setAnonymize(1);
476 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches)) {
477 if (is_object($this->survey)) {
478 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
483 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches)) {
484 if (is_object($this->survey)) {
485 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
490 if ($this->in_survey) {
491 if (is_object($this->survey)) {
492 $this->survey->setDescription($this->characterbuffer);
495 if (is_object($this->activequestion)) {
496 $this->activequestion->setDescription($this->characterbuffer);
501 if (is_object($this->activequestion)) {
502 if (strlen($this->textblock)) {
505 $this->activequestion->saveToDb();
507 if (is_object($this->survey) &&
509 $question_id = $this->activequestion->duplicate(
true,
"",
"",
"", $this->survey->getId());
511 $question_id = $this->activequestion->getId();
513 if (is_object($this->survey)) {
514 $this->survey->addQuestion($question_id);
517 if ($this->mapping) {
518 $this->mapping->addMapping(
"Modules/Survey",
"svy_q", $this->original_question_id, $question_id);
520 $this->activequestion = null;
522 $this->textblock =
"";
525 if ($this->in_survey) {
526 if (is_object($this->survey)) {
527 $this->survey->setAuthor($this->characterbuffer);
530 if (is_object($this->activequestion)) {
531 $this->activequestion->setAuthor($this->characterbuffer);
542 if ($this->in_survey) {
543 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0) {
544 if (strcmp($this->material[0][
"label"],
"introduction") == 0) {
545 if (is_object($this->survey)) {
546 $this->survey->setIntroduction($this->material[0][
"text"]);
549 if (strcmp($this->material[0][
"label"],
"outro") == 0) {
550 if (is_object($this->survey)) {
551 $this->survey->setOutro($this->material[0][
"text"]);
554 $this->material =
array();
557 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0) {
558 $this->activequestion->setMaterial($this->material[0][
"text"],
true, $this->material[0][
"label"]);
563 if (is_object($this->activequestion)) {
565 foreach ($this->material as $matarray) {
566 $questiontext .= $matarray[
"text"];
568 $this->activequestion->setQuestiontext($questiontext);
570 $this->material =
array();
579 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0) {
580 if (is_object($this->activequestion)) {
581 $this->activequestion->importAdditionalMetadata($this->metadata);
584 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0) {
585 foreach ($this->metadata as
$key => $value) {
586 switch ($value[
"label"]) {
588 if (strlen($value[
"entry"])) {
589 if (is_object($this->survey)) {
590 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
591 include_once
"./Services/MetaData/classes/class.ilMD.php";
593 $md_sax_parser->setXMLContent($value[
"entry"]);
594 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
595 $md_sax_parser->enableMDParsing(
true);
596 $md_sax_parser->startParsing();
597 $this->survey->MDUpdateListener(
"General");
601 case "display_question_titles":
602 if ($value[
"entry"] == 1) {
603 $this->survey->showQuestionTitles();
605 $this->survey->hideQuestionTitles();
609 $this->survey_status = $value[
"entry"];
611 case "evaluation_access":
612 $this->survey->setEvaluationAccess($value[
"entry"]);
615 $this->survey->setPoolUsage($value[
"entry"]);
617 case "own_results_view":
618 $this->survey->setViewOwnResults($value[
"entry"]);
620 case "own_results_mail":
621 $this->survey->setMailOwnResults($value[
"entry"]);
623 case "confirmation_mail":
624 $this->survey->setMailConfirmation($value[
"entry"]);
626 case "anon_user_list":
627 $this->survey->setAnonymousUserList($value[
"entry"]);
630 $this->survey->set360Mode($value[
"entry"]);
632 case "mode_360_self_eval":
633 $this->survey->set360SelfEvaluation($value[
"entry"]);
635 case "mode_360_self_rate":
636 $this->survey->set360SelfRaters($value[
"entry"]);
638 case "mode_360_self_appr":
639 $this->survey->set360SelfAppraisee($value[
"entry"]);
641 case "mode_360_results":
642 $this->survey->set360Results($value[
"entry"]);
644 case "mode_360_skill_service":
645 $this->survey->set360SkillService($value[
"entry"]);
650 if (!$this->spl_exists) {
651 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0) {
652 foreach ($this->metadata as
$key => $value) {
653 if (strcmp($value[
"label"],
"SCORM") == 0) {
654 if (strlen($value[
"entry"])) {
655 if ($this->spl_id > 0) {
656 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
657 include_once
"./Services/MetaData/classes/class.ilMD.php";
658 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
660 $md_sax_parser->setXMLContent($value[
"entry"]);
661 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id, 0,
"spl"));
662 $md_sax_parser->enableMDParsing(
true);
663 $md_sax_parser->startParsing();
665 $spl->MDUpdateListener(
"General");
674 if (is_object($this->activequestion)) {
675 $this->activequestion->importResponses($this->responses);
677 $this->is_matrix =
false;
680 array_push($this->variables, $this->characterbuffer);
683 if (is_object($this->activequestion)) {
684 $this->activequestion->importVariables($this->variables);
687 case "response_single":
688 case "response_multiple":
689 case "response_text":
691 case "response_time":
697 case "bipolar_adjectives":
698 if (is_object($this->activequestion)) {
699 $this->activequestion->importAdjectives($this->adjectives);
705 $row .= $material[
"text"];
707 $this->matrix[count($this->matrix)-1] =
array(
'title' =>
$row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
710 if (is_object($this->activequestion)) {
711 $this->activequestion->importMatrix($this->matrix);
717 case "questionblocktitle":
720 case "questionblock":
721 $this->in_questionblock =
false;
722 array_push($this->questionblocks,
array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
725 $this->depth[$a_xml_parser]--;
750 return "Error: " . $this->error_msg .
" at line:" . $this->error_line .
" column:" .
$this->error_col;
$attrib
Regular expression to match HTML/XML attribute pairs within a tag.
parse($a_xml_parser, $a_fp=null)
parse xml file
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
setSurveyObject($a_svy)
Sets a reference to a survey object public.
Survey Question Import Parser.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
startParsing()
start the parser
__construct($a_spl_id, $a_xml_file='', $spl_exists=false, $a_mapping=null)
Constructor.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
Create styles array
The data for the language used.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private