24 require_once(
"./classes/class.ilSaxParser.php");
88 $this->has_error = FALSE;
89 $this->characterbuffer =
"";
90 $this->activetag =
"";
91 $this->material = array();
92 $this->depth = array();
93 $this->path = array();
94 $this->metadata = array();
95 $this->responses = array();
96 $this->variables = array();
97 $this->response_id =
"";
98 $this->matrix = array();
99 $this->is_matrix = FALSE;
100 $this->adjectives = array();
102 $this->survey = NULL;
103 $this->in_survey = FALSE;
104 $this->anonymisation = 0;
105 $this->surveyaccess =
"restricted";
106 $this->questions = array();
107 $this->original_question_id =
"";
108 $this->constraints = array();
109 $this->textblock =
"";
110 $this->textblocks = array();
111 $this->in_questionblock = FALSE;
112 $this->questionblocks = array();
113 $this->questionblock = array();
114 $this->showQuestiontext = 1;
115 $this->questionblocktitle =
"";
124 $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');
152 function parse($a_xml_parser,$a_fp = null)
158 while(
$data = fread($a_fp,4096))
160 $parseOk = xml_parse($a_xml_parser,
$data,feof($a_fp));
169 && (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)
185 return $this->path[$this->depth[$a_xml_parser]-1];
198 $this->depth[$a_xml_parser]++;
199 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
200 $this->characterbuffer =
"";
201 $this->activetag = $a_name;
203 $this->attributes+=count($a_attribs);
206 case "questionblock":
207 $this->in_questionblock = TRUE;
208 $this->questionblock = array();
209 $this->questionblocktitle =
"";
210 $this->showQuestiontext = 1;
211 foreach ($a_attribs as
$attrib => $value)
215 case "showQuestiontext":
216 $this->showQuestiontext = $value;
222 $this->in_survey = TRUE;
223 foreach ($a_attribs as
$attrib => $value)
228 if (is_object($this->survey))
230 $this->survey->setTitle($value);
236 case "anonymisation":
237 foreach ($a_attribs as
$attrib => $value)
242 $this->anonymisation = $value;
248 foreach ($a_attribs as
$attrib => $value)
253 $this->surveyaccess = $value;
259 array_push($this->constraints,
261 "sourceref" => $a_attribs[
"sourceref"],
262 "destref" => $a_attribs[
"destref"],
263 "relation" => $a_attribs[
"relation"],
264 "value" => $a_attribs[
"value"]
270 $type = $a_attribs[
"type"];
274 case 'SurveyNominalQuestion':
275 $type =
'SurveyMultipleChoiceQuestion';
276 foreach ($a_attribs as $key => $value)
283 $type =
'SurveySingleChoiceQuestion';
287 $type =
'SurveyMultipleChoiceQuestion';
293 case 'SurveyOrdinalQuestion':
294 $type =
'SurveySingleChoiceQuestion';
299 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
302 $this->activequestion =
new $type();
303 $this->activequestion->setObjId($this->spl->getId());
308 $this->activequestion = NULL;
310 $this->original_question_id = $a_attribs[
"id"];
311 if ($this->in_questionblock)
313 array_push($this->questionblock, $this->original_question_id);
315 if (is_object($this->activequestion))
317 foreach ($a_attribs as $key => $value)
322 $this->activequestion->setTitle($value);
325 $this->activequestion->setSubtype($value);
328 $this->activequestion->setObligatory($value);
339 $this->material = array();
342 array_push($this->material, array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
346 if (array_key_exists(
"label", $a_attribs))
348 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches))
351 if (!is_array(
$_SESSION[
"import_mob_xhtml"]))
$_SESSION[
"import_mob_xhtml"] = array();
352 array_push(
$_SESSION[
"import_mob_xhtml"], array(
"mob" => $a_attribs[
"label"],
"uri" => $a_attribs[
"uri"]));
357 $this->metadata = array();
359 case "metadatafield":
360 array_push($this->metadata, array(
"label" =>
"",
"entry" =>
""));
363 $this->is_matrix = TRUE;
364 $this->matrix = array();
367 $this->material = array();
368 array_push($this->matrix,
"");
369 $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"]);
372 $this->material = array();
373 $this->responses = array();
376 $this->variables = array();
378 case "response_single":
379 $this->material = array();
380 $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"]);
381 $this->response_id = $a_attribs[
"id"];
383 case "response_multiple":
384 $this->material = array();
385 $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"]);
386 $this->response_id = $a_attribs[
"id"];
388 case "response_text":
389 $this->material = array();
390 $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"]);
391 $this->response_id = $a_attribs[
"id"];
394 $this->material = array();
395 $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"]);
396 $this->response_id = $a_attribs[
"id"];
398 case "response_time":
399 $this->material = array();
400 $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"]);
401 $this->response_id = $a_attribs[
"id"];
403 case "bipolar_adjectives":
404 $this->adjectives = array();
407 array_push($this->adjectives, array(
"label" => $a_attribs[
"label"],
"text" =>
""));
418 $this->text_size+=strlen($a_data);
419 $this->characterbuffer .= $a_data;
431 if (is_object($this->survey))
434 if (count($this->constraints))
436 $relations = $this->survey->getAllRelations(TRUE);
437 foreach ($this->constraints as $constraint)
439 $constraint_id= $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], 0);
440 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
444 if (count($this->questionblocks))
446 foreach ($this->questionblocks as
$data)
453 array_push($qblock, $this->questions[$question_id]);
455 $this->survey->createQuestionblock(
$title, $this->showQuestiontext, $qblock);
458 $this->survey->saveToDb();
461 if (count($this->textblocks))
463 foreach ($this->textblocks as $original_id =>
$textblock)
465 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
471 $this->in_survey = FALSE;
472 if (is_object($this->survey))
474 if (strcmp($this->surveyaccess,
"free") == 0)
476 $this->survey->setAnonymize(2);
480 if ($this->anonymisation == 0)
482 $this->survey->setAnonymize(0);
486 $this->survey->setAnonymize(1);
492 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2}).*/", $this->characterbuffer, $matches))
494 if (is_object($this->survey))
496 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
497 $this->survey->setStartDateEnabled(1);
502 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2}).*/", $this->characterbuffer, $matches))
504 if (is_object($this->survey))
506 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
507 $this->survey->setEndDateEnabled(1);
512 if ($this->in_survey)
514 if (is_object($this->survey))
516 $this->survey->setDescription($this->characterbuffer);
521 if (is_object($this->activequestion))
523 $this->activequestion->setDescription($this->characterbuffer);
528 if (is_object($this->activequestion))
530 if (strlen($this->textblock))
534 $this->activequestion->saveToDb();
535 if (is_object($this->survey))
538 $question_id = $this->activequestion->duplicate(TRUE);
539 $this->survey->addQuestion($question_id);
542 $this->activequestion = NULL;
544 $this->textblock =
"";
547 if ($this->in_survey)
549 if (is_object($this->survey))
551 $this->survey->setAuthor($this->characterbuffer);
556 if (is_object($this->activequestion))
558 $this->activequestion->setAuthor($this->characterbuffer);
569 if ($this->in_survey)
571 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
573 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
575 if (is_object($this->survey))
577 $this->survey->setIntroduction($this->material[0][
"text"]);
580 if (strcmp($this->material[0][
"label"],
"outro") == 0)
582 if (is_object($this->survey))
584 $this->survey->setOutro($this->material[0][
"text"]);
587 $this->material = array();
592 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
594 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
599 if (is_object($this->activequestion))
602 foreach ($this->material as $matarray)
604 $questiontext .= $matarray[
"text"];
606 $this->activequestion->setQuestiontext($questiontext);
608 $this->material = array();
617 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
619 if (is_object($this->activequestion))
621 $this->activequestion->importAdditionalMetadata($this->metadata);
624 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
626 foreach ($this->metadata as $key => $value)
628 switch ($value[
"label"])
631 if (strlen($value[
"entry"]))
633 if (is_object($this->survey))
635 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
636 include_once
"./Services/MetaData/classes/class.ilMD.php";
638 $md_sax_parser->setXMLContent($value[
"entry"]);
639 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(),0,
"svy"));
640 $md_sax_parser->enableMDParsing(
true);
641 $md_sax_parser->startParsing();
642 $this->survey->MDUpdateListener(
"General");
646 case "display_question_titles":
647 if ($value[
"entry"] == 1)
649 $this->survey->showQuestionTitles();
653 $this->survey->hideQuestionTitles();
657 $this->survey->setStatus($value[
"entry"]);
659 case "evaluation_access":
660 $this->survey->setEvaluationAccess($value[
"entry"]);
665 if (!$this->spl_exists)
667 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0)
669 foreach ($this->metadata as $key => $value)
671 if (strcmp($value[
"label"],
"SCORM") == 0)
673 if (strlen($value[
"entry"]))
675 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
676 include_once
"./Services/MetaData/classes/class.ilMD.php";
678 $md_sax_parser->setXMLContent($value[
"entry"]);
679 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl->getId(),0,
"spl"));
680 $md_sax_parser->enableMDParsing(
true);
681 $md_sax_parser->startParsing();
682 $this->spl->MDUpdateListener(
"General");
690 if (is_object($this->activequestion))
692 $this->activequestion->importResponses($this->responses);
694 $this->is_matrix = FALSE;
697 array_push($this->variables, $this->characterbuffer);
700 if (is_object($this->activequestion))
702 $this->activequestion->importVariables($this->variables);
705 case "response_single":
706 case "response_multiple":
707 case "response_text":
709 case "response_time":
715 case "bipolar_adjectives":
716 if (is_object($this->activequestion))
718 $this->activequestion->importAdjectives($this->adjectives);
725 $row .= $material[
"text"];
727 $this->matrix[count($this->matrix)-1] = array(
'title' =>
$row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
730 if (is_object($this->activequestion))
732 $this->activequestion->importMatrix($this->matrix);
738 case "questionblocktitle":
741 case "questionblock":
742 $this->in_questionblock = FALSE;
743 array_push($this->questionblocks, array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
746 $this->depth[$a_xml_parser]--;
771 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;