ILIAS  release_8 Revision v8.24
ilQuestionPageParser Class Reference

Legacy Content Object Parser. More...

+ Inheritance diagram for ilQuestionPageParser:
+ Collaboration diagram for ilQuestionPageParser:

Public Member Functions

 __construct (ilObject $a_content_object, string $a_xml_file, string $a_subdir, string $a_import_dir="")
 
 setHandlers ($a_xml_parser)
 
 setImportMapping (ilImportMapping $mapping=null)
 
 startParsing ()
 stores xml data in array More...
 
 storeTree ()
 insert StructureObjects and PageObjects into tree More...
 
 processPagesToParse ()
 parse pages that contain files, mobs and/or internal links More...
 
 copyMobFiles ()
 copy multimedia object files from import zip file to mob directory More...
 
 copyFileItems ()
 copy files of file items More...
 
 setQuestionMapping (array $a_map)
 set question import ident to pool/test question id mapping More...
 
 beginElement (string $a_name)
 
 endElement (string $a_name)
 
 getCurrentElement ()
 
 getOpenCount (string $a_name)
 
 buildTag (string $type, string $name, array $attr=[])
 
 processMeta ()
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 emptyMediaMetaCache ($a_xml_parser)
 
 getGlossaryTermMap ()
 
- Public Member Functions inherited from ilMDSaxParser
 __construct (?string $a_xml_file='')
 
 enableMDParsing (bool $a_status)
 
 getMDParsingStatus ()
 
 setMDObject (ilMD $md)
 
 getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 Set event handlers. More...
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 __getCharacterData ()
 
 __pushParent (object $md_obj)
 
 __popParent ()
 
 __getParent ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

ilTree $tree
 
array $cnt = []
 
array $current_element = []
 
ilObjLearningModule $learning_module = null
 
ilPageObject $page_object = null
 
ilLMPageObject $lm_page_object = null
 
array $structure_objects = []
 
ilObjMediaObject $media_object = null
 
object $current_object = null
 
ilLMTree $lm_tree = null
 
array $pg_into_tree = []
 
array $st_into_tree = []
 
array $container = []
 
bool $in_page_object = false
 
bool $in_meta_data = false
 
bool $in_media_object = false
 
bool $in_file_item = false
 
bool $in_glossary = false
 
bool $in_map_area = false
 
ilObject $content_object = null
 
ilObjGlossary $glossary_object = null
 
ilObjFile $file_item = null
 
array $pages_to_parse = []
 
array $mob_mapping = []
 
array $file_item_mapping = []
 
string $subdir = ""
 
ilMediaItem $media_item = null
 
string $loc_type = ""
 
ilMapArea $map_area = null
 
array $link_targets = []
 
array $qst_mapping = []
 
bool $metadata_parsing_disabled = false
 
bool $in_meta_meta_data = false
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Protected Attributes

bool $in_properties
 
bool $in_glossary_definition = false
 
array $media_meta_cache = []
 
bool $media_meta_start = false
 
array $pg_mapping = []
 
array $mobs_with_int_links = []
 
bool $inside_code = false
 
string $coType = ""
 
string $import_dir = ""
 
array $glossary_term_map = []
 
ilLogger $log
 
ilGlossaryTerm $glossary_term = null
 
ilImportMapping $mapping = null
 
string $cur_qid = ""
 
ilGlossaryDefinition $glossary_definition = null
 
string $chr_data = ""
 
bool $in_media_item = false
 
- Protected Attributes inherited from ilMDSaxParser
bool $md_in_md = false
 
string $md_chr_data = ''
 
ilMDIdentifier $md_ide = null
 
ilMDLanguage $md_lan = null
 
ilMDDescription $md_des = null
 
ilMDLifecycle $md_lif = null
 
ilMDContribute $md_con = null
 
ilMDEntity $md_ent = null
 
ilMDMetaMetadata $md_met = null
 
ilMDTechnical $md_tec = null
 
ilMDFormat $md_for = null
 
ilMDLocation $md_loc = null
 
ilMDRequirement $md_req = null
 
ilMDOrComposite $md_orc = null
 
ilMDEducational $md_edu = null
 
ilMDTypicalAgeRange $md_typ = null
 
ilMDRights $md_rig = null
 
ilMDRelation $md_rel = null
 
ilMDIdentifier_ $md_ide_ = null
 
ilMDAnnotation $md_ann = null
 
ilMDClassification $md_cla = null
 
ilMDTaxonPath $md_taxp = null
 
ilMDTaxon $md_tax = null
 
ilMDKeyword $md_key = null
 
array $md_parent = array()
 
ilMD $md = null
 
ilMDGeneral $md_gen = null
 
ilLogger $meta_log
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 parseLinkTarget (string $identifier)
 Parse a string the get the elements of a link target Return null if the string is not a link target. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ilMDSaxParser
 trimAndStripAttribs (array $attribs)
 
 trimAndStrip (string $input)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Detailed Description

Legacy Content Object Parser.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de
Deprecated:
use COPage dependency to export/import COPages instead

Definition at line 27 of file class.ilQuestionPageParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilQuestionPageParser::__construct ( ilObject  $a_content_object,
string  $a_xml_file,
string  $a_subdir,
string  $a_import_dir = "" 
)

Definition at line 86 of file class.ilQuestionPageParser.php.

91 {
92 global $DIC;
93
94 $this->log = $DIC["ilLog"];
95 $lng = $DIC->language();
96 $tree = $DIC->repositoryTree();
97
98 $this->log = ilLoggerFactory::getLogger('lm');
99
100 $this->import_dir = ($a_import_dir != "")
101 ? $a_import_dir
102 : $a_content_object->getImportDirectory();
103
104 parent::__construct($a_xml_file);
105 $this->cnt = array();
106 $this->current_element = array();
107 $this->structure_objects = array();
108 $this->content_object = $a_content_object;
109 $this->st_into_tree = array();
110 $this->pg_into_tree = array();
111 $this->pages_to_parse = array();
112 $this->mobs_with_int_links = array();
113 $this->mob_mapping = array();
114 $this->file_item_mapping = array();
115 $this->pg_mapping = array();
116 $this->link_targets = array();
117 $this->subdir = $a_subdir;
118 $this->lng = $lng;
119 $this->tree = $tree;
120 $this->inside_code = false;
121 $this->qst_mapping = array();
122 $this->coType = $this->content_object->getType();
123 $this->metadata_parsing_disabled = false;
124
125 if (($this->coType != "tst") && ($this->coType != "qpl")) {
126 $this->lm_tree = new ilLMTree($this->content_object->getId());
127 }
128 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
ilLanguage $lng
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $DIC, ilSaxParser\$lng, $tree, ILIAS\GlobalScreen\Provider\__construct(), ilLoggerFactory\getLogger(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ beginElement()

ilQuestionPageParser::beginElement ( string  $a_name)

Definition at line 359 of file class.ilQuestionPageParser.php.

359 : void
360 {
361 if (!isset($this->status["$a_name"])) {
362 $this->cnt[$a_name] = 1;
363 } else {
364 $this->cnt[$a_name]++;
365 }
366 $this->current_element[count($this->current_element)] = $a_name;
367 }

◆ buildTag()

ilQuestionPageParser::buildTag ( string  $type,
string  $name,
array  $attr = [] 
)

Definition at line 388 of file class.ilQuestionPageParser.php.

392 : string {
393 $tag = "<";
394
395 if ($type == "end") {
396 $tag .= "/";
397 }
398
399 $tag .= $name;
400
401 if (is_array($attr)) {
402 foreach ($attr as $k => $v) {
403 $tag .= " " . $k . "=\"$v\"";
404 }
405 }
406
407 $tag .= ">";
408
409 return $tag;
410 }
if($format !==null) $name
Definition: metadata.php:247
$type

◆ copyFileItems()

ilQuestionPageParser::copyFileItems ( )

copy files of file items

Definition at line 327 of file class.ilQuestionPageParser.php.

327 : void
328 {
329 $imp_dir = $this->import_dir;
330 foreach ($this->file_item_mapping as $origin_id => $file_id) {
331 if (empty($origin_id)) {
332 continue;
333 }
334 $obj_dir = $origin_id;
335 $source_dir = $imp_dir . "/" . $this->subdir . "/objects/" . $obj_dir;
336
337 $file_obj = new ilObjFile($file_id, false);
338 if (is_dir($source_dir)) {
339 $files = scandir($source_dir, SCANDIR_SORT_DESCENDING);
340 if ($files !== false && $files !== [] && is_file($source_dir . '/' . $files[0])) {
341 $file = fopen($source_dir . '/' . $files[0], 'rb');
342 $file_stream = Streams::ofResource($file);
343 $file_obj->appendStream($file_stream, $files[0]);
344 }
345 }
346 $file_obj->update();
347 }
348 }
Class ilObjFile.

References $import_dir.

Referenced by startParsing().

+ Here is the caller graph for this function:

◆ copyMobFiles()

ilQuestionPageParser::copyMobFiles ( )

copy multimedia object files from import zip file to mob directory

Definition at line 301 of file class.ilQuestionPageParser.php.

301 : void
302 {
303 $imp_dir = $this->import_dir;
304 foreach ($this->mob_mapping as $origin_id => $mob_id) {
305 if (empty($origin_id)) {
306 continue;
307 }
308
309 $obj_dir = $origin_id;
310 $source_dir = $imp_dir . "/" . $this->subdir . "/objects/" . $obj_dir;
311 $target_dir = ilFileUtils::getWebspaceDir() . "/mobs/mm_" . $mob_id;
312
313 if (is_dir($source_dir)) {
314 ilFileUtils::makeDir($target_dir);
315
316 if (is_dir($target_dir)) {
317 ilLoggerFactory::getLogger("mob")->debug("s:-$source_dir-,t:-$target_dir-");
318 ilFileUtils::rCopy(realpath($source_dir), realpath($target_dir));
319 }
320 }
321 }
322 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

References $import_dir, ilLoggerFactory\getLogger(), ilFileUtils\getWebspaceDir(), ilFileUtils\makeDir(), and ilFileUtils\rCopy().

Referenced by startParsing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emptyMediaMetaCache()

ilQuestionPageParser::emptyMediaMetaCache (   $a_xml_parser)
Parameters
resource$a_xml_parser

Definition at line 1373 of file class.ilQuestionPageParser.php.

1373 : void
1374 {
1375 foreach ($this->media_meta_cache as $cache_entry) {
1376 switch ($cache_entry["type"]) {
1377 case "handlerBeginTag":
1378 parent::handlerBeginTag(
1379 $a_xml_parser,
1380 $cache_entry["par1"],
1381 $cache_entry["par2"]
1382 );
1383 break;
1384
1385 case "handlerEndTag":
1386 parent::handlerEndTag(
1387 $a_xml_parser,
1388 $cache_entry["par1"]
1389 );
1390 break;
1391
1392 case "handlerCharacterData":
1393 parent::handlerCharacterData(
1394 $a_xml_parser,
1395 $cache_entry["par1"]
1396 );
1397 break;
1398 }
1399 }
1400
1401 $this->media_meta_start = false;
1402 $this->media_meta_cache[] = array();
1403 }

◆ endElement()

ilQuestionPageParser::endElement ( string  $a_name)

Definition at line 369 of file class.ilQuestionPageParser.php.

369 : void
370 {
371 $this->cnt[$a_name]--;
372 unset($this->current_element[count($this->current_element) - 1]);
373 }

◆ getCurrentElement()

ilQuestionPageParser::getCurrentElement ( )

Definition at line 375 of file class.ilQuestionPageParser.php.

375 : string
376 {
377 return ($this->current_element[count($this->current_element) - 1] ?? "");
378 }

◆ getGlossaryTermMap()

ilQuestionPageParser::getGlossaryTermMap ( )
Returns
mixed[]

Definition at line 1408 of file class.ilQuestionPageParser.php.

1408 : array
1409 {
1411 }

◆ getOpenCount()

ilQuestionPageParser::getOpenCount ( string  $a_name)

Definition at line 380 of file class.ilQuestionPageParser.php.

380 : int
381 {
382 if (isset($this->cnt[$a_name])) {
383 return $this->cnt[$a_name];
384 }
385 return 0;
386 }

◆ handlerCharacterData()

ilQuestionPageParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 1318 of file class.ilQuestionPageParser.php.

1318 : void
1319 {
1320 // call meta data handler
1321 if ($this->in_meta_data && $this->processMeta()) {
1322 // cache beginning of meta data within media object tags
1323 // (we need to know the id, after that we send the cached data
1324 // to the meta xml handler)
1325 if ($this->in_media_object && $this->media_meta_start) {
1326 $this->media_meta_cache[] =
1327 array("type" => "handlerCharacterData", "par1" => $a_data);
1328 } else {
1329 parent::handlerCharacterData($a_xml_parser, $a_data);
1330 }
1331 }
1332
1333 // the parser converts "&gt;" to ">" and "&lt;" to "<"
1334 // in character data, but we don't want that, because it's the
1335 // way we mask user html in our content, so we convert back...
1336
1337 $a_data = str_replace("<", "&lt;", $a_data);
1338 $a_data = str_replace(">", "&gt;", $a_data);
1339
1340
1341 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
1342 $a_data = preg_replace("/\n/", "", $a_data);
1343 if (!$this->inside_code) {
1344 $a_data = preg_replace("/\t+/", "", $a_data);
1345 }
1346
1347 $this->chr_data .= $a_data;
1348
1349 if (!empty($a_data) || $a_data === "0") {
1350 // append all data to page, if we are within PageObject,
1351 // but not within MetaData or MediaObject
1352 if (($this->in_page_object || $this->in_glossary_definition)
1353 && !$this->in_meta_data && !$this->in_media_object) {
1354 $this->page_object->appendXMLContent($a_data);
1355 }
1356
1357 switch ($this->getCurrentElement()) {
1358
1359 case "IntLink":
1360 case "ExtLink":
1361 if ($this->in_map_area) {
1362 $this->map_area->appendTitle($a_data);
1363 }
1364 break;
1365
1366 }
1367 }
1368 }

◆ handlerEndTag()

ilQuestionPageParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 904 of file class.ilQuestionPageParser.php.

904 : void
905 {
906 // call meta data handler
907 if ($this->in_meta_data && $this->processMeta()) {
908 // cache beginning of meta data within media object tags
909 // (we need to know the id, after that we send the cached data
910 // to the meta xml handler)
911 if ($this->in_media_object && $this->media_meta_start) {
912 $this->media_meta_cache[] =
913 array("type" => "handlerEndTag", "par1" => $a_name);
914 } else {
915 parent::handlerEndTag($a_xml_parser, $a_name);
916 }
917 }
918
919 // append content to page xml content
920 if (($this->in_page_object || $this->in_glossary_definition)
921 && !$this->in_meta_data && !$this->in_media_object) {
922 $app_name = ($a_name == "Definition")
923 ? "PageObject"
924 : $a_name;
925 $this->page_object->appendXMLContent($this->buildTag("end", $app_name));
926 }
927
928 switch ($a_name) {
929 case "StructureObject":
930 unset($this->structure_objects[count($this->structure_objects) - 1]);
931 break;
932
933 case "PageObject":
934
935 $this->in_page_object = false;
936 if (($this->coType != "tst") && ($this->coType != "qpl")) {
937 //if (!$this->lm_page_object->isAlias()) {
938 $this->page_object->updateFromXML();
939 $this->pg_mapping[$this->lm_page_object->getImportId()]
940 = $this->lm_page_object->getId();
941
942 if ($this->mapping instanceof ilImportMapping) {
943 $import_id_parsed = ilUtil::parseImportId($this->lm_page_object->getImportId());
944 if ($import_id_parsed['type'] == 'pg') {
945 $this->mapping->addMapping(
946 'Modules/LearningModule',
947 'pg',
948 $import_id_parsed['id'],
949 $this->lm_page_object->getId()
950 );
951 }
952 }
953
954 // collect pages with internal links
955 if ($this->page_object->containsIntLink()) {
956 $this->pages_to_parse["lm:" . $this->page_object->getId()] = "lm:" . $this->page_object->getId();
957 }
958
959 // collect pages with mobs or files
960 if ($this->page_object->needsImportParsing()) {
961 $this->pages_to_parse["lm:" . $this->page_object->getId()] = "lm:" . $this->page_object->getId();
962 }
963
964 // collect pages with questions
965 if ($this->page_object->getContainsQuestion()) {
966 $this->pages_to_parse["lm:" . $this->page_object->getId()] = "lm:" . $this->page_object->getId();
967 }
968 //}
969 } else {
970 $xml = $this->page_object->getXMLContent();
971 if ($this->cur_qid != "") {
972 $ids = $this->qst_mapping[$this->cur_qid] ?? ['pool' => 0, 'test' => 0];
973 if ($ids["pool"] > 0) {
974 // question pool question
975 $page = new ilAssQuestionPage($ids["pool"]);
976 $xmlcontent = str_replace(
977 $this->cur_qid,
978 "il__qst_" . $ids["pool"],
979 $xml
980 );
981 $page->setXMLContent($xmlcontent);
982 $page->updateFromXML();
983 if ($this->page_object->needsImportParsing()) {
984 $this->pages_to_parse["qpl:" . $page->getId()] = "qpl:" . $page->getId();
985 }
986 unset($page);
987 }
988 if ($ids["test"] > 0) {
989 // test question
990 $page = new ilAssQuestionPage($ids["test"]);
991 $xmlcontent = str_replace(
992 $this->cur_qid,
993 "il__qst_" . $ids["test"],
994 $xml
995 );
996 $page->setXMLContent($xmlcontent);
997 $page->updateFromXML();
998 if ($this->page_object->needsImportParsing()) {
999 $this->pages_to_parse["qpl:" . $page->getId()] = "qpl:" . $page->getId();
1000 }
1001 unset($page);
1002 }
1003 }
1004 }
1005
1006 // if we are within a structure object: put page in tree
1007 $cnt = count($this->structure_objects);
1008 if ($cnt > 0) {
1009 $parent_id = $this->structure_objects[$cnt - 1]->getId();
1010 //if ($this->lm_page_object->isAlias()) {
1011 // $this->pg_into_tree[$parent_id][] = array("type" => "pg_alias", "id" => $this->lm_page_object->getOriginId());
1012 //} else {
1013 $this->pg_into_tree[$parent_id][] = array("type" => "pg", "id" => $this->lm_page_object->getId());
1014 //}
1015 }
1016
1017 unset($this->page_object);
1018 unset($this->lm_page_object);
1019 unset($this->container[count($this->container) - 1]);
1020 break;
1021
1022 case "MediaObject":
1023 case "InteractiveImage":
1024 if ($a_name == "MediaObject") {
1025 $this->in_media_object = false;
1026 }
1027
1028 if (empty($this->mob_mapping[$this->media_object->getImportId()])) {
1029 // create media object
1030 // media items are saves for mobs outside of
1031 // pages only
1032 $this->media_object->create(true, false);
1033
1034 // collect mobs with internal links
1035 if ($this->media_object->containsIntLink()) {
1036 //echo "got int link :".$this->media_object->getId().":<br>";
1037 $this->mobs_with_int_links[] = $this->media_object->getId();
1038 }
1039
1040 $this->mob_mapping[$this->media_object->getImportId()]
1041 = $this->media_object->getId();
1042 } else {
1043 // get the id from mapping
1044 $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
1045
1046 // update "real" (no alias) media object
1047 // (note: we overwrite any data from the media object
1048 // created by an MediaAlias, only the data of the real
1049 // object is stored in db separately; data of the
1050 // MediaAliases are within the page XML
1051 if (!$this->media_object->isAlias()) {
1052 // now the media items are saved within the db
1053 $this->media_object->update();
1054
1055 //echo "<br>update media object :".$this->media_object->getId().":";
1056
1057 // collect mobs with internal links
1058 if ($this->media_object->containsIntLink()) {
1059 //echo "got int link :".$this->media_object->getId().":<br>";
1060 $this->mobs_with_int_links[] = $this->media_object->getId();
1061 }
1062 }
1063 }
1064
1065 // append media alias to page, if we are in a page
1066 if ($this->in_page_object || $this->in_glossary_definition) {
1067 if ($a_name != "InteractiveImage") {
1068 $this->page_object->appendXMLContent($this->media_object->getXML(IL_MODE_ALIAS));
1069 //echo "Appending:".htmlentities($this->media_object->getXML(IL_MODE_ALIAS))."<br>";
1070 }
1071 }
1072
1073 break;
1074
1075 case "MediaItem":
1076 case "MediaAliasItem":
1077 $this->in_media_item = false;
1078 $this->media_object->addMediaItem($this->media_item);
1079 break;
1080
1081 case "MapArea":
1082 $this->in_map_area = false;
1083 $this->media_item->addMapArea($this->map_area);
1084 break;
1085
1086 case "Properties":
1087 $this->in_properties = false;
1088 if ($this->content_object->getType() == "lm") {
1089 $this->content_object->update();
1090 }
1091 break;
1092
1093 case "MetaData":
1094 $this->in_meta_data = false;
1095 if (strtolower(get_class($this->current_object)) == "illmpageobject" && !$this->in_media_object) {
1096 // Metadaten eines PageObjects sichern in NestedSet
1097 if (is_object($this->lm_page_object)) {
1098 // update title/description of page object
1099 $this->current_object->MDUpdateListener('General');
1101 $this->current_object->getId(),
1102 $this->current_object->getImportId()
1103 );
1104 }
1105 } elseif ((strtolower(get_class($this->current_object)) == "ilobjquestionpool" ||
1106 strtolower(get_class($this->current_object)) == "ilobjtest") &&
1107 !$this->in_media_object) {
1108 // !$this->in_media_object && !$this->in_page_object)
1109 // changed for imports of ILIAS 2 Tests where PageObjects could have
1110 // Metadata sections (Helmut Schottmüller, 2005-12-02)
1111 if ($this->metadata_parsing_disabled) {
1112 $this->enableMDParsing(true);
1113 } else {
1114 if ($this->in_page_object && !is_null($this->page_object)) {
1115 /*
1116 $this->page_object->MDUpdateListener('General');
1117 ilLMObject::_writeImportId(
1118 $this->page_object->getId(),
1119 $this->page_object->getImportId()
1120 );*/
1121 } else {
1122 $this->current_object->MDUpdateListener('General');
1124 $this->current_object->getId(),
1125 $this->current_object->getImportId()
1126 );
1127 }
1128 }
1129 } elseif (strtolower(get_class($this->current_object)) == "ilstructureobject") { // save structure object at the end of its meta block
1130 // determine parent
1131 $cnt = count($this->structure_objects);
1132 if ($cnt > 1) {
1133 $parent_id = $this->structure_objects[$cnt - 2]->getId();
1134 } else {
1135 $parent_id = $this->lm_tree->getRootId();
1136 }
1137
1138 $this->st_into_tree[] = array("id" => $this->current_object->getId(),
1139 "parent" => $parent_id);
1140
1141 // update title/description of structure object
1142 $this->current_object->MDUpdateListener('General');
1144 $this->current_object->getId(),
1145 $this->current_object->getImportId()
1146 );
1147 } elseif (strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
1148 strtolower(get_class($this->current_object)) == "ilobjcontentobject" ||
1149 (strtolower(get_class($this->current_object)) == "ilobjglossary" && $this->in_glossary)) {
1150 // todo: saving of md? getting title/descr and
1151 // set it for current object
1152 } elseif (strtolower(get_class($this->current_object)) == "ilglossarydefinition" && !$this->in_media_object) {
1153 // now on top
1154 //$this->glossary_definition->create();
1155
1156 $this->page_object->setId($this->glossary_definition->getId());
1157 $this->page_object->updateFromXML();
1158
1159 // todo: saving of md? getting title/descr and
1160 // set it for current object
1161 }
1162
1163
1164 if (strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
1165 strtolower(get_class($this->current_object)) == "ilobjglossary") {
1166 if (strtolower(get_class($this->current_object)) == "ilobjglossary" &&
1167 $this->content_object->getType() != "glo") {
1168 //echo "<br><b>getting2: ".$this->content_object->getTitle()."</b>";
1169 $this->current_object->setTitle($this->content_object->getTitle() . " - " .
1170 $this->lng->txt("glossary"));
1171 }
1172
1173 $this->current_object->MDUpdateListener('General');
1174 /*
1175 if (!$this->in_media_object && $this->processMeta())
1176 {
1177 $this->current_object->update();
1178 }
1179 */
1180 }
1181
1182 if ($this->in_media_object) {
1183 //echo "<br>call media object update listener";
1184 $this->media_object->MDUpdateListener('General');
1185 }
1186
1187 if ($this->in_glossary_definition) {
1188 $this->glossary_definition->MDUpdateListener('General');
1189 }
1190
1191 break;
1192
1193 case "Meta-Metadata":
1194 $this->in_meta_meta_data = false;
1195 break;
1196
1197 case "FileItem":
1198 $this->in_file_item = false;
1199 // only update new file items
1200 if ($this->file_item->getImportId()) {
1201 $this->file_item->update();
1202 }
1203 break;
1204
1205
1206 case "Table":
1207 unset($this->container[count($this->container) - 1]);
1208 break;
1209
1210 case "Glossary":
1211 $this->in_glossary = false;
1212 break;
1213
1214 case "GlossaryTerm":
1215 $term = trim($this->chr_data);
1216 $term = str_replace("&lt;", "<", $term);
1217 $term = str_replace("&gt;", ">", $term);
1218 $this->glossary_term->setTerm($term);
1219 $this->glossary_term->create();
1220 $iia = explode("_", $this->glossary_term->getImportId());
1221 $this->glossary_term_map[(int) $iia[count($iia) - 1]] = $this->glossary_term->getId();
1222 break;
1223
1224 case "Paragraph":
1225 $this->inside_code = false;
1226 break;
1227
1228 case "Definition":
1229 $this->in_glossary_definition = false;
1230 $this->page_object->updateFromXML();
1231 $this->page_object->buildDom();
1232 $this->glossary_definition->setShortText($this->page_object->getFirstParagraphText());
1233 $this->glossary_definition->update();
1234 if ($this->page_object->containsIntLink()) {
1235 $this->pages_to_parse["gdf:" . $this->page_object->getId()] = "gdf:" . $this->page_object->getId();
1236 }
1237 if ($this->page_object->needsImportParsing()) {
1238 $this->pages_to_parse["gdf:" . $this->page_object->getId()] = "gdf:" . $this->page_object->getId();
1239 }
1240 break;
1241
1242 case "Format":
1243 if ($this->in_media_item) {
1244 $this->media_item->setFormat(trim($this->chr_data));
1245 }
1246 break;
1247
1248 case "Title":
1249 if ($this->in_meta_data && !$this->in_media_object) {
1250 $this->current_object->setTitle(trim($this->chr_data));
1251 }
1252 if ($this->in_media_object) {
1253 $this->media_object->setTitle(trim($this->chr_data));
1254 }
1255 break;
1256
1257 case "Description":
1258 case "Language":
1259 break;
1260
1261 case "Caption":
1262 if ($this->in_media_object) {
1263 $this->media_item->setCaption(trim($this->chr_data));
1264 }
1265 break;
1266
1267 case "TextRepresentation":
1268 if ($this->in_media_object) {
1269 $this->media_item->setTextRepresentation(trim($this->chr_data));
1270 }
1271 break;
1272
1273 // Location
1274 case "Location":
1275 // TODO: adapt for files in "real" subdirectories
1276 if ($this->in_media_item) {
1277 $this->media_item->setLocationType($this->loc_type);
1278 if ($this->loc_type == "Reference") {
1279 $this->media_item->setLocation(str_replace("&", "&amp;", trim($this->chr_data)));
1280 } else {
1281 $this->media_item->setLocation(trim($this->chr_data));
1282 }
1283 }
1284 if ($this->in_file_item) {
1285 // set file name from xml file
1286 $this->file_item->setFileName(trim($this->chr_data));
1287
1288 // special handling for file names with special characters
1289 // (e.g. "&gt;")
1290 if ($this->file_item->getType() == "file" &&
1291 is_int(strpos($this->chr_data, "&")) &&
1292 is_int(strpos($this->chr_data, ";"))) {
1293 $imp_dir = $this->import_dir;
1294 $source_dir = $imp_dir . "/" . $this->subdir . "/objects/" .
1295 $this->file_item->getImportId();
1296
1297 // read "physical" file name from directory
1298 if ($dir = opendir($source_dir)) {
1299 while (false !== ($file = readdir($dir))) {
1300 if ($file != "." && $file != "..") {
1301 $this->file_item->setFileName($file);
1302 }
1303 }
1304 closedir($dir);
1305 }
1306 }
1307
1308 // set file item title
1309 $this->file_item->setTitle(trim($this->chr_data));
1310 }
1311 break;
1312
1313 }
1314 $this->endElement($a_name);
1315 $this->chr_data = "";
1316 }
const IL_MODE_ALIAS
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _writeImportId(int $a_id, string $a_import_id)
enableMDParsing(bool $a_status)
buildTag(string $type, string $name, array $attr=[])
static parseImportId(string $a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( 'orig' ...
$xml
Definition: metadata.php:351

References $xml, ilLMObject\_writeImportId(), IL_MODE_ALIAS, ILIAS\Repository\int(), and ilUtil\parseImportId().

+ Here is the call graph for this function:

◆ parseLinkTarget()

ilQuestionPageParser::parseLinkTarget ( string  $identifier)
private

Parse a string the get the elements of a link target Return null if the string is not a link target.

Returns
array{target_inst: int, target_type: string, target_id: int}|null

Definition at line 1418 of file class.ilQuestionPageParser.php.

1418 : ?array
1419 {
1420 $link_arr = explode('_', $identifier);
1421
1422 if (count($link_arr) !== 4
1423 || $link_arr[0] !== 'il'
1424 || !is_numeric($link_arr[1])
1425 || !is_numeric($link_arr[3])
1426 ) {
1427 return null;
1428 }
1429
1430 return [
1431 'target_inst' => (int) $link_arr[1],
1432 'target_type' => (string) $link_arr[2],
1433 'target_id' => (int) $link_arr[3]
1434 ];
1435 }

References ILIAS\Repository\int().

Referenced by processPagesToParse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processMeta()

ilQuestionPageParser::processMeta ( )

Definition at line 890 of file class.ilQuestionPageParser.php.

890 : bool
891 {
892 // do not process second meta block in (ilias3) glossaries
893 // which comes right after the "Glossary" tag
894 if ($this->content_object->getType() == "glo" &&
895 $this->in_glossary && !$this->in_media_object
896 && !$this->in_glossary_definition) {
897 return false;
898 }
899
900 return true;
901 }

◆ processPagesToParse()

ilQuestionPageParser::processPagesToParse ( )

parse pages that contain files, mobs and/or internal links

Definition at line 201 of file class.ilQuestionPageParser.php.

201 : void
202 {
203 // outgoin internal links
204 foreach ($this->pages_to_parse as $page_id) {
205 $page_arr = explode(":", $page_id);
206 $page_obj = null;
207 //echo "<br>resolve:".$this->content_object->getType().":".$page_id; flush();
208 switch ($page_arr[0]) {
209 case "lm":
210 switch ($this->content_object->getType()) {
211 case "lm":
212 $page_obj = new ilLMPage($page_arr[1]);
213 break;
214
215 default:
216 die("Unknown content type " . $this->content_object->getType());
217 }
218
219 break;
220
221 case "gdf":
222 $page_obj = new ilGlossaryDefPage($page_arr[1]);
223 break;
224
225 case "qpl":
226 $page_obj = new ilAssQuestionPage($page_arr[1]);
227 break;
228 }
229 $page_obj->buildDom();
230 $page_obj->resolveIntLinks();
231 $page_obj->resolveIIMMediaAliases($this->mob_mapping);
232 if ($this->coType == "lm") {
233 $page_obj->resolveQuestionReferences($this->qst_mapping);
234 }
235 $page_obj->update(false);
236
237 if ($page_arr[0] == "gdf") {
238 $def = new ilGlossaryDefinition($page_arr[1]);
239 $def->updateShortText();
240 }
241
242 unset($page_obj);
243 }
244
245 //echo "<br><b>map area internal links</b>"; flush();
246 // outgoins map area (mob) internal links
247 foreach ($this->mobs_with_int_links as $mob_id) {
249 }
250
251 //echo "<br><b>incoming interna links</b>"; flush();
252 // incoming internal links
253 $done = array();
254 foreach ($this->link_targets as $link_target) {
255 $parsed = $this->parseLinkTarget((string) $link_target);
256 if (!isset($parsed)) {
257 continue;
258 }
259 //echo "doin link target:".$link_target.":<br>";
261 $parsed['target_type'],
262 $parsed['target_id'],
263 $parsed['target_inst']
264 );
265
266 foreach ($sources as $key => $source) {
267 //echo "got source:".$key.":<br>";
268 if (in_array($key, $done)) {
269 continue;
270 }
271 $type_arr = explode(":", $source["type"]);
272
273 // content object pages
274 if ($type_arr[1] == "pg") {
275 if (ilPageObject::_exists($type_arr[0], $source["id"])) {
280 unset($page_object);
281 }
282 }
283
284 // eventually correct links in questions to learning modules
285 if ($type_arr[0] == "qst") {
287 }
288 // eventually correct links in survey questions to learning modules
289 if ($type_arr[0] == "sqst") {
291 }
292 $done[$key] = $key;
293 }
294 }
295 }
static _resolveIntLinks(int $question_id)
_resolveIntLinks(int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _resolveMapAreaLinks(int $a_mob_id)
resolve internal links of all media items of a media object
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
update(bool $a_validate=true, bool $a_no_history=false)
update complete page content in db (dom xml content is used)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
resolveIntLinks(array $a_link_map=null)
Resolves all internal link targets of the page, if targets are available (after import)
buildDom(bool $a_force=false)
parseLinkTarget(string $identifier)
Parse a string the get the elements of a link target Return null if the string is not a link target.
$source
Definition: metadata.php:93
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key, $page_object, $source, ilPageObject\_exists(), ilInternalLink\_getSourcesOfTarget(), SurveyQuestion\_resolveIntLinks(), assQuestion\_resolveIntLinks(), ilMediaItem\_resolveMapAreaLinks(), ilPageObject\buildDom(), ilPageObjectFactory\getInstance(), parseLinkTarget(), ilPageObject\resolveIntLinks(), and ilPageObject\update().

Referenced by startParsing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilQuestionPageParser::setHandlers (   $a_xml_parser)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 133 of file class.ilQuestionPageParser.php.

133 : void
134 {
135 xml_set_object($a_xml_parser, $this);
136 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
137 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
138 }

◆ setImportMapping()

ilQuestionPageParser::setImportMapping ( ilImportMapping  $mapping = null)

Definition at line 140 of file class.ilQuestionPageParser.php.

140 : void
141 {
142 $this->mapping = $mapping;
143 }

References $mapping.

◆ setQuestionMapping()

ilQuestionPageParser::setQuestionMapping ( array  $a_map)

set question import ident to pool/test question id mapping

Parameters
mixed[]$a_map

Definition at line 354 of file class.ilQuestionPageParser.php.

354 : void
355 {
356 $this->qst_mapping = $a_map;
357 }

◆ startParsing()

ilQuestionPageParser::startParsing ( )

stores xml data in array

Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

Definition at line 145 of file class.ilQuestionPageParser.php.

145 : void
146 {
147 $this->log->debug("start");
148
149 //echo "<b>start parsing</b><br>";
150 parent::startParsing();
151 //echo "<b>storeTree</b><br>";
152 $this->storeTree();
153 //echo "<b>processPagesToParse</b><br>";
154 $this->processPagesToParse();
155 //echo "<b>copyMobFiles</b><br>";
156 $this->copyMobFiles();
157 //echo "<b>copyFileItems</b><br>";
158 $this->copyFileItems();
159 //echo "<br>END Parsing"; exit;
160 }
copyFileItems()
copy files of file items
copyMobFiles()
copy multimedia object files from import zip file to mob directory
processPagesToParse()
parse pages that contain files, mobs and/or internal links
storeTree()
insert StructureObjects and PageObjects into tree

References copyFileItems(), copyMobFiles(), processPagesToParse(), and storeTree().

+ Here is the call graph for this function:

◆ storeTree()

ilQuestionPageParser::storeTree ( )

insert StructureObjects and PageObjects into tree

Definition at line 165 of file class.ilQuestionPageParser.php.

165 : void
166 {
167 $ilLog = $this->log;
168
169 foreach ($this->st_into_tree as $st) {
170 $this->lm_tree->insertNode($st["id"], $st["parent"]);
171 if (is_array($this->pg_into_tree[$st["id"]])) {
172 foreach ($this->pg_into_tree[$st["id"]] as $pg) {
173 $pg_id = 0;
174 switch ($pg["type"]) {
175 case "pg_alias":
176 if ($this->pg_mapping[$pg["id"]] == "") {
177 $ilLog->write("LM Import: No PageObject for PageAlias " .
178 $pg["id"] . " found! (Please update export installation to ILIAS 3.3.0)");
179
180 // Jump two levels up. First level is switch
181 continue 2;
182 }
183 $pg_id = $this->pg_mapping[$pg["id"]];
184 break;
185
186 case "pg":
187 $pg_id = $pg["id"];
188 break;
189 }
190 if (!$this->lm_tree->isInTree($pg_id)) {
191 $this->lm_tree->insertNode($pg_id, $st["id"]);
192 }
193 }
194 }
195 }
196 }
write(string $a_message, $a_level=ilLogLevel::INFO)
write log message

References $log, and ilLogger\write().

Referenced by startParsing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $chr_data

string ilQuestionPageParser::$chr_data = ""
protected

Definition at line 83 of file class.ilQuestionPageParser.php.

◆ $cnt

array ilQuestionPageParser::$cnt = []

Definition at line 45 of file class.ilQuestionPageParser.php.

◆ $container

array ilQuestionPageParser::$container = []

Definition at line 56 of file class.ilQuestionPageParser.php.

◆ $content_object

ilObject ilQuestionPageParser::$content_object = null

Definition at line 63 of file class.ilQuestionPageParser.php.

◆ $coType

string ilQuestionPageParser::$coType = ""
protected

Definition at line 42 of file class.ilQuestionPageParser.php.

◆ $cur_qid

string ilQuestionPageParser::$cur_qid = ""
protected

Definition at line 81 of file class.ilQuestionPageParser.php.

◆ $current_element

array ilQuestionPageParser::$current_element = []

Definition at line 46 of file class.ilQuestionPageParser.php.

◆ $current_object

object ilQuestionPageParser::$current_object = null

Definition at line 52 of file class.ilQuestionPageParser.php.

◆ $file_item

ilObjFile ilQuestionPageParser::$file_item = null

Definition at line 65 of file class.ilQuestionPageParser.php.

◆ $file_item_mapping

array ilQuestionPageParser::$file_item_mapping = []

Definition at line 68 of file class.ilQuestionPageParser.php.

◆ $glossary_definition

ilGlossaryDefinition ilQuestionPageParser::$glossary_definition = null
protected

Definition at line 82 of file class.ilQuestionPageParser.php.

◆ $glossary_object

ilObjGlossary ilQuestionPageParser::$glossary_object = null

Definition at line 64 of file class.ilQuestionPageParser.php.

◆ $glossary_term

ilGlossaryTerm ilQuestionPageParser::$glossary_term = null
protected

Definition at line 79 of file class.ilQuestionPageParser.php.

◆ $glossary_term_map

array ilQuestionPageParser::$glossary_term_map = []
protected

Definition at line 77 of file class.ilQuestionPageParser.php.

◆ $import_dir

string ilQuestionPageParser::$import_dir = ""
protected

Definition at line 43 of file class.ilQuestionPageParser.php.

Referenced by copyFileItems(), and copyMobFiles().

◆ $in_file_item

bool ilQuestionPageParser::$in_file_item = false

Definition at line 60 of file class.ilQuestionPageParser.php.

◆ $in_glossary

bool ilQuestionPageParser::$in_glossary = false

Definition at line 61 of file class.ilQuestionPageParser.php.

◆ $in_glossary_definition

bool ilQuestionPageParser::$in_glossary_definition = false
protected

Definition at line 36 of file class.ilQuestionPageParser.php.

◆ $in_map_area

bool ilQuestionPageParser::$in_map_area = false

Definition at line 62 of file class.ilQuestionPageParser.php.

◆ $in_media_item

bool ilQuestionPageParser::$in_media_item = false
protected

Definition at line 84 of file class.ilQuestionPageParser.php.

◆ $in_media_object

bool ilQuestionPageParser::$in_media_object = false

Definition at line 59 of file class.ilQuestionPageParser.php.

◆ $in_meta_data

bool ilQuestionPageParser::$in_meta_data = false

Definition at line 58 of file class.ilQuestionPageParser.php.

◆ $in_meta_meta_data

bool ilQuestionPageParser::$in_meta_meta_data = false

Definition at line 76 of file class.ilQuestionPageParser.php.

◆ $in_page_object

bool ilQuestionPageParser::$in_page_object = false

Definition at line 57 of file class.ilQuestionPageParser.php.

◆ $in_properties

bool ilQuestionPageParser::$in_properties
protected

Definition at line 32 of file class.ilQuestionPageParser.php.

◆ $inside_code

bool ilQuestionPageParser::$inside_code = false
protected

Definition at line 41 of file class.ilQuestionPageParser.php.

◆ $learning_module

ilObjLearningModule ilQuestionPageParser::$learning_module = null

Definition at line 47 of file class.ilQuestionPageParser.php.

◆ $link_targets

array ilQuestionPageParser::$link_targets = []

Definition at line 73 of file class.ilQuestionPageParser.php.

◆ $lm_page_object

ilLMPageObject ilQuestionPageParser::$lm_page_object = null

Definition at line 49 of file class.ilQuestionPageParser.php.

◆ $lm_tree

ilLMTree ilQuestionPageParser::$lm_tree = null

Definition at line 53 of file class.ilQuestionPageParser.php.

◆ $loc_type

string ilQuestionPageParser::$loc_type = ""

Definition at line 71 of file class.ilQuestionPageParser.php.

◆ $log

ilLogger ilQuestionPageParser::$log
protected

Definition at line 78 of file class.ilQuestionPageParser.php.

Referenced by storeTree().

◆ $map_area

ilMapArea ilQuestionPageParser::$map_area = null

Definition at line 72 of file class.ilQuestionPageParser.php.

◆ $mapping

ilImportMapping ilQuestionPageParser::$mapping = null
protected

Definition at line 80 of file class.ilQuestionPageParser.php.

Referenced by setImportMapping().

◆ $media_item

ilMediaItem ilQuestionPageParser::$media_item = null

Definition at line 70 of file class.ilQuestionPageParser.php.

◆ $media_meta_cache

array ilQuestionPageParser::$media_meta_cache = []
protected

Definition at line 37 of file class.ilQuestionPageParser.php.

◆ $media_meta_start

bool ilQuestionPageParser::$media_meta_start = false
protected

Definition at line 38 of file class.ilQuestionPageParser.php.

◆ $media_object

ilObjMediaObject ilQuestionPageParser::$media_object = null

Definition at line 51 of file class.ilQuestionPageParser.php.

◆ $metadata_parsing_disabled

bool ilQuestionPageParser::$metadata_parsing_disabled = false

Definition at line 75 of file class.ilQuestionPageParser.php.

◆ $mob_mapping

array ilQuestionPageParser::$mob_mapping = []

Definition at line 67 of file class.ilQuestionPageParser.php.

◆ $mobs_with_int_links

array ilQuestionPageParser::$mobs_with_int_links = []
protected

Definition at line 40 of file class.ilQuestionPageParser.php.

◆ $page_object

ilPageObject ilQuestionPageParser::$page_object = null

Definition at line 48 of file class.ilQuestionPageParser.php.

Referenced by processPagesToParse().

◆ $pages_to_parse

array ilQuestionPageParser::$pages_to_parse = []

Definition at line 66 of file class.ilQuestionPageParser.php.

◆ $pg_into_tree

array ilQuestionPageParser::$pg_into_tree = []

Definition at line 54 of file class.ilQuestionPageParser.php.

◆ $pg_mapping

array ilQuestionPageParser::$pg_mapping = []
protected

Definition at line 39 of file class.ilQuestionPageParser.php.

◆ $qst_mapping

array ilQuestionPageParser::$qst_mapping = []

Definition at line 74 of file class.ilQuestionPageParser.php.

◆ $st_into_tree

array ilQuestionPageParser::$st_into_tree = []

Definition at line 55 of file class.ilQuestionPageParser.php.

◆ $structure_objects

array ilQuestionPageParser::$structure_objects = []

Definition at line 50 of file class.ilQuestionPageParser.php.

◆ $subdir

string ilQuestionPageParser::$subdir = ""

Definition at line 69 of file class.ilQuestionPageParser.php.

◆ $tree

ilTree ilQuestionPageParser::$tree

Definition at line 44 of file class.ilQuestionPageParser.php.

Referenced by __construct().


The documentation for this class was generated from the following file: