24 require_once(
"./Services/Xml/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");
95 function __construct($a_spl_id, $a_xml_file =
'', $spl_exists = FALSE)
97 die (
"Class surveyImportParserPre38 is deprecated.");
98 parent::__construct($a_xml_file);
99 $this->spl_id = $a_spl_id;
100 $this->has_error = FALSE;
101 $this->characterbuffer =
"";
102 $this->activetag =
"";
103 $this->material =
array();
104 $this->depth =
array();
105 $this->path =
array();
106 $this->metadata =
array();
107 $this->responses =
array();
108 $this->response_id =
"";
109 $this->matrix =
array();
110 $this->is_matrix = FALSE;
111 $this->adjectives =
array();
113 $this->survey = NULL;
114 $this->in_survey = FALSE;
115 $this->anonymisation = 0;
116 $this->surveyaccess =
"restricted";
117 $this->questions =
array();
118 $this->original_question_id =
"";
119 $this->constraints =
array();
120 $this->textblock =
"";
121 $this->textblocks =
array();
122 $this->in_questionblock = FALSE;
123 $this->questionblocks =
array();
124 $this->questionblock =
array();
125 $this->questionblocktitle =
"";
126 $this->question_title =
"";
127 $this->in_question = FALSE;
128 $this->in_response = FALSE;
129 $this->question_description =
"";
138 $this->survey = $a_svy;
148 xml_set_object($a_xml_parser,$this);
149 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
150 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
158 parent::startParsing();
166 function parse($a_xml_parser,$a_fp = null)
172 while(
$data = fread($a_fp,4096))
174 $parseOk = xml_parse($a_xml_parser,
$data,feof($a_fp));
183 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
185 $this->error_code = xml_get_error_code($a_xml_parser);
186 $this->error_line = xml_get_current_line_number($a_xml_parser);
187 $this->error_col = xml_get_current_column_number($a_xml_parser);
188 $this->error_msg = xml_error_string($a_xml_parser);
189 $this->has_error = TRUE;
197 if ($this->depth[$a_xml_parser] > 0)
199 return $this->path[$this->depth[$a_xml_parser]-1];
212 $this->depth[$a_xml_parser]++;
213 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
214 $this->characterbuffer =
"";
215 $this->activetag = $a_name;
217 $this->attributes+=count($a_attribs);
221 $this->in_survey = TRUE;
222 if (is_object($this->survey))
224 if (strlen($a_attribs[
"title"]))
226 $this->survey->setTitle($a_attribs[
"title"]);
234 $this->original_question_id = $a_attribs[
"ident"];
235 $this->question_title = $a_attribs[
"title"];
236 $this->in_question = TRUE;
239 $this->metadata =
array();
241 case "qtimetadatafield":
242 array_push($this->metadata,
array(
"label" =>
"",
"entry" =>
""));
245 $this->material =
array();
246 array_push($this->material,
array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
249 if (is_object($this->activequestion))
251 if (strlen($a_attribs[
"minnumber"]))
253 $this->activequestion->setMinimum($a_attribs[
"minnumber"]);
255 if (strlen($a_attribs[
"maxnumber"]))
257 $this->activequestion->setMaximum($a_attribs[
"maxnumber"]);
262 if (is_object($this->activequestion))
264 if (strcmp($this->activequestion->getQuestiontype(),
"SurveyNominalQuestion") == 0)
266 switch (strtolower($a_attribs[
"rcardinality"]))
269 $this->activequestion->setSubtype(1);
272 $this->activequestion->setSubtype(2);
278 case "response_label":
279 $this->in_response = TRUE;
290 $this->text_size+=strlen($a_data);
291 $this->characterbuffer .= $a_data;
302 case "questestinterop":
303 if (is_object($this->survey))
306 if (count($this->constraints))
308 $relations = $this->survey->getAllRelations(TRUE);
309 foreach ($this->constraints as $constraint)
311 $this->survey->addConstraint($this->questions[$constraint[
"sourceref"]], $this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"]);
315 if (count($this->questionblocks))
317 foreach ($this->questionblocks as
$data)
319 $questionblock = $data[
"questions"];
322 foreach ($questionblock as $question_id)
324 array_push($qblock, $this->questions[$question_id]);
326 $this->survey->createQuestionblock(
$title, TRUE, $qblock);
329 $this->survey->saveToDb();
332 if (count($this->textblocks))
334 foreach ($this->textblocks as $original_id => $textblock)
336 $this->survey->saveHeading($textblock, $this->questions[$original_id]);
342 $this->in_survey = FALSE;
345 if (is_object($this->activequestion))
347 $this->activequestion->setTitle($this->question_title);
348 $this->activequestion->setDescription($this->question_description);
349 $this->activequestion->saveToDb();
350 if (is_object($this->survey))
353 $question_id = $this->activequestion->duplicate(TRUE);
354 $this->survey->addQuestion($question_id);
358 $this->in_question = FALSE;
359 $this->question_description =
"";
360 $this->activequestion = NULL;
363 if (strcmp($this->
getParent($a_xml_parser),
"item") == 0)
365 if (preg_match(
"/Questiontype\=(.*)/", $this->characterbuffer, $matches))
367 $questiontype = $matches[1];
371 $questiontype =
"SurveyMetricQuestion";
374 $questiontype =
"SurveyMultipleChoiceQuestion";
377 $questiontype =
"SurveySingleChoiceQuestion";
380 $questiontype =
"SurveyTextQuestion";
383 if (strlen($questiontype))
385 include_once
"./Modules/SurveyQuestionPool/classes/class.$questiontype.php";
386 $this->activequestion =
new $questiontype();
387 $this->activequestion->setObjId($this->spl_id);
391 $this->activequestion = NULL;
394 else if (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches))
396 if (is_object($this->activequestion))
398 $this->activequestion->setAuthor($matches[1]);
401 else if (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches))
409 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
411 if (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches))
413 if (is_object($this->survey))
415 $this->survey->setAuthor($matches[1]);
418 else if (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches))
423 if (is_object($this->survey))
425 $this->survey->setDescription($this->characterbuffer);
438 if (strcmp($this->
getParent($a_xml_parser),
"section") == 0)
440 foreach ($this->metadata as $meta)
442 switch ($meta[
"label"])
445 if (!$this->spl_exists)
447 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
448 include_once
"./Services/MetaData/classes/class.ilMD.php";
449 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
451 $md_sax_parser->setXMLContent($value[
"entry"]);
452 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id,0,
"spl"));
453 $md_sax_parser->enableMDParsing(
true);
454 $md_sax_parser->startParsing();
456 $spl->MDUpdateListener(
"General");
462 if (is_object($this->activequestion))
464 foreach ($this->metadata as $meta)
466 switch ($this->activequestion->getQuestionType())
468 case "SurveyMultipleQuestion":
469 switch ($meta[
"label"])
472 $this->activequestion->setObligatory($meta[
"entry"]);
475 $this->activequestion->setOrientation($meta[
"entry"]);
479 case "SurveySingleChoiceQuestion":
480 switch ($meta[
"label"])
483 $this->activequestion->setObligatory($meta[
"entry"]);
486 $this->activequestion->setOrientation($meta[
"entry"]);
490 case "SurveyMetricQuestion":
491 switch ($meta[
"label"])
494 $this->activequestion->setObligatory($meta[
"entry"]);
497 $this->activequestion->setSubtype($meta[
"entry"]);
501 case "SurveyTextQuestion":
502 switch ($meta[
"label"])
505 $this->activequestion->setObligatory($meta[
"entry"]);
508 if (strlen($meta[
"entry"]))
510 $this->activequestion->setMaxChars($meta[
"entry"]);
518 if (is_object($this->survey))
520 foreach ($this->metadata as $meta)
522 switch ($meta[
"label"])
525 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0)
527 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
528 include_once
"./Services/MetaData/classes/class.ilMD.php";
530 $md_sax_parser->setXMLContent($meta[
"entry"]);
531 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
532 $md_sax_parser->enableMDParsing(TRUE);
533 $md_sax_parser->startParsing();
534 $this->survey->MDUpdateListener(
"General");
538 $this->survey->setAuthor($meta[
"entry"]);
541 $this->survey->setDescription($meta[
"entry"]);
543 case "evaluation_access":
544 $this->survey->setEvaluationAccess($meta[
"entry"]);
546 case "evaluation_access":
547 $this->survey->setEvaluationAccess($meta[
"entry"]);
550 $this->survey->setAnonymize($meta[
"entry"]);
553 $this->survey->setStatus($meta[
"entry"]);
556 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches))
558 $this->survey->setStartDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
559 $this->survey->setStartDateEnabled(1);
563 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches))
565 $this->survey->setEndDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
566 $this->survey->setEndDateEnabled(1);
569 case "display_question_titles":
572 $this->survey->showQuestionTitles();
576 if (preg_match(
"/questionblock_(\d+)/", $meta[
"label"], $matches))
579 $qb = $meta[
"entry"];
580 preg_match(
"/<title>(.*?)<\/title>/", $qb, $matches);
581 $qb_title = $matches[1];
582 preg_match(
"/<questions>(.*?)<\/questions>/", $qb, $matches);
583 $qb_questions = $matches[1];
584 $qb_questions_array = explode(
",", $qb_questions);
585 array_push($this->questionblocks,
array(
586 "title" => $qb_title,
587 "questions" => $qb_questions_array
590 if (preg_match(
"/constraint_(\d+)/", $meta[
"label"], $matches))
592 $constraint = $meta[
"entry"];
593 $constraint_array = explode(
",", $constraint);
594 if (count($constraint_array) == 3)
596 array_push($this->constraints,
array(
597 "sourceref" => $matches[1],
598 "destref" => $constraint_array[0],
599 "relation" => $constraint_array[1],
600 "value" => $constraint_array[2]
604 if (preg_match(
"/heading_(\d+)/", $meta[
"label"], $matches))
606 $heading = $meta[
"entry"];
607 $this->textblocks[$matches[1]] = $heading;
619 if ($this->in_survey)
621 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0)
623 if (strcmp($this->material[0][
"label"],
"introduction") == 0)
625 if (is_object($this->survey))
627 $this->survey->setIntroduction($this->material[0][
"text"]);
630 if (strcmp($this->material[0][
"label"],
"outro") == 0)
632 if (is_object($this->survey))
634 $this->survey->setOutro($this->material[0][
"text"]);
637 $this->material =
array();
647 if (is_object($this->activequestion))
649 $this->activequestion->setMaterial($this->material[0][
"text"], TRUE, $this->material[0][
"label"]);
653 if (is_object($this->activequestion))
655 $this->activequestion->setQuestiontext($this->material[0][
"text"]);
659 if (is_object($this->activequestion))
661 if ($this->in_response)
663 switch ($this->activequestion->getQuestiontype())
665 case "SurveyMultipleChoiceQuestion":
666 case "SurveySingleChoiceQuestion":
667 $this->activequestion->categories->addCategory($this->material[0][
"text"]);
674 case "response_label":
675 $this->in_response = FALSE;
678 $this->depth[$a_xml_parser]--;
703 return "Error: ".$this->error_msg.
" at line:".$this->error_line .
" column:".
$this->error_col;
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
const NOMINAL_QUESTION_IDENTIFIER
const TEXT_QUESTION_IDENTIFIER
parse($a_xml_parser, $a_fp=null)
parse xml file
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
const METRIC_QUESTION_IDENTIFIER
Old survey question import/export identifiers.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
Create styles array
The data for the language used.
startParsing()
start the parser
const ORDINAL_QUESTION_IDENTIFIER
Survey Question Import Parser.
__construct($a_spl_id, $a_xml_file='', $spl_exists=FALSE)
Constructor.
setSurveyObject($a_svy)
Sets a reference to a survey object public.