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");
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 public function parse($a_xml_parser, $a_fp = null)
171 while (
$data = fread($a_fp, 4096)) {
172 $parseOk = xml_parse($a_xml_parser,
$data, feof($a_fp));
181 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
182 $this->error_code = xml_get_error_code($a_xml_parser);
183 $this->error_line = xml_get_current_line_number($a_xml_parser);
184 $this->error_col = xml_get_current_column_number($a_xml_parser);
185 $this->error_msg = xml_error_string($a_xml_parser);
186 $this->has_error =
true;
194 if ($this->depth[$a_xml_parser] > 0) {
195 return $this->path[$this->depth[$a_xml_parser]-1];
206 $this->depth[$a_xml_parser]++;
207 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
208 $this->characterbuffer =
"";
209 $this->activetag = $a_name;
211 $this->attributes+=count($a_attribs);
214 $this->in_survey =
true;
215 if (is_object($this->survey)) {
216 if (strlen($a_attribs[
"title"])) {
217 $this->survey->setTitle($a_attribs[
"title"]);
225 $this->original_question_id = $a_attribs[
"ident"];
226 $this->question_title = $a_attribs[
"title"];
227 $this->in_question =
true;
230 $this->metadata =
array();
232 case "qtimetadatafield":
233 array_push($this->metadata,
array(
"label" =>
"",
"entry" =>
""));
236 $this->material =
array();
237 array_push($this->material,
array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
240 if (is_object($this->activequestion)) {
241 if (strlen($a_attribs[
"minnumber"])) {
242 $this->activequestion->setMinimum($a_attribs[
"minnumber"]);
244 if (strlen($a_attribs[
"maxnumber"])) {
245 $this->activequestion->setMaximum($a_attribs[
"maxnumber"]);
250 if (is_object($this->activequestion)) {
251 if (strcmp($this->activequestion->getQuestiontype(),
"SurveyNominalQuestion") == 0) {
252 switch (strtolower($a_attribs[
"rcardinality"])) {
254 $this->activequestion->setSubtype(1);
257 $this->activequestion->setSubtype(2);
263 case "response_label":
264 $this->in_response =
true;
275 $this->text_size+=strlen($a_data);
276 $this->characterbuffer .= $a_data;
286 case "questestinterop":
287 if (is_object($this->survey)) {
289 if (count($this->constraints)) {
290 $relations = $this->survey->getAllRelations(
true);
291 foreach ($this->constraints as $constraint) {
292 $this->survey->addConstraint($this->questions[$constraint[
"sourceref"]], $this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"]);
296 if (count($this->questionblocks)) {
297 foreach ($this->questionblocks as
$data) {
302 array_push($qblock, $this->questions[$question_id]);
304 $this->survey->createQuestionblock(
$title,
true, $qblock);
307 $this->survey->saveToDb();
310 if (count($this->textblocks)) {
311 foreach ($this->textblocks as $original_id =>
$textblock) {
312 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
318 $this->in_survey =
false;
321 if (is_object($this->activequestion)) {
322 $this->activequestion->setTitle($this->question_title);
323 $this->activequestion->setDescription($this->question_description);
324 $this->activequestion->saveToDb();
325 if (is_object($this->survey)) {
327 $question_id = $this->activequestion->duplicate(
true);
328 $this->survey->addQuestion($question_id);
332 $this->in_question =
false;
333 $this->question_description =
"";
334 $this->activequestion = null;
337 if (strcmp($this->
getParent($a_xml_parser),
"item") == 0) {
338 if (preg_match(
"/Questiontype\=(.*)/", $this->characterbuffer, $matches)) {
339 $questiontype = $matches[1];
340 switch ($matches[1]) {
342 $questiontype =
"SurveyMetricQuestion";
345 $questiontype =
"SurveyMultipleChoiceQuestion";
348 $questiontype =
"SurveySingleChoiceQuestion";
351 $questiontype =
"SurveyTextQuestion";
354 if (strlen($questiontype)) {
355 include_once
"./Modules/SurveyQuestionPool/classes/class.$questiontype.php";
356 $this->activequestion =
new $questiontype();
357 $this->activequestion->setObjId($this->spl_id);
359 $this->activequestion = null;
361 } elseif (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches)) {
362 if (is_object($this->activequestion)) {
363 $this->activequestion->setAuthor($matches[1]);
365 } elseif (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches)) {
370 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0) {
371 if (preg_match(
"/Author\=(.*)/", $this->characterbuffer, $matches)) {
372 if (is_object($this->survey)) {
373 $this->survey->setAuthor($matches[1]);
375 } elseif (preg_match(
"/ILIAS Version\=(.*)/", $this->characterbuffer, $matches)) {
377 if (is_object($this->survey)) {
378 $this->survey->setDescription($this->characterbuffer);
390 if (strcmp($this->
getParent($a_xml_parser),
"section") == 0) {
391 foreach ($this->metadata as $meta) {
392 switch ($meta[
"label"]) {
394 if (!$this->spl_exists) {
395 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
396 include_once
"./Services/MetaData/classes/class.ilMD.php";
397 include_once
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
399 $md_sax_parser->setXMLContent($value[
"entry"]);
400 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id, 0,
"spl"));
401 $md_sax_parser->enableMDParsing(
true);
402 $md_sax_parser->startParsing();
404 $spl->MDUpdateListener(
"General");
410 if (is_object($this->activequestion)) {
411 foreach ($this->metadata as $meta) {
412 switch ($this->activequestion->getQuestionType()) {
413 case "SurveyMultipleQuestion":
414 switch ($meta[
"label"]) {
416 $this->activequestion->setObligatory($meta[
"entry"]);
419 $this->activequestion->setOrientation($meta[
"entry"]);
423 case "SurveySingleChoiceQuestion":
424 switch ($meta[
"label"]) {
426 $this->activequestion->setObligatory($meta[
"entry"]);
429 $this->activequestion->setOrientation($meta[
"entry"]);
433 case "SurveyMetricQuestion":
434 switch ($meta[
"label"]) {
436 $this->activequestion->setObligatory($meta[
"entry"]);
439 $this->activequestion->setSubtype($meta[
"entry"]);
443 case "SurveyTextQuestion":
444 switch ($meta[
"label"]) {
446 $this->activequestion->setObligatory($meta[
"entry"]);
449 if (strlen($meta[
"entry"])) {
450 $this->activequestion->setMaxChars($meta[
"entry"]);
458 if (is_object($this->survey)) {
459 foreach ($this->metadata as $meta) {
460 switch ($meta[
"label"]) {
462 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0) {
463 include_once
"./Services/MetaData/classes/class.ilMDSaxParser.php";
464 include_once
"./Services/MetaData/classes/class.ilMD.php";
466 $md_sax_parser->setXMLContent($meta[
"entry"]);
467 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
468 $md_sax_parser->enableMDParsing(
true);
469 $md_sax_parser->startParsing();
470 $this->survey->MDUpdateListener(
"General");
474 $this->survey->setAuthor($meta[
"entry"]);
477 $this->survey->setDescription($meta[
"entry"]);
479 case "evaluation_access":
480 $this->survey->setEvaluationAccess($meta[
"entry"]);
482 case "evaluation_access":
483 $this->survey->setEvaluationAccess($meta[
"entry"]);
486 $this->survey->setAnonymize($meta[
"entry"]);
489 $this->survey->setStatus($meta[
"entry"]);
492 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches)) {
493 $this->survey->setStartDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
494 $this->survey->setStartDateEnabled(1);
498 if (preg_match(
"/P(\d+)Y(\d+)M(\d+)DT0H0M0S/", $meta[
"entry"], $matches)) {
499 $this->survey->setEndDate(sprintf(
"%04d-%02d-%02d", $matches[1], $matches[2], $matches[3]));
500 $this->survey->setEndDateEnabled(1);
503 case "display_question_titles":
504 if ($meta[
"entry"]) {
505 $this->survey->showQuestionTitles();
509 if (preg_match(
"/questionblock_(\d+)/", $meta[
"label"], $matches)) {
511 $qb = $meta[
"entry"];
512 preg_match(
"/<title>(.*?)<\/title>/", $qb, $matches);
513 $qb_title = $matches[1];
514 preg_match(
"/<questions>(.*?)<\/questions>/", $qb, $matches);
515 $qb_questions = $matches[1];
516 $qb_questions_array = explode(
",", $qb_questions);
517 array_push($this->questionblocks,
array(
518 "title" => $qb_title,
519 "questions" => $qb_questions_array
522 if (preg_match(
"/constraint_(\d+)/", $meta[
"label"], $matches)) {
523 $constraint = $meta[
"entry"];
524 $constraint_array = explode(
",", $constraint);
525 if (count($constraint_array) == 3) {
526 array_push($this->constraints,
array(
527 "sourceref" => $matches[1],
528 "destref" => $constraint_array[0],
529 "relation" => $constraint_array[1],
530 "value" => $constraint_array[2]
534 if (preg_match(
"/heading_(\d+)/", $meta[
"label"], $matches)) {
535 $heading = $meta[
"entry"];
536 $this->textblocks[$matches[1]] = $heading;
548 if ($this->in_survey) {
549 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0) {
550 if (strcmp($this->material[0][
"label"],
"introduction") == 0) {
551 if (is_object($this->survey)) {
552 $this->survey->setIntroduction($this->material[0][
"text"]);
555 if (strcmp($this->material[0][
"label"],
"outro") == 0) {
556 if (is_object($this->survey)) {
557 $this->survey->setOutro($this->material[0][
"text"]);
560 $this->material =
array();
563 switch ($this->
getParent($a_xml_parser)) {
567 if (is_object($this->activequestion)) {
568 $this->activequestion->setMaterial($this->material[0][
"text"],
true, $this->material[0][
"label"]);
572 if (is_object($this->activequestion)) {
573 $this->activequestion->setQuestiontext($this->material[0][
"text"]);
577 if (is_object($this->activequestion)) {
578 if ($this->in_response) {
579 switch ($this->activequestion->getQuestiontype()) {
580 case "SurveyMultipleChoiceQuestion":
581 case "SurveySingleChoiceQuestion":
582 $this->activequestion->categories->addCategory($this->material[0][
"text"]);
589 case "response_label":
590 $this->in_response =
false;
593 $this->depth[$a_xml_parser]--;
618 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
__construct($a_spl_id, $a_xml_file='', $spl_exists=false)
Constructor.
Survey Question Import Parser.
setSurveyObject($a_svy)
Sets a reference to a survey object public.