24 require_once(
"./Services/Xml/classes/class.ilSaxParser.php");
87 parent::ilSaxParser($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 =
"";
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');
146 parent::startParsing();
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"],
"type" => $a_attribs[
"type"],
"id" => $a_attribs[
"id"]));
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))
463 $this->survey->setStatus($this->survey_status);
464 $this->survey->saveToDb();
467 if (count($this->questionblocks))
469 foreach ($this->questionblocks as
$data)
471 $questionblock = $data[
"questions"];
472 $title = $data[
"title"];
474 foreach ($questionblock as $question_id)
476 array_push($qblock, $this->questions[$question_id]);
478 $this->survey->createQuestionblock($title, $this->showQuestiontext,
false, $qblock);
483 if (count($this->constraints))
485 $relations = $this->survey->getAllRelations(TRUE);
486 foreach ($this->constraints as $constraint)
488 $constraint_id= $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
489 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
494 if (count($this->textblocks))
496 foreach ($this->textblocks as $original_id => $textblock)
498 $this->survey->saveHeading($textblock, $this->questions[$original_id]);
504 $this->in_survey = FALSE;
505 if (is_object($this->survey))
507 if (strcmp($this->surveyaccess,
"free") == 0)
509 $this->survey->setAnonymize(2);
513 if ($this->anonymisation == 0)
515 $this->survey->setAnonymize(0);
519 $this->survey->setAnonymize(1);
525 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2})-(\d{2})-(\d{2}).*/", $this->characterbuffer, $matches))
527 if (is_object($this->survey))
529 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
530 $this->survey->setStartDateEnabled(1);
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]));
540 $this->survey->setEndDateEnabled(1);
545 if ($this->in_survey)
547 if (is_object($this->survey))
549 $this->survey->setDescription($this->characterbuffer);
554 if (is_object($this->activequestion))
556 $this->activequestion->setDescription($this->characterbuffer);
561 if (is_object($this->activequestion))
563 if (strlen($this->textblock))
567 $this->activequestion->saveToDb();
569 if (is_object($this->survey) &&
572 $question_id = $this->activequestion->duplicate(TRUE);
576 $question_id = $this->activequestion->getId();
578 if (is_object($this->survey))
580 $this->survey->addQuestion($question_id);
583 $this->activequestion = NULL;
585 $this->textblock =
"";
588 if ($this->in_survey)
590 if (is_object($this->survey))
592 $this->survey->setAuthor($this->characterbuffer);
597 if (is_object($this->activequestion))
599 $this->activequestion->setAuthor($this->characterbuffer);
610 if ($this->in_survey)
612 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
614 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
616 if (is_object($this->survey))
618 $this->survey->setIntroduction($this->material[0][
"text"]);
621 if (strcmp($this->material[0][
"label"],
"outro") == 0)
623 if (is_object($this->survey))
625 $this->survey->setOutro($this->material[0][
"text"]);
628 $this->material = array();
633 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
635 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
640 if (is_object($this->activequestion))
643 foreach ($this->material as $matarray)
645 $questiontext .= $matarray[
"text"];
647 $this->activequestion->setQuestiontext($questiontext);
649 $this->material = array();
658 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0)
660 if (is_object($this->activequestion))
662 $this->activequestion->importAdditionalMetadata($this->metadata);
665 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
667 foreach ($this->metadata as $key => $value)
669 switch ($value[
"label"])
672 if (strlen($value[
"entry"]))
674 if (is_object($this->survey))
676 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
677 include_once
"./Services/MetaData/classes/class.ilMD.php";
679 $md_sax_parser->setXMLContent($value[
"entry"]);
680 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(),0,
"svy"));
681 $md_sax_parser->enableMDParsing(
true);
682 $md_sax_parser->startParsing();
683 $this->survey->MDUpdateListener(
"General");
687 case "display_question_titles":
688 if ($value[
"entry"] == 1)
690 $this->survey->showQuestionTitles();
694 $this->survey->hideQuestionTitles();
698 $this->survey_status = $value[
"entry"];
700 case "evaluation_access":
701 $this->survey->setEvaluationAccess($value[
"entry"]);
704 $this->survey->setPoolUsage($value[
"entry"]);
706 case "own_results_view":
707 $this->survey->setViewOwnResults($value[
"entry"]);
709 case "own_results_mail":
710 $this->survey->setMailOwnResults($value[
"entry"]);
713 $this->survey->set360Mode($value[
"entry"]);
715 case "mode_360_self_eval":
716 $this->survey->set360SelfEvaluation($value[
"entry"]);
718 case "mode_360_self_rate":
719 $this->survey->set360SelfRaters($value[
"entry"]);
721 case "mode_360_self_appr":
722 $this->survey->set360SelfAppraisee($value[
"entry"]);
724 case "mode_360_results":
725 $this->survey->set360Results($value[
"entry"]);
727 case "mode_360_skill_service":
728 $this->survey->set360SkillService($value[
"entry"]);
733 if (!$this->spl_exists)
735 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0)
737 foreach ($this->metadata as $key => $value)
739 if (strcmp($value[
"label"],
"SCORM") == 0)
741 if (strlen($value[
"entry"]))
743 if ($this->spl_id > 0)
745 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
746 include_once
"./Services/MetaData/classes/class.ilMD.php";
747 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
749 $md_sax_parser->setXMLContent($value[
"entry"]);
750 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id,0,
"spl"));
751 $md_sax_parser->enableMDParsing(
true);
752 $md_sax_parser->startParsing();
754 $spl->MDUpdateListener(
"General");
763 if (is_object($this->activequestion))
765 $this->activequestion->importResponses($this->responses);
767 $this->is_matrix = FALSE;
770 array_push($this->variables, $this->characterbuffer);
773 if (is_object($this->activequestion))
775 $this->activequestion->importVariables($this->variables);
778 case "response_single":
779 case "response_multiple":
780 case "response_text":
782 case "response_time":
788 case "bipolar_adjectives":
789 if (is_object($this->activequestion))
791 $this->activequestion->importAdjectives($this->adjectives);
796 foreach ($this->material as $material)
798 $row .= $material[
"text"];
800 $this->matrix[count($this->matrix)-1] = array(
'title' =>
$row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
803 if (is_object($this->activequestion))
805 $this->activequestion->importMatrix($this->matrix);
811 case "questionblocktitle":
814 case "questionblock":
815 $this->in_questionblock = FALSE;
816 array_push($this->questionblocks, array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
819 $this->depth[$a_xml_parser]--;
844 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;
SurveyImportParser($a_spl_id, $a_xml_file='', $spl_exists=FALSE)
Constructor.
setSurveyObject(&$a_svy)
Sets a reference to a survey object public.
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.
Survey Question Import Parser.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
startParsing()
start the parser
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private