ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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:22
__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 299 of file class.ilQuestionPageParser.php.

Referenced by buildTag().

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

◆ buildTag()

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

Definition at line 328 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().

332  : string {
333  $tag = '<';
334 
335  if ($type == 'end') {
336  $tag .= '/';
337  }
338 
339  $tag .= $name;
340 
341  if (is_array($attr)) {
342  foreach ($attr as $k => $v) {
343  $tag .= ' ' . $k . "='$v'";
344  }
345  }
346 
347  $tag .= '>';
348 
349  return $tag;
350  }
+ 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 268 of file class.ilQuestionPageParser.php.

Referenced by startParsing().

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

◆ emptyMediaMetaCache()

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

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

Referenced by buildTag().

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

◆ endElement()

ilQuestionPageParser::endElement ( string  $a_name)

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

Referenced by handlerEndTag().

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

◆ getCurrentElement()

ilQuestionPageParser::getCurrentElement ( )

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

Referenced by handlerCharacterData().

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

◆ getGlossaryTermMap()

ilQuestionPageParser::getGlossaryTermMap ( )
Returns
mixed[]

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

References $glossary_term_map.

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

◆ getOpenCount()

ilQuestionPageParser::getOpenCount ( string  $a_name)

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

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

◆ handlerCharacterData()

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

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

References getCurrentElement(), and processMeta().

Referenced by setHandlers().

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

◆ handlerEndTag()

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

Definition at line 834 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().

Referenced by setHandlers().

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

References ILIAS\Repository\int(), and null.

Referenced by buildTag(), and processPagesToParse().

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

◆ processMeta()

ilQuestionPageParser::processMeta ( )

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

References $in_glossary_definition.

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

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

◆ processPagesToParse()

ilQuestionPageParser::processPagesToParse ( )

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

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

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

Referenced by startParsing().

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

References ilMDSaxParser\handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

120  : void
121  {
122  xml_set_element_handler($xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
123  xml_set_character_data_handler($xml_parser, $this->handlerCharacterData(...));
124  }
handlerEndTag($a_xml_parser, string $a_name)
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handlerCharacterData($a_xml_parser, string $a_data)
+ Here is the call graph for this function:

◆ setImportMapping()

ilQuestionPageParser::setImportMapping ( ?ilImportMapping  $mapping = null)

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

References $mapping.

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

◆ setQuestionMapping()

ilQuestionPageParser::setQuestionMapping ( array  $a_map)

set question import ident to pool/test question id mapping

Parameters
mixed[]$a_map

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

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

◆ startParsing()

ilQuestionPageParser::startParsing ( )

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

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

131  : void
132  {
133  $this->log->debug('start');
134 
135  parent::startParsing();
136  $this->storeTree();
137  $this->processPagesToParse();
138  $this->copyFileItems();
139  }
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 144 of file class.ilQuestionPageParser.php.

References $log, and ilLogger\write().

Referenced by startParsing().

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