24 require_once(
"./classes/class.ilSaxParser.php");
29 define(
"METRIC_QUESTION_IDENTIFIER",
"Metric Question");
30 define(
"NOMINAL_QUESTION_IDENTIFIER",
"Nominal Question");
31 define(
"ORDINAL_QUESTION_IDENTIFIER",
"Ordinal Question");
32 define(
"TEXT_QUESTION_IDENTIFIER",
"Text Question");
99 $this->has_error = FALSE;
100 $this->characterbuffer =
"";
101 $this->activetag =
"";
102 $this->material = array();
103 $this->depth = array();
104 $this->path = array();
105 $this->metadata = array();
106 $this->responses = array();
107 $this->response_id =
"";
108 $this->matrix = array();
109 $this->is_matrix = FALSE;
110 $this->adjectives = array();
112 $this->survey = NULL;
113 $this->in_survey = FALSE;
114 $this->anonymisation = 0;
115 $this->surveyaccess =
"restricted";
116 $this->questions = array();
117 $this->original_question_id =
"";
118 $this->constraints = array();
119 $this->textblock =
"";
120 $this->textblocks = array();
121 $this->in_questionblock = FALSE;
122 $this->questionblocks = array();
123 $this->questionblock = array();
124 $this->questionblocktitle =
"";
125 $this->question_title =
"";
126 $this->in_question = FALSE;
127 $this->in_response = FALSE;
128 $this->question_description =
"";
137 $this->survey =& $a_svy;
147 xml_set_object($a_xml_parser,$this);
148 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
149 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
165 function parse($a_xml_parser,$a_fp = null)
171 while(
$data = fread($a_fp,4096))
173 $parseOk = xml_parse($a_xml_parser,
$data,feof($a_fp));
182 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
184 $this->error_code = xml_get_error_code($a_xml_parser);
185 $this->error_line = xml_get_current_line_number($a_xml_parser);
186 $this->error_col = xml_get_current_column_number($a_xml_parser);
187 $this->error_msg = xml_error_string($a_xml_parser);
188 $this->has_error = TRUE;
196 if ($this->depth[$a_xml_parser] > 0)
198 return $this->path[$this->depth[$a_xml_parser]-1];
211 $this->depth[$a_xml_parser]++;
212 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
213 $this->characterbuffer =
"";
214 $this->activetag = $a_name;
216 $this->attributes+=count($a_attribs);
220 $this->in_survey = TRUE;
221 if (is_object($this->survey))
223 if (strlen($a_attribs[
"title"]))
225 $this->survey->setTitle($a_attribs[
"title"]);
230 $this->spl->setTitle($a_attribs[
"title"]);
233 $this->original_question_id = $a_attribs[
"ident"];
234 $this->question_title = $a_attribs[
"title"];
235 $this->in_question = TRUE;
238 $this->metadata = array();
240 case "qtimetadatafield":
241 array_push($this->metadata, array(
"label" =>
"",
"entry" =>
""));
244 $this->material = array();
245 array_push($this->material, array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
248 if (is_object($this->activequestion))
250 if (strlen($a_attribs[
"minnumber"]))
252 $this->activequestion->setMinimum($a_attribs[
"minnumber"]);
254 if (strlen($a_attribs[
"maxnumber"]))
256 $this->activequestion->setMaximum($a_attribs[
"maxnumber"]);
261 if (is_object($this->activequestion))
263 if (strcmp($this->activequestion->getQuestiontype(),
"SurveyNominalQuestion") == 0)
265 switch (strtolower($a_attribs[
"rcardinality"]))
268 $this->activequestion->setSubtype(1);
271 $this->activequestion->setSubtype(2);
277 case "response_label":
278 $this->in_response = TRUE;
289 $this->text_size+=strlen($a_data);
290 $this->characterbuffer .= $a_data;
301 case "questestinterop":
302 if (is_object($this->survey))
305 if (count($this->constraints))
307 $relations = $this->survey->getAllRelations(TRUE);
308 foreach ($this->constraints as $constraint)
310 $this->survey->addConstraint($this->questions[$constraint[
"sourceref"]], $this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"]);
314 if (count($this->questionblocks))
316 foreach ($this->questionblocks as
$data)
323 array_push($qblock, $this->questions[$question_id]);
325 $this->survey->createQuestionblock(
$title, TRUE, $qblock);
328 $this->survey->saveToDb();
331 if (count($this->textblocks))
333 foreach ($this->textblocks as $original_id =>
$textblock)
335 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
341 $this->in_survey = FALSE;
344 if (is_object($this->activequestion))
346 $this->activequestion->setTitle($this->question_title);
347 $this->activequestion->setDescription($this->question_description);
348 $this->activequestion->saveToDb();
349 if (is_object($this->survey))
352 $question_id = $this->activequestion->duplicate(TRUE);
353 $this->survey->addQuestion($question_id);
357 $this->in_question = FALSE;
358 $this->question_description =
"";
359 $this->activequestion = NULL;
362 if (strcmp($this->
getParent($a_xml_parser),
"item") == 0)
364 if (preg_match(
"/Questiontype\=(.*)/", $this->characterbuffer, $matches))
366 $questiontype = $matches[1];
370 $questiontype =
"SurveyMetricQuestion";
373 $questiontype =
"SurveyMultipleChoiceQuestion";
376 $questiontype =
"SurveySingleChoiceQuestion";
379 $questiontype =
"SurveyTextQuestion";
382 if (strlen($questiontype))
384 include_once
"./Modules/SurveyQuestionPool/classes/class.$questiontype.php";
385 $this->activequestion =
new $questiontype();
386 $this->activequestion->setObjId($this->spl->getId());
390 $this->activequestion = NULL;
393 else if (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches))
395 if (is_object($this->activequestion))
397 $this->activequestion->setAuthor($matches[1]);
400 else if (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches))
408 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
410 if (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches))
412 if (is_object($this->survey))
414 $this->survey->setAuthor($matches[1]);
417 else if (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches))
422 if (is_object($this->survey))
424 $this->survey->setDescription($this->characterbuffer);
437 if (strcmp($this->
getParent($a_xml_parser),
"section") == 0)
439 foreach ($this->metadata as $meta)
441 switch ($meta[
"label"])
444 if (!$this->spl_exists)
446 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
447 include_once
"./Services/MetaData/classes/class.ilMD.php";
449 $md_sax_parser->setXMLContent($meta[
"entry"]);
450 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl->getId(), 0,
"spl"));
451 $md_sax_parser->enableMDParsing(TRUE);
452 $md_sax_parser->startParsing();
453 $this->spl->MDUpdateListener(
"General");
459 if (is_object($this->activequestion))
461 foreach ($this->metadata as $meta)
463 switch ($this->activequestion->getQuestionType())
465 case "SurveyMultipleQuestion":
466 switch ($meta[
"label"])
469 $this->activequestion->setObligatory($meta[
"entry"]);
472 $this->activequestion->setOrientation($meta[
"entry"]);
476 case "SurveySingleChoiceQuestion":
477 switch ($meta[
"label"])
480 $this->activequestion->setObligatory($meta[
"entry"]);
483 $this->activequestion->setOrientation($meta[
"entry"]);
487 case "SurveyMetricQuestion":
488 switch ($meta[
"label"])
491 $this->activequestion->setObligatory($meta[
"entry"]);
494 $this->activequestion->setSubtype($meta[
"entry"]);
498 case "SurveyTextQuestion":
499 switch ($meta[
"label"])
502 $this->activequestion->setObligatory($meta[
"entry"]);
505 if (strlen($meta[
"entry"]))
507 $this->activequestion->setMaxChars($meta[
"entry"]);
515 if (is_object($this->survey))
517 foreach ($this->metadata as $meta)
519 switch ($meta[
"label"])
522 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
524 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
525 include_once
"./Services/MetaData/classes/class.ilMD.php";
527 $md_sax_parser->setXMLContent($meta[
"entry"]);
528 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
529 $md_sax_parser->enableMDParsing(TRUE);
530 $md_sax_parser->startParsing();
531 $this->survey->MDUpdateListener(
"General");
535 $this->survey->setAuthor($meta[
"entry"]);
538 $this->survey->setDescription($meta[
"entry"]);
540 case "evaluation_access":
541 $this->survey->setEvaluationAccess($meta[
"entry"]);
543 case "evaluation_access":
544 $this->survey->setEvaluationAccess($meta[
"entry"]);
547 $this->survey->setAnonymize($meta[
"entry"]);
550 $this->survey->setStatus($meta[
"entry"]);
553 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches))
555 $this->survey->setStartDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
556 $this->survey->setStartDateEnabled(1);
560 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches))
562 $this->survey->setEndDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
563 $this->survey->setEndDateEnabled(1);
566 case "display_question_titles":
569 $this->survey->showQuestionTitles();
573 if (preg_match(
"/questionblock_(\d+)/", $meta[
"label"], $matches))
576 $qb = $meta[
"entry"];
577 preg_match(
"/<title>(.*?)<\/title>/", $qb, $matches);
578 $qb_title = $matches[1];
579 preg_match(
"/<questions>(.*?)<\/questions>/", $qb, $matches);
580 $qb_questions = $matches[1];
581 $qb_questions_array = explode(
",", $qb_questions);
582 array_push($this->questionblocks, array(
583 "title" => $qb_title,
584 "questions" => $qb_questions_array
587 if (preg_match(
"/constraint_(\d+)/", $meta[
"label"], $matches))
589 $constraint = $meta[
"entry"];
590 $constraint_array = explode(
",", $constraint);
591 if (count($constraint_array) == 3)
593 array_push($this->constraints, array(
594 "sourceref" => $matches[1],
595 "destref" => $constraint_array[0],
596 "relation" => $constraint_array[1],
597 "value" => $constraint_array[2]
601 if (preg_match(
"/heading_(\d+)/", $meta[
"label"], $matches))
603 $heading = $meta[
"entry"];
604 $this->textblocks[$matches[1]] = $heading;
616 if ($this->in_survey)
618 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
620 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
622 if (is_object($this->survey))
624 $this->survey->setIntroduction($this->material[0][
"text"]);
627 if (strcmp($this->material[0][
"label"],
"outro") == 0)
629 if (is_object($this->survey))
631 $this->survey->setOutro($this->material[0][
"text"]);
634 $this->material = array();
644 if (is_object($this->activequestion))
646 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
650 if (is_object($this->activequestion))
652 $this->activequestion->setQuestiontext($this->material[0][
"text"]);
656 if (is_object($this->activequestion))
658 if ($this->in_response)
660 switch ($this->activequestion->getQuestiontype())
662 case "SurveyMultipleChoiceQuestion":
663 case "SurveySingleChoiceQuestion":
664 $this->activequestion->categories->addCategory($this->material[0][
"text"]);
671 case "response_label":
672 $this->in_response = FALSE;
675 $this->depth[$a_xml_parser]--;
700 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;