ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilQuestionPageParser Class Reference

Legacy Content Object Parser. More...

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

Public Member Functions

 __construct (private readonly ilObject $content_object, string $xml_file, private readonly string $importdir)
 
 setHandlers ($xml_parser)
 
 setImportMapping (ilImportMapping $mapping=null)
 
 startParsing ()
 
 storeTree ()
 insert StructureObjects and PageObjects into tree More...
 
 processPagesToParse ()
 parse pages that contain files, mobs and/or internal links 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
 
ilObjGlossary $glossary_object = null
 
ilObjFile $file_item = null
 
array $pages_to_parse = []
 
array $mob_mapping = []
 
array $file_item_mapping = []
 
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 $content_type = ''
 
array $glossary_term_map = []
 
ilLogger $log
 
ilGlossaryTerm $glossary_term = null
 
ilImportMapping $mapping = null
 
string $cur_qid = ''
 
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

 copyFileItems ()
 copy files of file items More...
 
 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 ( private readonly ilObject  $content_object,
string  $xml_file,
private readonly string  $importdir 
)

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

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

86  {
87  global $DIC;
88  $lng = $DIC->language();
89  $tree = $DIC->repositoryTree();
90 
91  $this->log = ilLoggerFactory::getLogger('lm');
92 
94  $this->cnt = [];
95  $this->current_element = [];
96  $this->structure_objects = [];
97  $this->st_into_tree = [];
98  $this->pg_into_tree = [];
99  $this->pages_to_parse = [];
100  $this->mobs_with_int_links = [];
101  $this->mob_mapping = [];
102  $this->file_item_mapping = [];
103  $this->pg_mapping = [];
104  $this->link_targets = [];
105  $this->lng = $lng;
106  $this->tree = $tree;
107  $this->inside_code = false;
108  $this->qst_mapping = [];
109  $this->content_type = $this->content_object->getType();
110  $this->metadata_parsing_disabled = false;
111 
112  if ($this->content_type !== 'tst' && $this->content_type !== 'qpl') {
113  $this->lm_tree = new ilLMTree($this->content_object->getId());
114  }
115  }
static getLogger(string $a_component_id)
Get component logger.
ilLanguage $lng
global $DIC
Definition: shib_login.php:25
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ beginElement()

ilQuestionPageParser::beginElement ( string  $a_name)

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

Referenced by buildTag().

300  : void
301  {
302  if (!isset($this->status['$a_name'])) {
303  $this->cnt[$a_name] = 1;
304  } else {
305  $this->cnt[$a_name]++;
306  }
307  $this->current_element[count($this->current_element)] = $a_name;
308  }
+ Here is the caller graph for this function:

◆ buildTag()

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

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

References $glossary_object, $glossary_term, $lm_page_object, beginElement(), emptyMediaMetaCache(), ilMDSaxParser\enableMDParsing(), ilMDSaxParser\handlerBeginTag(), IL_EXT_LINK, IL_INT_LINK, ilUtil\parseImportId(), parseLinkTarget(), processMeta(), and ilUtil\yn2tf().

Referenced by handlerEndTag().

333  : string {
334  $tag = '<';
335 
336  if ($type == 'end') {
337  $tag .= '/';
338  }
339 
340  $tag .= $name;
341 
342  if (is_array($attr)) {
343  foreach ($attr as $k => $v) {
344  $tag .= ' ' . $k . "='$v'";
345  }
346  }
347 
348  $tag .= '>';
349 
350  return $tag;
351  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyFileItems()

ilQuestionPageParser::copyFileItems ( )
private

copy files of file items

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

Referenced by startParsing().

269  : void
270  {
271  foreach ($this->file_item_mapping as $origin_id => $file_id) {
272  if (empty($origin_id)) {
273  continue;
274  }
275  $obj_dir = $origin_id;
276  $source_dir = $this->importdir . DIRECTORY_SEPARATOR . 'objects' . DIRECTORY_SEPARATOR . $obj_dir;
277 
278  $file_obj = new ilObjFile($file_id, false);
279  if (is_dir($source_dir)) {
280  $files = scandir($source_dir, SCANDIR_SORT_DESCENDING);
281  if ($files !== false && $files !== [] && is_file($source_dir . '/' . $files[0])) {
282  $file = fopen($source_dir . '/' . $files[0], 'rb');
283  $file_stream = Streams::ofResource($file);
284  $file_obj->appendStream($file_stream, $files[0]);
285  }
286  }
287  $file_obj->update();
288  }
289  }
Class ilObjFile.
+ Here is the caller graph for this function:

◆ emptyMediaMetaCache()

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

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

Referenced by buildTag().

1300  : void
1301  {
1302  foreach ($this->media_meta_cache as $cache_entry) {
1303  switch ($cache_entry['type']) {
1304  case 'handlerBeginTag':
1305  parent::handlerBeginTag(
1306  $a_xml_parser,
1307  $cache_entry['par1'],
1308  $cache_entry['par2']
1309  );
1310  break;
1311 
1312  case 'handlerEndTag':
1313  parent::handlerEndTag(
1314  $a_xml_parser,
1315  $cache_entry['par1']
1316  );
1317  break;
1318 
1319  case 'handlerCharacterData':
1320  parent::handlerCharacterData(
1321  $a_xml_parser,
1322  $cache_entry['par1']
1323  );
1324  break;
1325  }
1326  }
1327 
1328  $this->media_meta_start = false;
1329  $this->media_meta_cache[] = [];
1330  }
+ Here is the caller graph for this function:

◆ endElement()

ilQuestionPageParser::endElement ( string  $a_name)

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

Referenced by handlerEndTag().

310  : void
311  {
312  $this->cnt[$a_name]--;
313  unset($this->current_element[count($this->current_element) - 1]);
314  }
+ Here is the caller graph for this function:

◆ getCurrentElement()

ilQuestionPageParser::getCurrentElement ( )

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

Referenced by handlerCharacterData().

316  : string
317  {
318  return ($this->current_element[count($this->current_element) - 1] ?? '');
319  }
+ Here is the caller graph for this function:

◆ getGlossaryTermMap()

ilQuestionPageParser::getGlossaryTermMap ( )
Returns
mixed[]

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

References $glossary_term_map.

1335  : array
1336  {
1337  return $this->glossary_term_map;
1338  }

◆ getOpenCount()

ilQuestionPageParser::getOpenCount ( string  $a_name)

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

321  : int
322  {
323  if (isset($this->cnt[$a_name])) {
324  return $this->cnt[$a_name];
325  }
326  return 0;
327  }

◆ handlerCharacterData()

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

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

References getCurrentElement(), and processMeta().

1247  : void
1248  {
1249  // call meta data handler
1250  if ($this->in_meta_data && $this->processMeta()) {
1251  // cache beginning of meta data within media object tags
1252  // (we need to know the id, after that we send the cached data
1253  // to the meta xml handler)
1254  if ($this->in_media_object && $this->media_meta_start) {
1255  $this->media_meta_cache[] =
1256  ['type' => 'handlerCharacterData', 'par1' => $a_data];
1257  } else {
1258  parent::handlerCharacterData($a_xml_parser, $a_data);
1259  }
1260  }
1261 
1262  // the parser converts '&gt;' to '>' and '&lt;' to '<'
1263  // in character data, but we don't want that, because it's the
1264  // way we mask user html in our content, so we convert back...
1265 
1266  $a_data = str_replace('<', '&lt;', $a_data);
1267  $a_data = str_replace('>', '&gt;', $a_data);
1268 
1269 
1270  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
1271  $a_data = preg_replace('/\n/', '', $a_data);
1272  if (!$this->inside_code) {
1273  $a_data = preg_replace('/\t+/', '', $a_data);
1274  }
1275 
1276  $this->chr_data .= $a_data;
1277 
1278  if (!empty($a_data) || $a_data === '0') {
1279  // append all data to page, if we are within PageObject,
1280  // but not within MetaData or MediaObject
1281  if (($this->in_page_object || $this->in_glossary_definition)
1282  && !$this->in_meta_data && !$this->in_media_object) {
1283  $this->page_object->appendXMLContent($a_data);
1284  }
1285 
1286  switch ($this->getCurrentElement()) {
1287  case 'IntLink':
1288  case 'ExtLink':
1289  if ($this->in_map_area) {
1290  $this->map_area->appendTitle($a_data);
1291  }
1292  break;
1293  }
1294  }
1295  }
+ Here is the call graph for this function:

◆ handlerEndTag()

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

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

References $cur_qid, ilLMObject\_writeImportId(), buildTag(), ilMDSaxParser\enableMDParsing(), endElement(), IL_MODE_ALIAS, ILIAS\Repository\int(), ILIAS\Repository\lng(), ilUtil\parseImportId(), and processMeta().

835  : void
836  {
837  // call meta data handler
838  if ($this->in_meta_data && $this->processMeta()) {
839  // cache beginning of meta data within media object tags
840  // (we need to know the id, after that we send the cached data
841  // to the meta xml handler)
842  if ($this->in_media_object && $this->media_meta_start) {
843  $this->media_meta_cache[] =
844  ['type' => 'handlerEndTag', 'par1' => $a_name];
845  } else {
846  parent::handlerEndTag($a_xml_parser, $a_name);
847  }
848  }
849 
850  // append content to page xml content
851  if (($this->in_page_object || $this->in_glossary_definition)
852  && !$this->in_meta_data && !$this->in_media_object) {
853  $app_name = ($a_name == 'Definition')
854  ? 'PageObject'
855  : $a_name;
856  $this->page_object->appendXMLContent($this->buildTag('end', $app_name));
857  }
858 
859  switch ($a_name) {
860  case 'StructureObject':
861  unset($this->structure_objects[count($this->structure_objects) - 1]);
862  break;
863 
864  case 'PageObject':
865  $this->in_page_object = false;
866  if ($this->content_type != 'tst' && $this->content_type != 'qpl') {
867  //if (!$this->lm_page_object->isAlias()) {
868  $this->page_object->updateFromXML();
869  $this->pg_mapping[$this->lm_page_object->getImportId()]
870  = $this->lm_page_object->getId();
871 
872  if ($this->mapping instanceof ilImportMapping) {
873  $import_id_parsed = ilUtil::parseImportId($this->lm_page_object->getImportId());
874  if ($import_id_parsed['type'] == 'pg') {
875  $this->mapping->addMapping(
876  'components/ILIAS/LearningModule',
877  'pg',
878  $import_id_parsed['id'],
879  $this->lm_page_object->getId()
880  );
881  }
882  }
883 
884  // collect pages with internal links
885  if ($this->page_object->containsIntLink()) {
886  $this->pages_to_parse['lm:' . $this->page_object->getId()] = 'lm:' . $this->page_object->getId();
887  }
888 
889  // collect pages with mobs or files
890  if ($this->page_object->needsImportParsing()) {
891  $this->pages_to_parse['lm:' . $this->page_object->getId()] = 'lm:' . $this->page_object->getId();
892  }
893 
894  // collect pages with questions
895  if ($this->page_object->getContainsQuestion()) {
896  $this->pages_to_parse['lm:' . $this->page_object->getId()] = 'lm:' . $this->page_object->getId();
897  }
898  //}
899  } else {
900  $xml = $this->page_object->getXMLContent();
901  if ($this->cur_qid != '') {
902  $ids = $this->qst_mapping[$this->cur_qid] ?? ['pool' => 0, 'test' => 0];
903  if ($ids['pool'] > 0) {
904  // question pool question
905  $page = new ilAssQuestionPage($ids['pool']);
906  $xmlcontent = str_replace(
907  $this->cur_qid,
908  'il__qst_' . $ids['pool'],
909  $xml
910  );
911  $page->setXMLContent($xmlcontent);
912  $page->updateFromXML();
913  if ($this->page_object->needsImportParsing()) {
914  $this->pages_to_parse['qpl:' . $page->getId()] = 'qpl:' . $page->getId();
915  }
916  unset($page);
917  }
918  if ($ids['test'] > 0) {
919  // test question
920  $page = new ilAssQuestionPage($ids['test']);
921  $xmlcontent = str_replace(
922  $this->cur_qid,
923  'il__qst_' . $ids['test'],
924  $xml
925  );
926  $page->setXMLContent($xmlcontent);
927  $page->updateFromXML();
928  if ($this->page_object->needsImportParsing()) {
929  $this->pages_to_parse['qpl:' . $page->getId()] = 'qpl:' . $page->getId();
930  }
931  unset($page);
932  }
933  }
934  }
935 
936  // if we are within a structure object: put page in tree
937  $cnt = count($this->structure_objects);
938  if ($cnt > 0) {
939  $parent_id = $this->structure_objects[$cnt - 1]->getId();
940  $this->pg_into_tree[$parent_id][] = ['type' => 'pg', 'id' => $this->lm_page_object->getId()];
941  }
942 
943  unset($this->page_object);
944  unset($this->lm_page_object);
945  unset($this->container[count($this->container) - 1]);
946  break;
947 
948  case 'MediaObject':
949  case 'InteractiveImage':
950  if ($a_name == 'MediaObject') {
951  $this->in_media_object = false;
952  }
953 
954  if (empty($this->mob_mapping[$this->media_object->getImportId()])) {
955  // create media object
956  // media items are saves for mobs outside of
957  // pages only
958  $this->media_object->create(true, false);
959 
960  // collect mobs with internal links
961  if ($this->media_object->containsIntLink()) {
962  $this->mobs_with_int_links[] = $this->media_object->getId();
963  }
964 
965  $this->mob_mapping[$this->media_object->getImportId()]
966  = $this->media_object->getId();
967  } else {
968  // get the id from mapping
969  $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
970 
971  // update 'real' (no alias) media object
972  // (note: we overwrite any data from the media object
973  // created by an MediaAlias, only the data of the real
974  // object is stored in db separately; data of the
975  // MediaAliases are within the page XML
976  if (!$this->media_object->isAlias()) {
977  // now the media items are saved within the db
978  $this->media_object->update();
979 
980  // collect mobs with internal links
981  if ($this->media_object->containsIntLink()) {
982  $this->mobs_with_int_links[] = $this->media_object->getId();
983  }
984  }
985  }
986 
987  // append media alias to page, if we are in a page
988  if ($this->in_page_object || $this->in_glossary_definition) {
989  if ($a_name != 'InteractiveImage') {
990  $this->page_object->appendXMLContent($this->media_object->getXML(IL_MODE_ALIAS));
991  }
992  }
993 
994  break;
995 
996  case 'MediaAliasItem':
997  $this->in_media_item = false;
998  $this->media_object->addMediaItem($this->media_item);
999  break;
1000  case 'MediaItem':
1001  $this->in_media_item = false;
1002  $import_dir = $this->importdir . DIRECTORY_SEPARATOR . 'objects' . DIRECTORY_SEPARATOR . $this->media_object->getImportId();
1003  if (!file_exists($import_dir)
1004  || !is_dir($import_dir)) {
1005  $this->media_object->addMediaItem($this->media_item);
1006  break;
1007  }
1008 
1009  $dir_handle = opendir($import_dir);
1010  while (($file = readdir($dir_handle)) !== false) {
1011  if ($file !== $this->media_item->getLocation()) {
1012  continue;
1013  }
1014 
1015  $this->media_object->addMediaItemFromLocalFile(
1016  $this->media_item->getPurpose(),
1017  $import_dir . DIRECTORY_SEPARATOR . $file,
1018  $file
1019  );
1020  break;
1021  }
1022  closedir($dir_handle);
1023  break;
1024 
1025  case 'MapArea':
1026  $this->in_map_area = false;
1027  $this->media_item->addMapArea($this->map_area);
1028  break;
1029 
1030  case 'Properties':
1031  $this->in_properties = false;
1032  if ($this->content_object->getType() == 'lm') {
1033  $this->content_object->update();
1034  }
1035  break;
1036 
1037  case 'MetaData':
1038  $this->in_meta_data = false;
1039  if (strtolower(get_class($this->current_object)) == 'illmpageobject' && !$this->in_media_object) {
1040  // Metadaten eines PageObjects sichern in NestedSet
1041  if (is_object($this->lm_page_object)) {
1042  // update title/description of page object
1043  $this->current_object->MDUpdateListener('General');
1045  $this->current_object->getId(),
1046  $this->current_object->getImportId()
1047  );
1048  }
1049  } elseif ((strtolower(get_class($this->current_object)) == 'ilobjquestionpool' ||
1050  strtolower(get_class($this->current_object)) == 'ilobjtest') &&
1051  !$this->in_media_object) {
1052  // !$this->in_media_object && !$this->in_page_object)
1053  // changed for imports of ILIAS 2 Tests where PageObjects could have
1054  // Metadata sections (Helmut Schottmüller, 2005-12-02)
1055  if ($this->metadata_parsing_disabled) {
1056  $this->enableMDParsing(true);
1057  } else {
1058  if ($this->in_page_object && !is_null($this->page_object)) {
1059  /*
1060  $this->page_object->MDUpdateListener('General');
1061  ilLMObject::_writeImportId(
1062  $this->page_object->getId(),
1063  $this->page_object->getImportId()
1064  );*/
1065  } else {
1066  $this->current_object->MDUpdateListener('General');
1068  $this->current_object->getId(),
1069  $this->current_object->getImportId()
1070  );
1071  }
1072  }
1073  } elseif (strtolower(get_class($this->current_object)) == 'ilstructureobject') { // save structure object at the end of its meta block
1074  // determine parent
1075  $cnt = count($this->structure_objects);
1076  if ($cnt > 1) {
1077  $parent_id = $this->structure_objects[$cnt - 2]->getId();
1078  } else {
1079  $parent_id = $this->lm_tree->getRootId();
1080  }
1081 
1082  $this->st_into_tree[] = ['id' => $this->current_object->getId(),
1083  'parent' => $parent_id];
1084 
1085  // update title/description of structure object
1086  $this->current_object->MDUpdateListener('General');
1088  $this->current_object->getId(),
1089  $this->current_object->getImportId()
1090  );
1091  } elseif (strtolower(get_class($this->current_object)) == 'ilobjlearningmodule' ||
1092  strtolower(get_class($this->current_object)) == 'ilobjcontentobject' ||
1093  (strtolower(get_class($this->current_object)) == 'ilobjglossary' && $this->in_glossary)) {
1094  // todo: saving of md? getting title/descr and
1095  // set it for current object
1096  } elseif (strtolower(get_class($this->current_object)) == 'ilglossaryterm' && !$this->in_media_object) {
1097  // now on top
1098 
1099  $this->page_object->setId($this->glossary_term->getId());
1100  $this->page_object->updateFromXML();
1101 
1102  // todo: saving of md? getting title/descr and
1103  // set it for current object
1104  }
1105 
1106 
1107  if (strtolower(get_class($this->current_object)) == 'ilobjlearningmodule' ||
1108  strtolower(get_class($this->current_object)) == 'ilobjglossary') {
1109  if (strtolower(get_class($this->current_object)) == 'ilobjglossary' &&
1110  $this->content_object->getType() != 'glo') {
1111  $this->current_object->setTitle($this->content_object->getTitle() . ' - ' .
1112  $this->lng->txt('glossary'));
1113  }
1114 
1115  $this->current_object->MDUpdateListener('General');
1116  }
1117 
1118  if ($this->in_media_object) {
1119  $this->media_object->MDUpdateListener('General');
1120  }
1121 
1122  break;
1123 
1124  case 'Meta-Metadata':
1125  $this->in_meta_meta_data = false;
1126  break;
1127 
1128  case 'FileItem':
1129  $this->in_file_item = false;
1130  // only update new file items
1131  if ($this->file_item->getImportId()) {
1132  $this->file_item->update();
1133  }
1134  break;
1135 
1136 
1137  case 'Table':
1138  unset($this->container[count($this->container) - 1]);
1139  break;
1140 
1141  case 'Glossary':
1142  $this->in_glossary = false;
1143  break;
1144 
1145  case 'GlossaryTerm':
1146  $term = trim($this->chr_data);
1147  $term = str_replace('&lt;', '<', $term);
1148  $term = str_replace('&gt;', '>', $term);
1149  $this->glossary_term->setTerm($term);
1150  $this->glossary_term->create();
1151  $iia = explode('_', $this->glossary_term->getImportId());
1152  $this->glossary_term_map[(int) $iia[count($iia) - 1]] = $this->glossary_term->getId();
1153  break;
1154 
1155  case 'Paragraph':
1156  $this->inside_code = false;
1157  break;
1158 
1159  case 'Definition':
1160  $this->in_glossary_definition = false;
1161  $this->page_object->updateFromXML();
1162  $this->page_object->buildDom();
1163  $this->glossary_term->setShortText($this->page_object->getFirstParagraphText());
1164  $this->glossary_term->update();
1165  if ($this->page_object->containsIntLink()) {
1166  $this->pages_to_parse['term:' . $this->page_object->getId()] = 'term:' . $this->page_object->getId();
1167  }
1168  if ($this->page_object->needsImportParsing()) {
1169  $this->pages_to_parse['term:' . $this->page_object->getId()] = 'term:' . $this->page_object->getId();
1170  }
1171  break;
1172 
1173  case 'Format':
1174  if ($this->in_media_item) {
1175  $this->media_item->setFormat(trim($this->chr_data));
1176  }
1177  break;
1178 
1179  case 'Title':
1180  if ($this->in_meta_data && !$this->in_media_object) {
1181  $this->current_object->setTitle(trim($this->chr_data));
1182  }
1183  if ($this->in_media_object) {
1184  $this->media_object->setTitle(trim($this->chr_data));
1185  }
1186  break;
1187 
1188  case 'Description':
1189  case 'Language':
1190  break;
1191 
1192  case 'Caption':
1193  if ($this->in_media_object) {
1194  $this->media_item->setCaption(trim($this->chr_data));
1195  }
1196  break;
1197 
1198  case 'TextRepresentation':
1199  if ($this->in_media_object) {
1200  $this->media_item->setTextRepresentation(trim($this->chr_data));
1201  }
1202  break;
1203 
1204  // Location
1205  case 'Location':
1206  // TODO: adapt for files in 'real' subdirectories
1207  if ($this->in_media_item) {
1208  $this->media_item->setLocationType($this->loc_type);
1209  if ($this->loc_type == 'Reference') {
1210  $this->media_item->setLocation(str_replace('&', '&amp;', trim($this->chr_data)));
1211  } else {
1212  $this->media_item->setLocation(trim($this->chr_data));
1213  }
1214  }
1215  if ($this->in_file_item) {
1216  // set file name from xml file
1217  $this->file_item->setFileName(trim($this->chr_data));
1218 
1219  // special handling for file names with special characters
1220  // (e.g. '&gt;')
1221  if ($this->file_item->getType() == 'file' &&
1222  is_int(strpos($this->chr_data, '&')) &&
1223  is_int(strpos($this->chr_data, ';'))) {
1224  $source_dir = $this->importdir . DIRECTORY_SEPARATOR . 'objects' . DIRECTORY_SEPARATOR .
1225  $this->file_item->getImportId();
1226 
1227  // read 'physical' file name from directory
1228  if ($dir = opendir($source_dir)) {
1229  while (false !== ($file = readdir($dir))) {
1230  if ($file != '.' && $file != '..') {
1231  $this->file_item->setFileName($file);
1232  }
1233  }
1234  closedir($dir);
1235  }
1236  }
1237 
1238  // set file item title
1239  $this->file_item->setTitle(trim($this->chr_data));
1240  }
1241  break;
1242  }
1243  $this->endElement($a_name);
1244  $this->chr_data = '';
1245  }
enableMDParsing(bool $a_status)
buildTag(string $type, string $name, array $attr=[])
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 parseImportId(string $a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( &#39;orig&#39; ...
const IL_MODE_ALIAS
static _writeImportId(int $a_id, string $a_import_id)
+ 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 1345 of file class.ilQuestionPageParser.php.

References ILIAS\Repository\int().

Referenced by buildTag(), and processPagesToParse().

1345  : ?array
1346  {
1347  $link_arr = explode('_', $identifier);
1348 
1349  if (count($link_arr) !== 4
1350  || $link_arr[0] !== 'il'
1351  || !is_numeric($link_arr[1])
1352  || !is_numeric($link_arr[3])
1353  ) {
1354  return null;
1355  }
1356 
1357  return [
1358  'target_inst' => (int) $link_arr[1],
1359  'target_type' => (string) $link_arr[2],
1360  'target_id' => (int) $link_arr[3]
1361  ];
1362  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processMeta()

ilQuestionPageParser::processMeta ( )

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

References $in_glossary_definition.

Referenced by buildTag(), handlerCharacterData(), and handlerEndTag().

821  : bool
822  {
823  // do not process second meta block in (ilias3) glossaries
824  // which comes right after the 'Glossary' tag
825  if ($this->content_object->getType() == 'glo' &&
826  $this->in_glossary && !$this->in_media_object
828  return false;
829  }
830 
831  return true;
832  }
+ Here is the caller graph for this function:

◆ processPagesToParse()

ilQuestionPageParser::processPagesToParse ( )

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

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

References ilPageObject\_exists(), ilInternalLink\_getSourcesOfTarget(), ilMediaItem\_resolveMapAreaLinks(), ilPageObject\buildDom(), ilPageObjectFactory\getInstance(), assQuestion\instantiateQuestion(), parseLinkTarget(), ilPageObject\resolveIntLinks(), and ilPageObject\update().

Referenced by startParsing().

181  : void
182  {
183  // outgoin internal links
184  foreach ($this->pages_to_parse as $page_id) {
185  $page_arr = explode(':', $page_id);
186  $page_obj = null;
187  switch ($page_arr[0]) {
188  case 'lm':
189  switch ($this->content_object->getType()) {
190  case 'lm':
191  $page_obj = new ilLMPage($page_arr[1]);
192  break;
193 
194  default:
195  die('Unknown content type ' . $this->content_object->getType());
196  }
197 
198  break;
199 
200  case 'term':
201  $page_obj = new ilGlossaryDefPage($page_arr[1]);
202  break;
203 
204  case 'qpl':
205  $page_obj = new ilAssQuestionPage($page_arr[1]);
206  break;
207  }
208  $page_obj->buildDom();
209  $page_obj->resolveIntLinks();
210  $page_obj->resolveIIMMediaAliases($this->mob_mapping);
211  if ($this->content_type == 'lm') {
212  $page_obj->resolveQuestionReferences($this->qst_mapping);
213  }
214  $page_obj->update(false);
215 
216  if ($page_arr[0] == 'term') {
217  $term = new ilGlossaryTerm($page_arr[1]);
218  $term->updateShortText();
219  }
220 
221  unset($page_obj);
222  }
223 
224  foreach ($this->mobs_with_int_links as $mob_id) {
226  }
227 
228  $done = [];
229  foreach ($this->link_targets as $link_target) {
230  $parsed = $this->parseLinkTarget((string) $link_target);
231  if (!isset($parsed)) {
232  continue;
233  }
234  //echo "doin link target:".$link_target.":<br>";
236  $parsed['target_type'],
237  $parsed['target_id'],
238  $parsed['target_inst']
239  );
240  foreach ($sources as $key => $source) {
241  if (in_array($key, $done)) {
242  continue;
243  }
244  $type_arr = explode(':', $source['type']);
245 
246  // content object pages
247  if ($type_arr[1] == 'pg') {
248  if (ilPageObject::_exists($type_arr[0], $source['id'])) {
249  $page_object = ilPageObjectFactory::getInstance($type_arr[0], $source['id']);
252  $page_object->update();
253  unset($page_object);
254  }
255  }
256 
257  // eventually correct links in questions to learning modules
258  if ($type_arr[0] === 'qst') {
259  assQuestion::instantiateQuestion($source['id'])->resolveSuggestedSolutionLinks();
260  }
261  $done[$key] = $key;
262  }
263  }
264  }
buildDom(bool $a_force=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
resolveIntLinks(array $a_link_map=null)
Resolves all internal link targets of the page, if targets are available (after import) ...
update(bool $a_validate=true, bool $a_no_history=false)
update complete page content in db (dom xml content is used)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseLinkTarget(string $identifier)
Parse a string the get the elements of a link target Return null if the string is not a link target...
static instantiateQuestion(int $question_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

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

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

120  : void
121  {
122  xml_set_object($xml_parser, $this);
123  xml_set_element_handler($xml_parser, 'handlerBeginTag', 'handlerEndTag');
124  xml_set_character_data_handler($xml_parser, 'handlerCharacterData');
125  }

◆ setImportMapping()

ilQuestionPageParser::setImportMapping ( ilImportMapping  $mapping = null)

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

References $mapping.

127  : void
128  {
129  $this->mapping = $mapping;
130  }

◆ setQuestionMapping()

ilQuestionPageParser::setQuestionMapping ( array  $a_map)

set question import ident to pool/test question id mapping

Parameters
mixed[]$a_map

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

295  : void
296  {
297  $this->qst_mapping = $a_map;
298  }

◆ startParsing()

ilQuestionPageParser::startParsing ( )

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

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

132  : void
133  {
134  $this->log->debug('start');
135 
136  parent::startParsing();
137  $this->storeTree();
138  $this->processPagesToParse();
139  $this->copyFileItems();
140  }
processPagesToParse()
parse pages that contain files, mobs and/or internal links
copyFileItems()
copy files of file items
storeTree()
insert StructureObjects and PageObjects into tree
+ Here is the call graph for this function:

◆ storeTree()

ilQuestionPageParser::storeTree ( )

insert StructureObjects and PageObjects into tree

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

References $log, and ilLogger\write().

Referenced by startParsing().

145  : void
146  {
147  $ilLog = $this->log;
148 
149  foreach ($this->st_into_tree as $st) {
150  $this->lm_tree->insertNode($st['id'], $st['parent']);
151  if (is_array($this->pg_into_tree[$st['id']])) {
152  foreach ($this->pg_into_tree[$st['id']] as $pg) {
153  $pg_id = 0;
154  switch ($pg['type']) {
155  case 'pg_alias':
156  if ($this->pg_mapping[$pg['id']] == '') {
157  $ilLog->write('LM Import: No PageObject for PageAlias ' .
158  $pg['id'] . ' found! (Please update export installation to ILIAS 3.3.0)');
159 
160  // Jump two levels up. First level is switch
161  continue 2;
162  }
163  $pg_id = $this->pg_mapping[$pg['id']];
164  break;
165 
166  case 'pg':
167  $pg_id = $pg['id'];
168  break;
169  }
170  if (!$this->lm_tree->isInTree($pg_id)) {
171  $this->lm_tree->insertNode($pg_id, $st['id']);
172  }
173  }
174  }
175  }
176  }
write(string $message, $level=ilLogLevel::INFO, array $context=[])
write log message
+ 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 79 of file class.ilQuestionPageParser.php.

◆ $cnt

array ilQuestionPageParser::$cnt = []

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

◆ $container

array ilQuestionPageParser::$container = []

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

◆ $content_type

string ilQuestionPageParser::$content_type = ''
protected

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

◆ $cur_qid

string ilQuestionPageParser::$cur_qid = ''
protected

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

Referenced by handlerEndTag().

◆ $current_element

array ilQuestionPageParser::$current_element = []

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

◆ $current_object

object ilQuestionPageParser::$current_object = null

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

◆ $file_item

ilObjFile ilQuestionPageParser::$file_item = null

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

◆ $file_item_mapping

array ilQuestionPageParser::$file_item_mapping = []

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

◆ $glossary_object

ilObjGlossary ilQuestionPageParser::$glossary_object = null

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

Referenced by buildTag().

◆ $glossary_term

ilGlossaryTerm ilQuestionPageParser::$glossary_term = null
protected

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

Referenced by buildTag().

◆ $glossary_term_map

array ilQuestionPageParser::$glossary_term_map = []
protected

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

Referenced by getGlossaryTermMap().

◆ $in_file_item

bool ilQuestionPageParser::$in_file_item = false

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

◆ $in_glossary

bool ilQuestionPageParser::$in_glossary = false

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

◆ $in_glossary_definition

bool ilQuestionPageParser::$in_glossary_definition = false
protected

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

Referenced by processMeta().

◆ $in_map_area

bool ilQuestionPageParser::$in_map_area = false

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

◆ $in_media_item

bool ilQuestionPageParser::$in_media_item = false
protected

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

◆ $in_media_object

bool ilQuestionPageParser::$in_media_object = false

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

◆ $in_meta_data

bool ilQuestionPageParser::$in_meta_data = false

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

◆ $in_meta_meta_data

bool ilQuestionPageParser::$in_meta_meta_data = false

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

◆ $in_page_object

bool ilQuestionPageParser::$in_page_object = false

Definition at line 56 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 46 of file class.ilQuestionPageParser.php.

◆ $link_targets

array ilQuestionPageParser::$link_targets = []

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

◆ $lm_page_object

ilLMPageObject ilQuestionPageParser::$lm_page_object = null

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

Referenced by buildTag().

◆ $lm_tree

ilLMTree ilQuestionPageParser::$lm_tree = null

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

◆ $loc_type

string ilQuestionPageParser::$loc_type = ''

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

◆ $log

ilLogger ilQuestionPageParser::$log
protected

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

Referenced by storeTree().

◆ $map_area

ilMapArea ilQuestionPageParser::$map_area = null

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

◆ $mapping

ilImportMapping ilQuestionPageParser::$mapping = null
protected

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

Referenced by setImportMapping().

◆ $media_item

ilMediaItem ilQuestionPageParser::$media_item = null

Definition at line 67 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 50 of file class.ilQuestionPageParser.php.

◆ $metadata_parsing_disabled

bool ilQuestionPageParser::$metadata_parsing_disabled = false

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

◆ $mob_mapping

array ilQuestionPageParser::$mob_mapping = []

Definition at line 65 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 47 of file class.ilQuestionPageParser.php.

◆ $pages_to_parse

array ilQuestionPageParser::$pages_to_parse = []

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

◆ $pg_into_tree

array ilQuestionPageParser::$pg_into_tree = []

Definition at line 53 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 71 of file class.ilQuestionPageParser.php.

◆ $st_into_tree

array ilQuestionPageParser::$st_into_tree = []

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

◆ $structure_objects

array ilQuestionPageParser::$structure_objects = []

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

◆ $tree

ilTree ilQuestionPageParser::$tree

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

Referenced by __construct().


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