24require_once(
"./Services/Xml/classes/class.ilSaxParser.php");
 
   87        parent::__construct($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 = 
"";
 
  118        $this->mapping = $a_mapping;
 
  127        $this->survey = $a_svy;
 
  137        xml_set_object($a_xml_parser, $this);
 
  138        xml_set_element_handler($a_xml_parser, 
'handlerBeginTag', 
'handlerEndTag');
 
  139        xml_set_character_data_handler($a_xml_parser, 
'handlerCharacterData');
 
  147        parent::startParsing();
 
  155    public function parse($a_xml_parser, $a_fp = 
null)
 
  160                while (
$data = fread($a_fp, 4096)) {
 
  161                    $parseOk = xml_parse($a_xml_parser, 
$data, feof($a_fp));
 
  170           && (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE)) {
 
  171            $this->error_code = xml_get_error_code($a_xml_parser);
 
  172            $this->error_line = xml_get_current_line_number($a_xml_parser);
 
  173            $this->error_col = xml_get_current_column_number($a_xml_parser);
 
  174            $this->error_msg = xml_error_string($a_xml_parser);
 
  175            $this->has_error = 
true;
 
  183        if ($this->depth[$a_xml_parser] > 0) {
 
  184            return $this->path[$this->depth[$a_xml_parser] - 1];
 
  195        $this->depth[$a_xml_parser]++;
 
  196        $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
 
  197        $this->characterbuffer = 
"";
 
  198        $this->activetag = $a_name;
 
  200        $this->attributes += count($a_attribs);
 
  202            case "questionblock":
 
  203                $this->in_questionblock = 
true;
 
  204                $this->questionblock = array();
 
  205                $this->questionblocktitle = 
"";
 
  206                $this->showQuestiontext = 1;
 
  207                foreach ($a_attribs as 
$attrib => $value) {
 
  209                        case "showQuestiontext":
 
  210                            $this->showQuestiontext = $value;
 
  215            case "surveyquestions":
 
  216                foreach ($a_attribs as 
$attrib => $value) {
 
  219                            if ($this->spl_id > 0) {
 
  220                                include_once 
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
 
  222                                $spl->setOnline($value);
 
  230                $this->in_survey = 
true;
 
  231                foreach ($a_attribs as 
$attrib => $value) {
 
  234                            if (is_object($this->survey)) {
 
  235                                $this->survey->setTitle($value);
 
  236                                $this->survey->update(
true);
 
  242            case "anonymisation":
 
  243                foreach ($a_attribs as 
$attrib => $value) {
 
  246                            $this->anonymisation = $value;
 
  252                foreach ($a_attribs as 
$attrib => $value) {
 
  255                            $this->surveyaccess = $value;
 
  264                        "sourceref" => $a_attribs[
"sourceref"],
 
  265                        "destref" => $a_attribs[
"destref"],
 
  266                        "relation" => $a_attribs[
"relation"],
 
  267                        "value" => $a_attribs[
"value"],
 
  270                        "conjunction" => (
int) $a_attribs[
"conjuction"]
 
  276                $type = $a_attribs[
"type"];
 
  279                    case 'SurveyNominalQuestion':
 
  280                        $type = 
'SurveyMultipleChoiceQuestion';
 
  281                        foreach ($a_attribs as 
$key => $value) {
 
  285                                        $type = 
'SurveySingleChoiceQuestion';
 
  287                                        $type = 
'SurveyMultipleChoiceQuestion';
 
  293                    case 'SurveyOrdinalQuestion':
 
  294                        $type = 
'SurveySingleChoiceQuestion';
 
  298                    include_once 
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
 
  300                        $this->activequestion = 
new $type();
 
  303                        $q_obj_id = $this->spl_id;
 
  304                        if ($this->spl_id < 0) {
 
  305                            $q_obj_id = $this->survey->getId();
 
  308                        $this->activequestion->setObjId($q_obj_id);
 
  311                    $this->activequestion = 
null;
 
  313                $this->original_question_id = $a_attribs[
"id"];
 
  314                if ($this->in_questionblock) {
 
  315                    array_push($this->questionblock, $this->original_question_id);
 
  317                if (is_object($this->activequestion)) {
 
  318                    foreach ($a_attribs as 
$key => $value) {
 
  321                                $this->activequestion->setTitle($value);
 
  324                                $this->activequestion->setSubtype($value);
 
  327                                $this->activequestion->setObligatory($value);
 
  334                switch ($this->
getParent($a_xml_parser)) {
 
  337                        $this->material = array();
 
  340                array_push($this->material, array(
"text" => 
"", 
"image" => 
"", 
"label" => $a_attribs[
"label"]));
 
  344                    if (array_key_exists(
"label", $a_attribs)) {
 
  345                        if (preg_match(
"/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs[
"label"], $matches)) {
 
  347                            if (!is_array(
$_SESSION[
"import_mob_xhtml"])) {
 
  350                            array_push(
$_SESSION[
"import_mob_xhtml"], array(
"mob" => $a_attribs[
"label"], 
"uri" => $a_attribs[
"uri"], 
"type" => $a_attribs[
"type"], 
"id" => $a_attribs[
"id"]));
 
  355                $this->metadata = array();
 
  357            case "metadatafield":
 
  358                array_push($this->metadata, array(
"label" => 
"", 
"entry" => 
""));
 
  361                $this->is_matrix = 
true;
 
  362                $this->matrix = array();
 
  365                $this->material = array();
 
  366                array_push($this->matrix, 
"");
 
  367                $this->matrixrowattribs = array(
"id" => $a_attribs[
"id"], 
"label" => $a_attribs[
"label"], 
"other" => $a_attribs[
"other"]);
 
  370                $this->material = array();
 
  371                $this->responses = array();
 
  374                $this->variables = array();
 
  376            case "response_single":
 
  377                $this->material = array();
 
  378                $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"]);
 
  379                $this->response_id = $a_attribs[
"id"];
 
  381            case "response_multiple":
 
  382                $this->material = array();
 
  383                $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"]);
 
  384                $this->response_id = $a_attribs[
"id"];
 
  386            case "response_text":
 
  387                $this->material = array();
 
  388                $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"]);
 
  389                $this->response_id = $a_attribs[
"id"];
 
  392                $this->material = array();
 
  393                $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"]);
 
  394                $this->response_id = $a_attribs[
"id"];
 
  396            case "response_time":
 
  397                $this->material = array();
 
  398                $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"]);
 
  399                $this->response_id = $a_attribs[
"id"];
 
  401            case "bipolar_adjectives":
 
  402                $this->adjectives = array();
 
  405                array_push($this->adjectives, array(
"label" => $a_attribs[
"label"], 
"text" => 
""));
 
  416        $this->text_size += strlen($a_data);
 
  417        $this->characterbuffer .= $a_data;
 
  428                if (is_object($this->survey)) {
 
  429                    $this->survey->setOfflineStatus(!$this->survey_status);
 
  430                    $this->survey->saveToDb();
 
  433                    if (count($this->questionblocks)) {
 
  434                        foreach ($this->questionblocks as 
$data) {
 
  439                                array_push($qblock, $this->questions[$question_id]);
 
  441                            $this->survey->createQuestionblock(
$title, $this->showQuestiontext, 
false, $qblock);
 
  446                    if (count($this->constraints)) {
 
  447                        $relations = $this->survey->getAllRelations(
true);
 
  448                        foreach ($this->constraints as $constraint) {
 
  449                            $constraint_id = $this->survey->addConstraint($this->questions[$constraint[
"destref"]], $relations[$constraint[
"relation"]][
"id"], $constraint[
"value"], $constraint[
"conjunction"]);
 
  450                            $this->survey->addConstraintToQuestion($this->questions[$constraint[
"sourceref"]], $constraint_id);
 
  455                    if (count($this->textblocks)) {
 
  456                        foreach ($this->textblocks as $original_id => 
$textblock) {
 
  457                            $this->survey->saveHeading(
$textblock, $this->questions[$original_id]);
 
  463                $this->in_survey = 
false;
 
  464                if (is_object($this->survey)) {
 
  465                    if (strcmp($this->surveyaccess, 
"free") == 0) {
 
  466                        $this->survey->setAnonymize(2);
 
  468                        if ($this->anonymisation == 0) {
 
  469                            $this->survey->setAnonymize(0);
 
  471                            $this->survey->setAnonymize(1);
 
  477                if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches)) {
 
  478                    if (is_object($this->survey)) {
 
  479                        $this->survey->setStartDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
 
  484                if (preg_match(
"/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*/", $this->characterbuffer, $matches)) {
 
  485                    if (is_object($this->survey)) {
 
  486                        $this->survey->setEndDate(sprintf(
"%04d%02d%02d%02d%02d%02d", $matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]));
 
  491                if ($this->in_survey) {
 
  492                    if (is_object($this->survey)) {
 
  493                        $this->survey->setDescription($this->characterbuffer);
 
  494                        $this->survey->update(
true);
 
  497                    if (is_object($this->activequestion)) {
 
  498                        $this->activequestion->setDescription($this->characterbuffer);
 
  503                if (is_object($this->activequestion)) {
 
  504                    if (strlen($this->textblock)) {
 
  507                    $this->activequestion->saveToDb();
 
  509                    if (is_object($this->survey) &&
 
  511                        $question_id = $this->activequestion->duplicate(
true, 
"", 
"", 
"", $this->survey->getId());
 
  513                        $question_id = $this->activequestion->getId();
 
  515                    if (is_object($this->survey)) { 
 
  516                        $this->survey->addQuestion($question_id);
 
  519                    if ($this->mapping) {
 
  520                        $this->mapping->addMapping(
"Modules/Survey", 
"svy_q", $this->original_question_id, $question_id);
 
  522                    $this->activequestion = 
null;
 
  524                $this->textblock = 
"";
 
  527                if ($this->in_survey) {
 
  528                    if (is_object($this->survey)) {
 
  529                        $this->survey->setAuthor($this->characterbuffer);
 
  532                    if (is_object($this->activequestion)) {
 
  533                        $this->activequestion->setAuthor($this->characterbuffer);
 
  544                if ($this->in_survey) {
 
  545                    if (strcmp($this->
getParent($a_xml_parser), 
"objectives") == 0) {
 
  546                        if (strcmp($this->material[0][
"label"], 
"introduction") == 0) {
 
  547                            if (is_object($this->survey)) {
 
  548                                $this->survey->setIntroduction($this->material[0][
"text"]);
 
  551                        if (strcmp($this->material[0][
"label"], 
"outro") == 0) {
 
  552                            if (is_object($this->survey)) {
 
  553                                $this->survey->setOutro($this->material[0][
"text"]);
 
  556                        $this->material = array();
 
  559                    if (strcmp($this->
getParent($a_xml_parser), 
"question") == 0) {
 
  560                        $this->activequestion->setMaterial($this->material[0][
"text"], 
true, $this->material[0][
"label"]);
 
  565                if (is_object($this->activequestion)) {
 
  567                    foreach ($this->material as $matarray) {
 
  568                        $questiontext .= $matarray[
"text"];
 
  570                    $this->activequestion->setQuestiontext($questiontext);
 
  572                $this->material = array();
 
  581                if (strcmp($this->
getParent($a_xml_parser), 
"question") == 0) {
 
  582                    if (is_object($this->activequestion)) {
 
  583                        $this->activequestion->importAdditionalMetadata($this->metadata);
 
  586                if (strcmp($this->
getParent($a_xml_parser), 
"survey") == 0) {
 
  587                    foreach ($this->metadata as 
$key => $value) {
 
  588                        switch ($value[
"label"]) {
 
  590                                if (strlen($value[
"entry"])) {
 
  591                                    if (is_object($this->survey)) {
 
  592                                        include_once 
"./Services/MetaData/classes/class.ilMDSaxParser.php";
 
  593                                        include_once 
"./Services/MetaData/classes/class.ilMD.php";
 
  595                                        $md_sax_parser->setXMLContent($value[
"entry"]);
 
  596                                        $md_sax_parser->setMDObject($tmp = 
new ilMD($this->survey->getId(), 0, 
"svy"));
 
  597                                        $md_sax_parser->enableMDParsing(
true);
 
  598                                        $md_sax_parser->startParsing();
 
  599                                        $this->survey->MDUpdateListener(
"General");
 
  603                            case "display_question_titles":
 
  604                                if ($value[
"entry"] == 1) {
 
  605                                    $this->survey->showQuestionTitles();
 
  607                                    $this->survey->hideQuestionTitles();
 
  611                                $this->survey_status = $value[
"entry"];
 
  613                            case "evaluation_access":
 
  614                                $this->survey->setEvaluationAccess($value[
"entry"]);
 
  617                                $this->survey->setPoolUsage($value[
"entry"]);
 
  619                            case "own_results_view":
 
  620                                $this->survey->setViewOwnResults($value[
"entry"]);
 
  622                            case "own_results_mail":
 
  623                                $this->survey->setMailOwnResults($value[
"entry"]);
 
  625                            case "confirmation_mail":
 
  626                                $this->survey->setMailConfirmation($value[
"entry"]);
 
  628                            case "anon_user_list":
 
  629                                $this->survey->setAnonymousUserList($value[
"entry"]);
 
  632                                $this->survey->setMode($value[
"entry"]);
 
  634                            case "mode_360_self_eval":
 
  635                                $this->survey->set360SelfEvaluation($value[
"entry"]);
 
  637                            case "mode_360_self_rate":
 
  638                                $this->survey->set360SelfRaters($value[
"entry"]);
 
  640                            case "mode_360_self_appr":
 
  641                                $this->survey->set360SelfAppraisee($value[
"entry"]);
 
  643                            case "mode_360_results":
 
  644                                $this->survey->set360Results($value[
"entry"]);
 
  646                            case "mode_self_eval_results":
 
  647                                $this->survey->setSelfEvaluationResults($value[
"entry"]);
 
  649                            case "mode_skill_service":
 
  650                                $this->survey->setSkillService($value[
"entry"]);
 
  655                if (!$this->spl_exists) {
 
  656                    if (strcmp($this->
getParent($a_xml_parser), 
"surveyquestions") == 0) {
 
  657                        foreach ($this->metadata as 
$key => $value) {
 
  658                            if (strcmp($value[
"label"], 
"SCORM") == 0) {
 
  659                                if (strlen($value[
"entry"])) {
 
  660                                    if ($this->spl_id > 0) {
 
  661                                        include_once 
"./Services/MetaData/classes/class.ilMDSaxParser.php";
 
  662                                        include_once 
"./Services/MetaData/classes/class.ilMD.php";
 
  663                                        include_once 
"./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
 
  665                                        $md_sax_parser->setXMLContent($value[
"entry"]);
 
  666                                        $md_sax_parser->setMDObject($tmp = 
new ilMD($this->spl_id, 0, 
"spl"));
 
  667                                        $md_sax_parser->enableMDParsing(
true);
 
  668                                        $md_sax_parser->startParsing();
 
  670                                        $spl->MDUpdateListener(
"General");
 
  679                if (is_object($this->activequestion)) {
 
  680                    $this->activequestion->importResponses($this->responses);
 
  682                $this->is_matrix = 
false;
 
  685                array_push($this->variables, $this->characterbuffer);
 
  688                if (is_object($this->activequestion)) {
 
  689                    $this->activequestion->importVariables($this->variables);
 
  692            case "response_single":
 
  693            case "response_multiple":
 
  694            case "response_text":
 
  696            case "response_time":
 
  702            case "bipolar_adjectives":
 
  703                if (is_object($this->activequestion)) {
 
  704                    $this->activequestion->importAdjectives($this->adjectives);
 
  712                $this->matrix[count($this->matrix) - 1] = array(
'title' => 
$row, 
'id' => $this->matrixrowattribs[
'id'], 
'label' => $this->matrixrowattribs[
'label'], 
'other' => $this->matrixrowattribs[
'other']);
 
  715                if (is_object($this->activequestion)) {
 
  716                    $this->activequestion->importMatrix($this->matrix);
 
  722            case "questionblocktitle":
 
  725            case "questionblock":
 
  726                $this->in_questionblock = 
false;
 
  727                array_push($this->questionblocks, array(
"title" => $this->questionblocktitle, 
"questions" => $this->questionblock));
 
  730        $this->depth[$a_xml_parser]--;
 
  755        return "Error: " . $this->error_msg . 
" at line:" . $this->error_line . 
" column:" . 
$this->error_col;
 
$attrib
Regular expression to match HTML/XML attribute pairs within a tag.
An exception for terminatinating execution or to throw for unit testing.
Survey Question Import Parser.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
startParsing()
start the parser
parse($a_xml_parser, $a_fp=null)
parse xml file
setSurveyObject($a_svy)
Sets a reference to a survey object @access public.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
__construct($a_spl_id, $a_xml_file='', $spl_exists=false, $a_mapping=null)
Constructor.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...