24 require_once(
"./Services/Xml/classes/class.ilSaxParser.php");
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 =
"";
126 $this->survey =& $a_svy;
136 xml_set_object($a_xml_parser,$this);
137 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
138 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
154 function parse($a_xml_parser,$a_fp = null)
160 while(
$data = fread($a_fp,4096))
162 $parseOk = xml_parse($a_xml_parser,
$data,feof($a_fp));
171 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
173 $this->error_code = xml_get_error_code($a_xml_parser);
174 $this->error_line = xml_get_current_line_number($a_xml_parser);
175 $this->error_col = xml_get_current_column_number($a_xml_parser);
176 $this->error_msg = xml_error_string($a_xml_parser);
177 $this->has_error = TRUE;
185 if ($this->depth[$a_xml_parser] > 0)
187 return $this->path[$this->depth[$a_xml_parser]-1];
200 $this->depth[$a_xml_parser]++;
201 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
202 $this->characterbuffer =
"";
203 $this->activetag = $a_name;
205 $this->attributes+=count($a_attribs);
208 case "questionblock":
209 $this->in_questionblock = TRUE;
210 $this->questionblock = array();
211 $this->questionblocktitle =
"";
212 $this->showQuestiontext = 1;
213 foreach ($a_attribs as
$attrib => $value)
217 case "showQuestiontext":
218 $this->showQuestiontext = $value;
223 case "surveyquestions":
224 foreach ($a_attribs as
$attrib => $value)
229 if ($this->spl_id > 0)
231 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
233 $spl->setOnline($value);
241 $this->in_survey = TRUE;
242 foreach ($a_attribs as
$attrib => $value)
247 if (is_object($this->survey))
249 $this->survey->setTitle($value);
255 case "anonymisation":
256 foreach ($a_attribs as
$attrib => $value)
261 $this->anonymisation = $value;
267 foreach ($a_attribs as
$attrib => $value)
272 $this->surveyaccess = $value;
278 array_push($this->constraints,
280 "sourceref" => $a_attribs[
"sourceref"],
281 "destref" => $a_attribs[
"destref"],
282 "relation" => $a_attribs[
"relation"],
283 "value" => $a_attribs[
"value"],
286 "conjunction" => (
int)$a_attribs[
"conjuction"]
292 $type = $a_attribs[
"type"];
296 case 'SurveyNominalQuestion':
297 $type =
'SurveyMultipleChoiceQuestion';
298 foreach ($a_attribs as $key => $value)
305 $type =
'SurveySingleChoiceQuestion';
309 $type =
'SurveyMultipleChoiceQuestion';
315 case 'SurveyOrdinalQuestion':
316 $type =
'SurveySingleChoiceQuestion';
321 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
324 $this->activequestion =
new $type();
327 $q_obj_id = $this->spl_id;
328 if($this->spl_id < 0)
330 $q_obj_id = $this->survey->getId();
333 $this->activequestion->setObjId($q_obj_id);
338 $this->activequestion = NULL;
340 $this->original_question_id = $a_attribs[
"id"];
341 if ($this->in_questionblock)
343 array_push($this->questionblock, $this->original_question_id);
345 if (is_object($this->activequestion))
347 foreach ($a_attribs as $key => $value)
352 $this->activequestion->setTitle($value);
355 $this->activequestion->setSubtype($value);
358 $this->activequestion->setObligatory($value);
369 $this->material = array();
372 array_push($this->material, array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
376 if (array_key_exists(
"label", $a_attribs))
378 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches))
381 if (!is_array(
$_SESSION[
"import_mob_xhtml"]))
$_SESSION[
"import_mob_xhtml"] = array();
382 array_push(
$_SESSION[
"import_mob_xhtml"], array(
"mob" => $a_attribs[
"label"],
"uri" => $a_attribs[
"uri"]));
387 $this->metadata = array();
389 case "metadatafield":
390 array_push($this->metadata, array(
"label" =>
"",
"entry" =>
""));
393 $this->is_matrix = TRUE;
394 $this->matrix = array();
397 $this->material = array();
398 array_push($this->matrix,
"");
399 $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"]);
402 $this->material = array();
403 $this->responses = array();
406 $this->variables = array();
408 case "response_single":
409 $this->material = array();
410 $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"]);
411 $this->response_id = $a_attribs[
"id"];
413 case "response_multiple":
414 $this->material = array();
415 $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"]);
416 $this->response_id = $a_attribs[
"id"];
418 case "response_text":
419 $this->material = array();
420 $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"]);
421 $this->response_id = $a_attribs[
"id"];
424 $this->material = array();
425 $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"]);
426 $this->response_id = $a_attribs[
"id"];
428 case "response_time":
429 $this->material = array();
430 $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"]);
431 $this->response_id = $a_attribs[
"id"];
433 case "bipolar_adjectives":
434 $this->adjectives = array();
437 array_push($this->adjectives, array(
"label" => $a_attribs[
"label"],
"text" =>
""));
448 $this->text_size+=strlen($a_data);
449 $this->characterbuffer .= $a_data;
461 if (is_object($this->survey))
464 if (count($this->constraints))
466 $relations = $this->survey->getAllRelations(TRUE);
467 foreach ($this->constraints as $constraint)
469 $constraint_id= $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
470 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
474 if (count($this->questionblocks))
476 foreach ($this->questionblocks as
$data)
483 array_push($qblock, $this->questions[$question_id]);
485 $this->survey->createQuestionblock(
$title, $this->showQuestiontext,
false, $qblock);
488 $this->survey->setStatus($this->survey_status);
489 $this->survey->saveToDb();
492 if (count($this->textblocks))
494 foreach ($this->textblocks as $original_id =>
$textblock)
496 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
502 $this->in_survey = FALSE;
503 if (is_object($this->survey))
505 if (strcmp($this->surveyaccess,
"free") == 0)
507 $this->survey->setAnonymize(2);
511 if ($this->anonymisation == 0)
513 $this->survey->setAnonymize(0);
517 $this->survey->setAnonymize(1);
523 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2}).*/", $this->characterbuffer, $matches))
525 if (is_object($this->survey))
527 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
528 $this->survey->setStartDateEnabled(1);
533 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2}).*/", $this->characterbuffer, $matches))
535 if (is_object($this->survey))
537 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
538 $this->survey->setEndDateEnabled(1);
543 if ($this->in_survey)
545 if (is_object($this->survey))
547 $this->survey->setDescription($this->characterbuffer);
552 if (is_object($this->activequestion))
554 $this->activequestion->setDescription($this->characterbuffer);
559 if (is_object($this->activequestion))
561 if (strlen($this->textblock))
565 $this->activequestion->saveToDb();
566 if (is_object($this->survey))
569 $question_id = $this->activequestion->duplicate(TRUE);
570 $this->survey->addQuestion($question_id);
573 $this->activequestion = NULL;
575 $this->textblock =
"";
578 if ($this->in_survey)
580 if (is_object($this->survey))
582 $this->survey->setAuthor($this->characterbuffer);
587 if (is_object($this->activequestion))
589 $this->activequestion->setAuthor($this->characterbuffer);
600 if ($this->in_survey)
602 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
604 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
606 if (is_object($this->survey))
608 $this->survey->setIntroduction($this->material[0][
"text"]);
611 if (strcmp($this->material[0][
"label"],
"outro") == 0)
613 if (is_object($this->survey))
615 $this->survey->setOutro($this->material[0][
"text"]);
618 $this->material = array();
623 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
625 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
630 if (is_object($this->activequestion))
633 foreach ($this->material as $matarray)
635 $questiontext .= $matarray[
"text"];
637 $this->activequestion->setQuestiontext($questiontext);
639 $this->material = array();
648 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
650 if (is_object($this->activequestion))
652 $this->activequestion->importAdditionalMetadata($this->metadata);
655 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
657 foreach ($this->metadata as $key => $value)
659 switch ($value[
"label"])
662 if (strlen($value[
"entry"]))
664 if (is_object($this->survey))
666 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
667 include_once
"./Services/MetaData/classes/class.ilMD.php";
669 $md_sax_parser->setXMLContent($value[
"entry"]);
670 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(),0,
"svy"));
671 $md_sax_parser->enableMDParsing(
true);
672 $md_sax_parser->startParsing();
673 $this->survey->MDUpdateListener(
"General");
677 case "display_question_titles":
678 if ($value[
"entry"] == 1)
680 $this->survey->showQuestionTitles();
684 $this->survey->hideQuestionTitles();
688 $this->survey_status = $value[
"entry"];
690 case "evaluation_access":
691 $this->survey->setEvaluationAccess($value[
"entry"]);
696 if (!$this->spl_exists)
698 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0)
700 foreach ($this->metadata as $key => $value)
702 if (strcmp($value[
"label"],
"SCORM") == 0)
704 if (strlen($value[
"entry"]))
706 if ($this->spl_id > 0)
708 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
709 include_once
"./Services/MetaData/classes/class.ilMD.php";
710 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
712 $md_sax_parser->setXMLContent($value[
"entry"]);
713 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id,0,
"spl"));
714 $md_sax_parser->enableMDParsing(
true);
715 $md_sax_parser->startParsing();
717 $spl->MDUpdateListener(
"General");
726 if (is_object($this->activequestion))
728 $this->activequestion->importResponses($this->responses);
730 $this->is_matrix = FALSE;
733 array_push($this->variables, $this->characterbuffer);
736 if (is_object($this->activequestion))
738 $this->activequestion->importVariables($this->variables);
741 case "response_single":
742 case "response_multiple":
743 case "response_text":
745 case "response_time":
751 case "bipolar_adjectives":
752 if (is_object($this->activequestion))
754 $this->activequestion->importAdjectives($this->adjectives);
761 $row .= $material[
"text"];
763 $this->matrix[count($this->matrix)-1] = array(
'title' =>
$row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
766 if (is_object($this->activequestion))
768 $this->activequestion->importMatrix($this->matrix);
774 case "questionblocktitle":
777 case "questionblock":
778 $this->in_questionblock = FALSE;
779 array_push($this->questionblocks, array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
782 $this->depth[$a_xml_parser]--;
807 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;