66 $this->spl_id = $a_spl_id;
67 $this->has_error =
false;
68 $this->characterbuffer =
"";
69 $this->survey_status = 0;
70 $this->activetag =
"";
71 $this->material = array();
72 $this->depth = array();
73 $this->path = array();
74 $this->metadata = array();
75 $this->responses = array();
76 $this->variables = array();
77 $this->response_id =
"";
78 $this->matrix = array();
79 $this->is_matrix =
false;
80 $this->adjectives = array();
83 $this->in_survey =
false;
84 $this->anonymisation = 0;
85 $this->surveyaccess =
"restricted";
86 $this->questions = array();
87 $this->original_question_id =
"";
88 $this->constraints = array();
89 $this->textblock =
"";
90 $this->textblocks = array();
91 $this->in_questionblock =
false;
92 $this->questionblocks = array();
93 $this->questionblock = array();
94 $this->showQuestiontext = 1;
95 $this->showBlocktitle = 0;
96 $this->compressView = 0;
97 $this->questionblocktitle =
"";
98 $this->mapping = $a_mapping;
107 $this->survey = $a_svy;
117 xml_set_object($a_xml_parser, $this);
118 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
119 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
127 parent::startParsing();
135 public function parse($a_xml_parser, $a_fp = null)
140 while (
$data = fread($a_fp, 4096)) {
141 $parseOk = xml_parse($a_xml_parser,
$data, feof($a_fp));
150 && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
151 $this->error_code = xml_get_error_code($a_xml_parser);
152 $this->error_line = xml_get_current_line_number($a_xml_parser);
153 $this->error_col = xml_get_current_column_number($a_xml_parser);
154 $this->error_msg = xml_error_string($a_xml_parser);
155 $this->has_error =
true;
163 if ($this->depth[$a_xml_parser] > 0) {
164 return $this->path[$this->depth[$a_xml_parser] - 1];
176 $this->depth[$a_xml_parser]++;
177 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
178 $this->characterbuffer =
"";
179 $this->activetag = $a_name;
181 $this->attributes += count($a_attribs);
183 case "questionblock":
184 $this->in_questionblock =
true;
185 $this->questionblock = array();
186 $this->questionblocktitle =
"";
187 $this->showQuestiontext = 1;
188 $this->showBlocktitle = 0;
189 $this->compressView = 0;
190 foreach ($a_attribs as
$attrib => $value) {
192 case "showQuestiontext":
193 $this->showQuestiontext = (int) $value;
195 case "showBlocktitle":
196 $this->showBlocktitle = (int) $value;
199 $this->compressView = (int) $value;
204 case "surveyquestions":
205 foreach ($a_attribs as
$attrib => $value) {
208 if ($this->spl_id > 0) {
210 $spl->setOnline($value);
218 $this->in_survey =
true;
219 foreach ($a_attribs as
$attrib => $value) {
222 if (is_object($this->survey)) {
223 $this->survey->setTitle($value);
224 $this->survey->update(
true);
230 case "anonymisation":
231 foreach ($a_attribs as
$attrib => $value) {
234 $this->anonymisation = $value;
240 foreach ($a_attribs as
$attrib => $value) {
243 $this->surveyaccess = $value;
252 "sourceref" => $a_attribs[
"sourceref"],
253 "destref" => $a_attribs[
"destref"],
254 "relation" => $a_attribs[
"relation"],
255 "value" => $a_attribs[
"value"],
258 "conjunction" => (
int) $a_attribs[
"conjuction"]
264 $type = $a_attribs[
"type"];
267 case 'SurveyNominalQuestion':
268 $type =
'SurveyMultipleChoiceQuestion';
269 foreach ($a_attribs as $key => $value) {
273 $type =
'SurveySingleChoiceQuestion';
275 $type =
'SurveyMultipleChoiceQuestion';
281 case 'SurveyOrdinalQuestion':
282 $type =
'SurveySingleChoiceQuestion';
287 $this->activequestion =
new $type();
290 $q_obj_id = $this->spl_id;
291 if ($this->spl_id < 0) {
292 $q_obj_id = $this->survey->getId();
295 $this->activequestion->setObjId($q_obj_id);
298 $this->activequestion = null;
300 $this->original_question_id = $a_attribs[
"id"];
301 if ($this->in_questionblock) {
302 array_push($this->questionblock, $this->original_question_id);
304 if (is_object($this->activequestion)) {
305 foreach ($a_attribs as $key => $value) {
308 $this->activequestion->setTitle($value);
311 $this->activequestion->setSubtype($value);
314 $this->activequestion->setObligatory($value);
321 switch ($this->
getParent($a_xml_parser)) {
324 $this->material = array();
327 array_push($this->material, array(
"text" =>
"",
"image" =>
"",
"label" => $a_attribs[
"label"]));
331 if (array_key_exists(
"label", $a_attribs)) {
332 if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches)) {
334 if (!is_array(
$_SESSION[
"import_mob_xhtml"])) {
337 array_push(
$_SESSION[
"import_mob_xhtml"], array(
"mob" => $a_attribs[
"label"],
"uri" => $a_attribs[
"uri"],
"type" => $a_attribs[
"type"],
"id" => $a_attribs[
"id"]));
342 $this->metadata = array();
344 case "metadatafield":
345 array_push($this->metadata, array(
"label" =>
"",
"entry" =>
""));
348 $this->is_matrix =
true;
349 $this->matrix = array();
352 $this->material = array();
353 array_push($this->matrix,
"");
354 $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"],
"label" => $a_attribs[
"label"],
"other" => $a_attribs[
"other"]);
357 $this->material = array();
358 $this->responses = array();
361 $this->variables = array();
363 case "response_single":
364 $this->material = array();
365 $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"]);
366 $this->response_id = $a_attribs[
"id"];
368 case "response_multiple":
369 $this->material = array();
370 $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"]);
371 $this->response_id = $a_attribs[
"id"];
373 case "response_text":
374 $this->material = array();
375 $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"]);
376 $this->response_id = $a_attribs[
"id"];
379 $this->material = array();
380 $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"]);
381 $this->response_id = $a_attribs[
"id"];
383 case "response_time":
384 $this->material = array();
385 $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"]);
386 $this->response_id = $a_attribs[
"id"];
388 case "bipolar_adjectives":
389 $this->adjectives = array();
392 array_push($this->adjectives, array(
"label" => $a_attribs[
"label"],
"text" =>
""));
403 $this->text_size += strlen($a_data);
404 $this->characterbuffer .= $a_data;
410 return $this->
trimAndStrip((
string) $this->characterbuffer);
420 if (is_object($this->survey)) {
421 $this->survey->setOfflineStatus(!$this->survey_status);
422 $this->survey->saveToDb();
425 if (count($this->questionblocks)) {
426 foreach ($this->questionblocks as
$data) {
428 $title = $data[
"title"];
431 array_push($qblock, $this->questions[$question_id]);
433 $this->survey->createQuestionblock(
435 $this->showQuestiontext,
436 $this->showBlocktitle,
444 if (count($this->constraints)) {
445 $relations = $this->survey->getAllRelations(
true);
446 foreach ($this->constraints as $constraint) {
447 $constraint_id = $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
448 $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
453 if (count($this->textblocks)) {
454 foreach ($this->textblocks as $original_id =>
$textblock) {
455 $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
461 $this->in_survey =
false;
462 if (is_object($this->survey)) {
463 if (strcmp($this->surveyaccess,
"free") == 0) {
464 $this->survey->setAnonymize(2);
466 if ($this->anonymisation == 0) {
467 $this->survey->setAnonymize(0);
469 $this->survey->setAnonymize(1);
475 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
476 if (is_object($this->survey)) {
477 $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
482 if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->
getCharacterBuffer(), $matches)) {
483 if (is_object($this->survey)) {
484 $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
489 if ($this->in_survey) {
490 if (is_object($this->survey)) {
492 $this->survey->update(
true);
495 if (is_object($this->activequestion)) {
501 if (is_object($this->activequestion)) {
502 if (strlen($this->textblock)) {
505 $this->activequestion->saveToDb();
507 if (is_object($this->survey) &&
509 $question_id = $this->activequestion->duplicate(
true,
"",
"",
"", $this->survey->getId());
511 $question_id = $this->activequestion->getId();
513 if (is_object($this->survey)) {
514 $this->survey->addQuestion($question_id);
517 if ($this->mapping) {
518 $this->mapping->addMapping(
"Modules/Survey",
"svy_q", $this->original_question_id, $question_id);
520 $this->activequestion = null;
522 $this->textblock =
"";
525 if ($this->in_survey) {
526 if (is_object($this->survey)) {
530 if (is_object($this->activequestion)) {
542 if ($this->in_survey) {
543 if (strcmp($this->
getParent($a_xml_parser),
"objectives") == 0) {
544 if (strcmp($this->material[0][
"label"],
"introduction") == 0) {
545 if (is_object($this->survey)) {
546 $this->survey->setIntroduction($this->material[0][
"text"]);
549 if (strcmp($this->material[0][
"label"],
"outro") == 0) {
550 if (is_object($this->survey)) {
551 $this->survey->setOutro($this->material[0][
"text"]);
554 $this->material = array();
557 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0) {
558 $this->activequestion->setMaterial($this->material[0][
"text"],
true, $this->material[0][
"label"]);
563 if (is_object($this->activequestion)) {
565 foreach ($this->material as $matarray) {
566 $questiontext .= $matarray[
"text"];
568 $this->activequestion->setQuestiontext($questiontext);
570 $this->material = array();
579 if (strcmp($this->
getParent($a_xml_parser),
"question") == 0) {
580 if (is_object($this->activequestion)) {
581 $this->activequestion->importAdditionalMetadata($this->metadata);
584 if (strcmp($this->
getParent($a_xml_parser),
"survey") == 0) {
585 foreach ($this->metadata as $key => $value) {
586 switch ($value[
"label"]) {
588 if (strlen($value[
"entry"])) {
589 if (is_object($this->survey)) {
591 $md_sax_parser->setXMLContent($value[
"entry"]);
592 $md_sax_parser->setMDObject($tmp =
new ilMD($this->survey->getId(), 0,
"svy"));
593 $md_sax_parser->enableMDParsing(
true);
594 $md_sax_parser->startParsing();
595 $this->survey->MDUpdateListener(
"General");
599 case "display_question_titles":
600 if ($value[
"entry"] == 1) {
601 $this->survey->showQuestionTitles();
603 $this->survey->hideQuestionTitles();
607 $this->survey_status = $value[
"entry"];
609 case "evaluation_access":
610 $this->survey->setEvaluationAccess($value[
"entry"]);
613 $this->survey->setPoolUsage($value[
"entry"]);
615 case "own_results_view":
616 $this->survey->setViewOwnResults($value[
"entry"]);
618 case "own_results_mail":
619 $this->survey->setMailOwnResults($value[
"entry"]);
621 case "confirmation_mail":
622 $this->survey->setMailConfirmation($value[
"entry"]);
624 case "anon_user_list":
625 $this->survey->setAnonymousUserList($value[
"entry"]);
628 $this->survey->setMode($value[
"entry"]);
630 case "mode_360_self_eval":
631 $this->survey->set360SelfEvaluation($value[
"entry"]);
633 case "mode_360_self_rate":
634 $this->survey->set360SelfRaters($value[
"entry"]);
636 case "mode_360_self_appr":
637 $this->survey->set360SelfAppraisee($value[
"entry"]);
639 case "mode_360_results":
640 $this->survey->set360Results($value[
"entry"]);
642 case "mode_self_eval_results":
643 $this->survey->setSelfEvaluationResults($value[
"entry"]);
645 case "mode_skill_service":
646 $this->survey->setSkillService($value[
"entry"]);
651 if (!$this->spl_exists) {
652 if (strcmp($this->
getParent($a_xml_parser),
"surveyquestions") == 0) {
653 foreach ($this->metadata as $key => $value) {
654 if (strcmp($value[
"label"],
"SCORM") == 0) {
655 if (strlen($value[
"entry"])) {
656 if ($this->spl_id > 0) {
658 $md_sax_parser->setXMLContent($value[
"entry"]);
659 $md_sax_parser->setMDObject($tmp =
new ilMD($this->spl_id, 0,
"spl"));
660 $md_sax_parser->enableMDParsing(
true);
661 $md_sax_parser->startParsing();
663 $spl->MDUpdateListener(
"General");
672 if (is_object($this->activequestion)) {
673 $this->activequestion->importResponses($this->responses);
675 $this->is_matrix =
false;
681 if (is_object($this->activequestion)) {
682 $this->activequestion->importVariables($this->variables);
685 case "response_single":
686 case "response_multiple":
687 case "response_text":
689 case "response_time":
693 $this->adjectives[count($this->adjectives) - 1][
"text"] = $this->
getCharacterBuffer();
695 case "bipolar_adjectives":
696 if (is_object($this->activequestion)) {
697 $this->activequestion->importAdjectives($this->adjectives);
703 $row .= $material[
"text"];
705 $this->matrix[count($this->matrix) - 1] = array(
'title' => $row,
'id' => $this->matrixrowattribs[
'id'],
'label' => $this->matrixrowattribs[
'label'],
'other' => $this->matrixrowattribs[
'other']);
708 if (is_object($this->activequestion)) {
709 $this->activequestion->importMatrix($this->matrix);
715 case "questionblocktitle":
718 case "questionblock":
719 $this->in_questionblock =
false;
720 array_push($this->questionblocks, array(
"title" => $this->questionblocktitle,
"questions" => $this->questionblock));
723 $this->depth[$a_xml_parser]--;
748 return "Error: " . $this->error_msg .
" at line:" . $this->error_line .
" column:" .
$this->error_col;
784 foreach ($attribs as $k => $v) {
trimAndStrip(string $input)
parse($a_xml_parser, $a_fp=null)
parse xml file
Class ilObjSurveyQuestionPool.
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.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
trimAndStripAttribs(array $attribs)
__construct(Container $dic, ilPlugin $plugin)
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
$attrib
Regular expression to match HTML/XML attribute pairs within a tag.