24 require_once(
"./Services/Xml/classes/class.ilSaxParser.php");
85 function __construct($a_spl_id, $a_xml_file =
'', $spl_exists = FALSE, $a_mapping = null)
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 function parse($a_xml_parser,$a_fp = null)
161 while(
$data = fread($a_fp,4096))
163 $parseOk = xml_parse($a_xml_parser,
$data,feof($a_fp));
172 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
174 $this->error_code = xml_get_error_code($a_xml_parser);
175 $this->error_line = xml_get_current_line_number($a_xml_parser);
176 $this->error_col = xml_get_current_column_number($a_xml_parser);
177 $this->error_msg = xml_error_string($a_xml_parser);
178 $this->has_error = TRUE;
186 if ($this->depth[$a_xml_parser] > 0)
188 return $this->path[$this->depth[$a_xml_parser]-1];
201 $this->depth[$a_xml_parser]++;
202 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
203 $this->characterbuffer =
"";
204 $this->activetag = $a_name;
206 $this->attributes+=count($a_attribs);
209 case "questionblock":
210 $this->in_questionblock = TRUE;
211 $this->questionblock =
array();
212 $this->questionblocktitle =
"";
213 $this->showQuestiontext = 1;
214 foreach ($a_attribs as
$attrib => $value)
218 case "showQuestiontext":
219 $this->showQuestiontext = $value;
224 case "surveyquestions":
225 foreach ($a_attribs as
$attrib => $value)
230 if ($this->spl_id > 0)
232 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
234 $spl->setOnline($value);
242 $this->in_survey = TRUE;
243 foreach ($a_attribs as
$attrib => $value)
248 if (is_object($this->survey))
250 $this->survey->setTitle($value);
256 case "anonymisation":
257 foreach ($a_attribs as
$attrib => $value)
262 $this->anonymisation = $value;
268 foreach ($a_attribs as
$attrib => $value)
273 $this->surveyaccess = $value;
279 array_push($this->constraints,
281 "sourceref" => $a_attribs[
"sourceref"],
282 "destref" => $a_attribs[
"destref"],
283 "relation" => $a_attribs[
"relation"],
284 "value" => $a_attribs[
"value"],
287 "conjunction" => (
int)$a_attribs[
"conjuction"]
293 $type = $a_attribs[
"type"];
297 case 'SurveyNominalQuestion':
298 $type =
'SurveyMultipleChoiceQuestion';
299 foreach ($a_attribs as $key => $value)
306 $type =
'SurveySingleChoiceQuestion';
310 $type =
'SurveyMultipleChoiceQuestion';
316 case 'SurveyOrdinalQuestion':
317 $type =
'SurveySingleChoiceQuestion';
322 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
325 $this->activequestion =
new $type();
328 $q_obj_id = $this->spl_id;
329 if($this->spl_id < 0)
331 $q_obj_id = $this->survey->getId();
334 $this->activequestion->setObjId($q_obj_id);
339 $this->activequestion = NULL;
341 $this->original_question_id = $a_attribs[
"id"];
342 if ($this->in_questionblock)
344 array_push($this->questionblock, $this->original_question_id);
346 if (is_object($this->activequestion))
348 foreach ($a_attribs as $key => $value)
353 $this->activequestion->setTitle($value);
356 $this->activequestion->setSubtype($value);
359 $this->activequestion->setObligatory($value);
370 $this->material =
array();
373 array_push($this->material,
array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
377 if (array_key_exists(
"label", $a_attribs))
379 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches))
383 array_push(
$_SESSION[
"import_mob_xhtml"],
array(
"mob" => $a_attribs[
"label"],
"uri" => $a_attribs[
"uri"],
"type" => $a_attribs[
"type"],
"id" => $a_attribs[
"id"]));
388 $this->metadata =
array();
390 case "metadatafield":
391 array_push($this->metadata,
array(
"label" =>
"",
"entry" =>
""));
394 $this->is_matrix = TRUE;
395 $this->matrix =
array();
398 $this->material =
array();
399 array_push($this->matrix,
"");
400 $this->matrixrowattribs =
array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"]);
403 $this->material =
array();
404 $this->responses =
array();
407 $this->variables =
array();
409 case "response_single":
410 $this->material =
array();
411 $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"]);
412 $this->response_id = $a_attribs[
"id"];
414 case "response_multiple":
415 $this->material =
array();
416 $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"]);
417 $this->response_id = $a_attribs[
"id"];
419 case "response_text":
420 $this->material =
array();
421 $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"]);
422 $this->response_id = $a_attribs[
"id"];
425 $this->material =
array();
426 $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"]);
427 $this->response_id = $a_attribs[
"id"];
429 case "response_time":
430 $this->material =
array();
431 $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"]);
432 $this->response_id = $a_attribs[
"id"];
434 case "bipolar_adjectives":
435 $this->adjectives =
array();
438 array_push($this->adjectives,
array(
"label" => $a_attribs[
"label"],
"text" =>
""));
449 $this->text_size+=strlen($a_data);
450 $this->characterbuffer .= $a_data;
462 if (is_object($this->survey))
464 $this->survey->setStatus($this->survey_status);
465 $this->survey->saveToDb();
468 if (count($this->questionblocks))
470 foreach ($this->questionblocks as
$data)
472 $questionblock = $data[
"questions"];
475 foreach ($questionblock as $question_id)
477 array_push($qblock, $this->questions[$question_id]);
479 $this->survey->createQuestionblock(
$title, $this->showQuestiontext,
false, $qblock);
484 if (count($this->constraints))
486 $relations = $this->survey->getAllRelations(TRUE);
487 foreach ($this->constraints as $constraint)
489 $constraint_id= $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
490 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
495 if (count($this->textblocks))
497 foreach ($this->textblocks as $original_id => $textblock)
499 $this->survey->saveHeading($textblock, $this->questions[$original_id]);
505 $this->in_survey = FALSE;
506 if (is_object($this->survey))
508 if (strcmp($this->surveyaccess,
"free") == 0)
510 $this->survey->setAnonymize(2);
514 if ($this->anonymisation == 0)
516 $this->survey->setAnonymize(0);
520 $this->survey->setAnonymize(1);
526 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches))
528 if (is_object($this->survey))
530 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
535 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches))
537 if (is_object($this->survey))
539 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
544 if ($this->in_survey)
546 if (is_object($this->survey))
548 $this->survey->setDescription($this->characterbuffer);
553 if (is_object($this->activequestion))
555 $this->activequestion->setDescription($this->characterbuffer);
560 if (is_object($this->activequestion))
562 if (strlen($this->textblock))
566 $this->activequestion->saveToDb();
568 if (is_object($this->survey) &&
571 $question_id = $this->activequestion->duplicate(TRUE,
"",
"",
"", $this->survey->getId());
575 $question_id = $this->activequestion->getId();
577 if (is_object($this->survey))
579 $this->survey->addQuestion($question_id);
584 $this->mapping->addMapping(
"Modules/Survey",
"svy_q", $this->original_question_id, $question_id);
586 $this->activequestion = NULL;
588 $this->textblock =
"";
591 if ($this->in_survey)
593 if (is_object($this->survey))
595 $this->survey->setAuthor($this->characterbuffer);
600 if (is_object($this->activequestion))
602 $this->activequestion->setAuthor($this->characterbuffer);
613 if ($this->in_survey)
615 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
617 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
619 if (is_object($this->survey))
621 $this->survey->setIntroduction($this->material[0][
"text"]);
624 if (strcmp($this->material[0][
"label"],
"outro") == 0)
626 if (is_object($this->survey))
628 $this->survey->setOutro($this->material[0][
"text"]);
631 $this->material =
array();
636 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
638 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
643 if (is_object($this->activequestion))
646 foreach ($this->material as $matarray)
648 $questiontext .= $matarray[
"text"];
650 $this->activequestion->setQuestiontext($questiontext);
652 $this->material =
array();
661 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
663 if (is_object($this->activequestion))
665 $this->activequestion->importAdditionalMetadata($this->metadata);
668 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
670 foreach ($this->metadata as $key => $value)
672 switch ($value[
"label"])
675 if (strlen($value[
"entry"]))
677 if (is_object($this->survey))
679 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
680 include_once
"./Services/MetaData/classes/class.ilMD.php";
682 $md_sax_parser->setXMLContent($value[
"entry"]);
683 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(),0,
"svy"));
684 $md_sax_parser->enableMDParsing(
true);
685 $md_sax_parser->startParsing();
686 $this->survey->MDUpdateListener(
"General");
690 case "display_question_titles":
691 if ($value[
"entry"] == 1)
693 $this->survey->showQuestionTitles();
697 $this->survey->hideQuestionTitles();
701 $this->survey_status = $value[
"entry"];
703 case "evaluation_access":
704 $this->survey->setEvaluationAccess($value[
"entry"]);
707 $this->survey->setPoolUsage($value[
"entry"]);
709 case "own_results_view":
710 $this->survey->setViewOwnResults($value[
"entry"]);
712 case "own_results_mail":
713 $this->survey->setMailOwnResults($value[
"entry"]);
715 case "confirmation_mail":
716 $this->survey->setMailConfirmation($value[
"entry"]);
718 case "anon_user_list":
719 $this->survey->setAnonymousUserList($value[
"entry"]);
722 $this->survey->set360Mode($value[
"entry"]);
724 case "mode_360_self_eval":
725 $this->survey->set360SelfEvaluation($value[
"entry"]);
727 case "mode_360_self_rate":
728 $this->survey->set360SelfRaters($value[
"entry"]);
730 case "mode_360_self_appr":
731 $this->survey->set360SelfAppraisee($value[
"entry"]);
733 case "mode_360_results":
734 $this->survey->set360Results($value[
"entry"]);
736 case "mode_360_skill_service":
737 $this->survey->set360SkillService($value[
"entry"]);
742 if (!$this->spl_exists)
744 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0)
746 foreach ($this->metadata as $key => $value)
748 if (strcmp($value[
"label"],
"SCORM") == 0)
750 if (strlen($value[
"entry"]))
752 if ($this->spl_id > 0)
754 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
755 include_once
"./Services/MetaData/classes/class.ilMD.php";
756 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
758 $md_sax_parser->setXMLContent($value[
"entry"]);
759 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id,0,
"spl"));
760 $md_sax_parser->enableMDParsing(
true);
761 $md_sax_parser->startParsing();
763 $spl->MDUpdateListener(
"General");
772 if (is_object($this->activequestion))
774 $this->activequestion->importResponses($this->responses);
776 $this->is_matrix = FALSE;
779 array_push($this->variables, $this->characterbuffer);
782 if (is_object($this->activequestion))
784 $this->activequestion->importVariables($this->variables);
787 case "response_single":
788 case "response_multiple":
789 case "response_text":
791 case "response_time":
797 case "bipolar_adjectives":
798 if (is_object($this->activequestion))
800 $this->activequestion->importAdjectives($this->adjectives);
805 foreach ($this->material as $material)
807 $row .= $material[
"text"];
809 $this->matrix[count($this->matrix)-1] =
array(
'title' =>
$row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
812 if (is_object($this->activequestion))
814 $this->activequestion->importMatrix($this->matrix);
820 case "questionblocktitle":
823 case "questionblock":
824 $this->in_questionblock = FALSE;
825 array_push($this->questionblocks,
array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
828 $this->depth[$a_xml_parser]--;
853 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;
parse($a_xml_parser, $a_fp=null)
parse xml file
$attrib
Regular expression to match HTML/XML attribute pairs within a tag.
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