Survey Question Import Parser. More...
Inheritance diagram for SurveyImportParser:
Collaboration diagram for SurveyImportParser:Survey Question Import Parser.
Definition at line 35 of file class.SurveyImportParser.php.
| SurveyImportParser::getErrorCode | ( | ) |
Definition at line 699 of file class.SurveyImportParser.php.
{
return $this->error_code;
}
| SurveyImportParser::getErrorColumn | ( | ) |
Definition at line 709 of file class.SurveyImportParser.php.
{
return $this->error_col;
}
| SurveyImportParser::getErrorLine | ( | ) |
Definition at line 704 of file class.SurveyImportParser.php.
{
return $this->error_line;
}
| SurveyImportParser::getErrorMessage | ( | ) |
Definition at line 714 of file class.SurveyImportParser.php.
{
return $this->error_msg;
}
| SurveyImportParser::getFullError | ( | ) |
Definition at line 719 of file class.SurveyImportParser.php.
{
return "Error: ".$this->error_msg." at line:".$this->error_line ." column:".$this->error_col;
}
| SurveyImportParser::getParent | ( | $ | a_xml_parser | ) |
Definition at line 178 of file class.SurveyImportParser.php.
Referenced by handlerBeginTag(), and handlerEndTag().
{
if ($this->depth[$a_xml_parser] > 0)
{
return $this->path[$this->depth[$a_xml_parser]-1];
}
else
{
return "";
}
}
Here is the caller graph for this function:| SurveyImportParser::getXMLAttributes | ( | ) |
Definition at line 734 of file class.SurveyImportParser.php.
{
return $this->attributes;
}
| SurveyImportParser::getXMLElements | ( | ) |
Definition at line 729 of file class.SurveyImportParser.php.
{
return $this->elements;
}
| SurveyImportParser::getXMLSize | ( | ) |
Definition at line 724 of file class.SurveyImportParser.php.
{
return $this->size;
}
| SurveyImportParser::getXMLTextSections | ( | ) |
Definition at line 739 of file class.SurveyImportParser.php.
{
return $this->texts;
}
| SurveyImportParser::getXMLTextSize | ( | ) |
Definition at line 744 of file class.SurveyImportParser.php.
{
return $this->text_size;
}
| SurveyImportParser::handlerBeginTag | ( | $ | a_xml_parser, | |
| $ | a_name, | |||
| $ | a_attribs | |||
| ) |
handler for begin of element
Definition at line 193 of file class.SurveyImportParser.php.
References $_SESSION, $attrib, and getParent().
{
$this->depth[$a_xml_parser]++;
$this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
$this->characterbuffer = "";
$this->activetag = $a_name;
$this->elements++;
$this->attributes+=count($a_attribs);
switch ($a_name)
{
case "questionblock":
$this->in_questionblock = TRUE;
$this->questionblock = array();
$this->questionblocktitle = "";
$this->showQuestiontext = 1;
foreach ($a_attribs as $attrib => $value)
{
switch ($attrib)
{
case "showQuestiontext":
$this->showQuestiontext = $value;
break;
}
}
break;
case "survey":
$this->in_survey = TRUE;
foreach ($a_attribs as $attrib => $value)
{
switch ($attrib)
{
case "title":
if (is_object($this->survey))
{
$this->survey->setTitle($value);
}
break;
}
}
break;
case "anonymisation":
foreach ($a_attribs as $attrib => $value)
{
switch ($attrib)
{
case "enabled":
$this->anonymisation = $value;
break;
}
}
break;
case "access":
foreach ($a_attribs as $attrib => $value)
{
switch ($attrib)
{
case "type":
$this->surveyaccess = $value;
break;
}
}
break;
case "constraint":
array_push($this->constraints,
array(
"sourceref" => $a_attribs["sourceref"],
"destref" => $a_attribs["destref"],
"relation" => $a_attribs["relation"],
"value" => $a_attribs["value"]
)
);
break;
case "question":
// start with a new survey question
$type = $a_attribs["type"];
if (strlen($type))
{
include_once "./Modules/SurveyQuestionPool/classes/class.$type.php";
$this->activequestion = new $type();
$this->activequestion->setObjId($this->spl->getId());
}
else
{
$this->activequestion = NULL;
}
$this->original_question_id = $a_attribs["id"];
if ($this->in_questionblock)
{
array_push($this->questionblock, $this->original_question_id);
}
if (is_object($this->activequestion))
{
foreach ($a_attribs as $key => $value)
{
switch ($key)
{
case "title":
$this->activequestion->setTitle($value);
break;
case "subtype":
$this->activequestion->setSubtype($value);
break;
case "obligatory":
$this->activequestion->setObligatory($value);
break;
}
}
}
break;
case "material":
switch ($this->getParent($a_xml_parser))
{
case "question":
case "questiontext":
$this->material = array();
break;
}
array_push($this->material, array("text" => "", "image" => "", "label" => $a_attribs["label"]));
break;
case "matimage":
case "label":
if (array_key_exists("label", $a_attribs))
{
if (preg_match("/(il_([0-9]+)_mob_([0-9]+))/", $a_attribs["label"], $matches))
{
// import an mediaobject which was inserted using tiny mce
if (!is_array($_SESSION["import_mob_xhtml"])) $_SESSION["import_mob_xhtml"] = array();
array_push($_SESSION["import_mob_xhtml"], array("mob" => $a_attribs["label"], "uri" => $a_attribs["uri"]));
}
}
break;
case "metadata":
$this->metadata = array();
break;
case "metadatafield":
array_push($this->metadata, array("label" => "", "entry" => ""));
break;
case "matrix":
$this->is_matrix = TRUE;
$this->matrix = array();
break;
case "matrixrow":
$this->material = array();
array_push($this->matrix, "");
break;
case "responses":
$this->material = array();
$this->responses = array();
break;
case "response_single":
$this->material = array();
$this->responses[$a_attribs["id"]] = array("type" => "single", "id" => $a_attribs["id"], "label" => $a_attribs["label"]);
$this->response_id = $a_attribs["id"];
break;
case "response_multiple":
$this->material = array();
$this->responses[$a_attribs["id"]] = array("type" => "multiple", "id" => $a_attribs["id"], "label" => $a_attribs["label"]);
$this->response_id = $a_attribs["id"];
break;
case "response_text":
$this->material = array();
$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"]);
$this->response_id = $a_attribs["id"];
break;
case "response_num":
$this->material = array();
$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"]);
$this->response_id = $a_attribs["id"];
break;
case "response_time":
$this->material = array();
$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"]);
$this->response_id = $a_attribs["id"];
break;
case "bipolar_adjectives":
$this->adjectives = array();
break;
case "adjective":
array_push($this->adjectives, array("label" => $a_attribs["label"], "text" => ""));
break;
}
}
Here is the call graph for this function:| SurveyImportParser::handlerCharacterData | ( | $ | a_xml_parser, | |
| $ | a_data | |||
| ) |
handler for character data
Definition at line 379 of file class.SurveyImportParser.php.
{
$this->texts++;
$this->text_size+=strlen($a_data);
$this->characterbuffer .= $a_data;
$a_data = $this->characterbuffer;
}
| SurveyImportParser::handlerEndTag | ( | $ | a_xml_parser, | |
| $ | a_name | |||
| ) |
handler for end of element
Definition at line 390 of file class.SurveyImportParser.php.
References $data, $material, $questionblock, $textblock, $title, and getParent().
{
switch ($a_name)
{
case "surveyobject":
if (is_object($this->survey))
{
// write constraints
if (count($this->constraints))
{
$relations = $this->survey->getAllRelations(TRUE);
foreach ($this->constraints as $constraint)
{
$this->survey->addConstraint($this->questions[$constraint["sourceref"]], $this->questions[$constraint["destref"]], $relations[$constraint["relation"]]["id"], $constraint["value"]);
}
}
// write question blocks
if (count($this->questionblocks))
{
foreach ($this->questionblocks as $data)
{
$questionblock = $data["questions"];
$title = $data["title"];
$qblock = array();
foreach ($questionblock as $question_id)
{
array_push($qblock, $this->questions[$question_id]);
}
$this->survey->createQuestionblock($title, $this->showQuestiontext, $qblock);
}
}
$this->survey->saveToDb();
// write textblocks
if (count($this->textblocks))
{
foreach ($this->textblocks as $original_id => $textblock)
{
$this->survey->saveHeading($textblock, $this->questions[$original_id]);
}
}
}
break;
case "survey":
$this->in_survey = FALSE;
if (is_object($this->survey))
{
if (strcmp($this->surveyaccess, "free") == 0)
{
$this->survey->setAnonymize(2);
}
else
{
if ($this->anonymisation == 0)
{
$this->survey->setAnonymize(0);
}
else
{
$this->survey->setAnonymize(1);
}
}
}
break;
case "startingtime":
if (preg_match("/(\d{4}-\d{2}-\d{2})T\d{2}-\d{2}-\d{2}.*/", $this->characterbuffer, $matches))
{
if (is_object($this->survey))
{
$this->survey->setStartDate($matches[1]);
$this->survey->setStartDateEnabled(1);
}
}
break;
case "endingtime":
if (preg_match("/(\d{4}-\d{2}-\d{2})T\d{2}-\d{2}-\d{2}.*/", $this->characterbuffer, $matches))
{
if (is_object($this->survey))
{
$this->survey->setEndDate($matches[1]);
$this->survey->setEndDateEnabled(1);
}
}
break;
case "description":
if ($this->in_survey)
{
if (is_object($this->survey))
{
$this->survey->setDescription($this->characterbuffer);
}
}
else
{
if (is_object($this->activequestion))
{
$this->activequestion->setDescription($this->characterbuffer);
}
}
break;
case "question":
if (is_object($this->activequestion))
{
if (strlen($this->textblock))
{
$this->textblocks[$this->original_question_id] = $this->textblock;
}
$this->activequestion->saveToDb();
if (is_object($this->survey))
{
// duplicate the question for the survey
$question_id = $this->activequestion->duplicate(TRUE);
$this->survey->addQuestion($question_id);
$this->questions[$this->original_question_id] = $question_id;
}
$this->activequestion = NULL;
}
$this->textblock = "";
break;
case "author":
if ($this->in_survey)
{
if (is_object($this->survey))
{
$this->survey->setAuthor($this->characterbuffer);
}
}
else
{
if (is_object($this->activequestion))
{
$this->activequestion->setAuthor($this->characterbuffer);
}
}
break;
case "mattext":
$this->material[count($this->material)-1]["text"] = $this->characterbuffer;
break;
case "matimage":
$this->material[count($this->material)-1]["image"] = $this->characterbuffer;
break;
case "material":
if ($this->in_survey)
{
if (strcmp($this->getParent($a_xml_parser), "objectives") == 0)
{
if (strcmp($this->material[0]["label"], "introduction") == 0)
{
if (is_object($this->survey))
{
$this->survey->setIntroduction($this->material[0]["text"]);
}
}
if (strcmp($this->material[0]["label"], "outro") == 0)
{
if (is_object($this->survey))
{
$this->survey->setOutro($this->material[0]["text"]);
}
}
$this->material = array();
}
}
else
{
if (strcmp($this->getParent($a_xml_parser), "question") == 0)
{
$this->activequestion->setMaterial($this->material[0]["text"], TRUE, $this->material[0]["label"]);
}
}
break;
case "questiontext":
if (is_object($this->activequestion))
{
$questiontext = "";
foreach ($this->material as $matarray)
{
$questiontext .= $matarray["text"];
}
$this->activequestion->setQuestiontext($questiontext);
}
$this->material = array();
break;
case "fieldlabel":
$this->metadata[count($this->metadata)-1]["label"] = $this->characterbuffer;
break;
case "fieldentry":
$this->metadata[count($this->metadata)-1]["entry"] = $this->characterbuffer;
break;
case "metadata":
if (strcmp($this->getParent($a_xml_parser), "question") == 0)
{
if (is_object($this->activequestion))
{
$this->activequestion->importAdditionalMetadata($this->metadata);
}
}
if (strcmp($this->getParent($a_xml_parser), "survey") == 0)
{
foreach ($this->metadata as $key => $value)
{
switch ($value["label"])
{
case "SCORM":
if (strlen($value["entry"]))
{
if (is_object($this->survey))
{
include_once "./Services/MetaData/classes/class.ilMDSaxParser.php";
include_once "./Services/MetaData/classes/class.ilMD.php";
$md_sax_parser = new ilMDSaxParser();
$md_sax_parser->setXMLContent($value["entry"]);
$md_sax_parser->setMDObject($tmp = new ilMD($this->survey->getId(),0, "svy"));
$md_sax_parser->enableMDParsing(true);
$md_sax_parser->startParsing();
$this->survey->MDUpdateListener("General");
}
}
break;
case "display_question_titles":
if ($value["entry"] == 1)
{
$this->survey->showQuestionTitles();
}
break;
case "status":
$this->survey->setStatus($value["entry"]);
break;
case "evaluation_access":
$this->survey->setEvaluationAccess($value["entry"]);
break;
}
}
}
if (!$this->spl_exists)
{
if (strcmp($this->getParent($a_xml_parser), "surveyquestions") == 0)
{
foreach ($this->metadata as $key => $value)
{
if (strcmp($value["label"], "SCORM") == 0)
{
if (strlen($value["entry"]))
{
include_once "./Services/MetaData/classes/class.ilMDSaxParser.php";
include_once "./Services/MetaData/classes/class.ilMD.php";
$md_sax_parser = new ilMDSaxParser();
$md_sax_parser->setXMLContent($value["entry"]);
$md_sax_parser->setMDObject($tmp = new ilMD($this->spl->getId(),0, "spl"));
$md_sax_parser->enableMDParsing(true);
$md_sax_parser->startParsing();
$this->spl->MDUpdateListener("General");
}
}
}
}
}
break;
case "responses":
if (is_object($this->activequestion))
{
$this->activequestion->importResponses($this->responses);
}
$this->is_matrix = FALSE;
break;
case "response_single":
case "response_multiple":
case "response_text":
case "response_num":
case "response_time":
$this->responses[$this->response_id]["material"] = $this->material;
break;
case "adjective":
$this->adjectives[count($this->adjectives)-1]["text"] = $this->characterbuffer;
break;
case "bipolar_adjectives":
if (is_object($this->activequestion))
{
$this->activequestion->importAdjectives($this->adjectives);
}
break;
case "matrixrow":
$row = "";
foreach ($this->material as $material)
{
$row .= $material["text"];
}
$this->matrix[count($this->matrix)-1] = $row;
break;
case "matrix":
if (is_object($this->activequestion))
{
$this->activequestion->importMatrix($this->matrix);
}
break;
case "textblock":
$this->textblock = $this->characterbuffer;
break;
case "questionblocktitle":
$this->questionblocktitle = $this->characterbuffer;
break;
case "questionblock":
$this->in_questionblock = FALSE;
array_push($this->questionblocks, array("title" => $this->questionblocktitle, "questions" => $this->questionblock));
break;
}
$this->depth[$a_xml_parser]--;
}
Here is the call graph for this function:| SurveyImportParser::hasError | ( | ) |
Definition at line 749 of file class.SurveyImportParser.php.
{
return $this->has_error;
}
| SurveyImportParser::parse | ( | $ | a_xml_parser, | |
| $ | a_fp = null | |||
| ) |
parse xml file
private
Reimplemented from ilSaxParser.
Definition at line 149 of file class.SurveyImportParser.php.
References $data, ilSaxParser::getInputType(), and ilSaxParser::getXMLContent().
{
switch($this->getInputType())
{
case 'file':
while($data = fread($a_fp,4096))
{
$parseOk = xml_parse($a_xml_parser,$data,feof($a_fp));
}
break;
case 'string':
$parseOk = xml_parse($a_xml_parser,$this->getXMLContent());
break;
}
if(!$parseOk
&& (xml_get_error_code($a_xml_parser) != XML_ERROR_NONE))
{
$this->error_code = xml_get_error_code($a_xml_parser);
$this->error_line = xml_get_current_line_number($a_xml_parser);
$this->error_col = xml_get_current_column_number($a_xml_parser);
$this->error_msg = xml_error_string($a_xml_parser);
$this->has_error = TRUE;
return false;
}
return true;
}
Here is the call graph for this function:| SurveyImportParser::setHandlers | ( | $ | a_xml_parser | ) |
set event handler should be overwritten by inherited class private
Reimplemented from ilSaxParser.
Definition at line 129 of file class.SurveyImportParser.php.
{
xml_set_object($a_xml_parser,$this);
xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
}
| SurveyImportParser::setSurveyObject | ( | &$ | a_svy | ) |
Sets a reference to a survey object public.
Definition at line 119 of file class.SurveyImportParser.php.
{
$this->survey =& $a_svy;
}
| SurveyImportParser::startParsing | ( | ) |
start the parser
Reimplemented from ilSaxParser.
Definition at line 139 of file class.SurveyImportParser.php.
{
parent::startParsing();
}
| SurveyImportParser::SurveyImportParser | ( | &$ | a_spl, | |
| $ | a_xml_file = '', |
|||
| $ | spl_exists = FALSE | |||
| ) |
Constructor.
| string | $a_xml_file xml file |
public
Definition at line 82 of file class.SurveyImportParser.php.
References $spl_exists, and ilSaxParser::ilSaxParser().
{
parent::ilSaxParser($a_xml_file);
$this->spl =& $a_spl;
$this->has_error = FALSE;
$this->characterbuffer = "";
$this->activetag = "";
$this->material = array();
$this->depth = array();
$this->path = array();
$this->metadata = array();
$this->responses = array();
$this->response_id = "";
$this->matrix = array();
$this->is_matrix = FALSE;
$this->adjectives = array();
$this->spl_exists = $spl_exists;
$this->survey = NULL;
$this->in_survey = FALSE;
$this->anonymisation = 0;
$this->surveyaccess = "restricted";
$this->questions = array();
$this->original_question_id = "";
$this->constraints = array();
$this->textblock = "";
$this->textblocks = array();
$this->in_questionblock = FALSE;
$this->questionblocks = array();
$this->questionblock = array();
$this->showQuestiontext = 1;
$this->questionblocktitle = "";
}
Here is the call graph for this function:| SurveyImportParser::$activequestion |
Definition at line 39 of file class.SurveyImportParser.php.
| SurveyImportParser::$activetag |
Definition at line 52 of file class.SurveyImportParser.php.
| SurveyImportParser::$adjectives |
Definition at line 59 of file class.SurveyImportParser.php.
| SurveyImportParser::$anonymisation |
Definition at line 63 of file class.SurveyImportParser.php.
| SurveyImportParser::$attributes |
Definition at line 48 of file class.SurveyImportParser.php.
| SurveyImportParser::$characterbuffer |
Definition at line 51 of file class.SurveyImportParser.php.
| SurveyImportParser::$constraints |
Definition at line 67 of file class.SurveyImportParser.php.
| SurveyImportParser::$depth |
Definition at line 38 of file class.SurveyImportParser.php.
| SurveyImportParser::$elements |
Definition at line 47 of file class.SurveyImportParser.php.
| SurveyImportParser::$error_code |
Definition at line 41 of file class.SurveyImportParser.php.
| SurveyImportParser::$error_col |
Definition at line 43 of file class.SurveyImportParser.php.
| SurveyImportParser::$error_line |
Definition at line 42 of file class.SurveyImportParser.php.
| SurveyImportParser::$error_msg |
Definition at line 44 of file class.SurveyImportParser.php.
| SurveyImportParser::$has_error |
Definition at line 45 of file class.SurveyImportParser.php.
| SurveyImportParser::$in_questionblock |
Definition at line 70 of file class.SurveyImportParser.php.
| SurveyImportParser::$in_survey |
Definition at line 61 of file class.SurveyImportParser.php.
| SurveyImportParser::$is_matrix |
Definition at line 58 of file class.SurveyImportParser.php.
| SurveyImportParser::$material |
Definition at line 53 of file class.SurveyImportParser.php.
Referenced by handlerEndTag().
| SurveyImportParser::$matrix |
Definition at line 57 of file class.SurveyImportParser.php.
| SurveyImportParser::$metadata |
Definition at line 54 of file class.SurveyImportParser.php.
| SurveyImportParser::$original_question_id |
Definition at line 66 of file class.SurveyImportParser.php.
| SurveyImportParser::$path |
Definition at line 37 of file class.SurveyImportParser.php.
| SurveyImportParser::$questionblock |
Definition at line 71 of file class.SurveyImportParser.php.
Referenced by handlerEndTag().
| SurveyImportParser::$questionblocks |
Definition at line 72 of file class.SurveyImportParser.php.
| SurveyImportParser::$questionblocktitle |
Definition at line 73 of file class.SurveyImportParser.php.
| SurveyImportParser::$questions |
Definition at line 65 of file class.SurveyImportParser.php.
| SurveyImportParser::$response_id |
Definition at line 56 of file class.SurveyImportParser.php.
| SurveyImportParser::$responses |
Definition at line 55 of file class.SurveyImportParser.php.
| SurveyImportParser::$size |
Definition at line 46 of file class.SurveyImportParser.php.
| SurveyImportParser::$spl |
Definition at line 40 of file class.SurveyImportParser.php.
| SurveyImportParser::$spl_exists |
Definition at line 60 of file class.SurveyImportParser.php.
Referenced by SurveyImportParser().
| SurveyImportParser::$survey |
Definition at line 62 of file class.SurveyImportParser.php.
| SurveyImportParser::$surveyaccess |
Definition at line 64 of file class.SurveyImportParser.php.
| SurveyImportParser::$text_size |
Definition at line 50 of file class.SurveyImportParser.php.
| SurveyImportParser::$textblock |
Definition at line 68 of file class.SurveyImportParser.php.
Referenced by handlerEndTag().
| SurveyImportParser::$textblocks |
Definition at line 69 of file class.SurveyImportParser.php.
| SurveyImportParser::$texts |
Definition at line 49 of file class.SurveyImportParser.php.
1.7.1