00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("content/classes/class.ilLMPageObject.php");
00025 require_once("content/classes/Pages/class.ilPageObject.php");
00026 require_once("content/classes/class.ilStructureObject.php");
00027 require_once("content/classes/class.ilObjLearningModule.php");
00028 require_once("classes/class.ilMetaData.php");
00029 require_once("content/classes/Pages/class.ilPCParagraph.php");
00030 require_once("content/classes/Pages/class.ilPCTable.php");
00031 require_once("content/classes/Media/class.ilObjMediaObject.php");
00032 require_once("content/classes/Media/class.ilMediaItem.php");
00033 require_once("content/classes/Media/class.ilMapArea.php");
00034 require_once("content/classes/class.ilBibItem.php");
00035 require_once("content/classes/class.ilObjGlossary.php");
00036 require_once("content/classes/class.ilGlossaryTerm.php");
00037 require_once("content/classes/class.ilGlossaryDefinition.php");
00038 require_once("content/classes/Pages/class.ilInternalLink.php");
00039 require_once("classes/class.ilObjFile.php");
00040
00050 class ilContObjParser extends ilSaxParser
00051 {
00052 var $lng;
00053 var $tree;
00054 var $cnt;
00055 var $current_element;
00056 var $learning_module;
00057 var $page_object;
00058 var $lm_page_object;
00059 var $structure_objects;
00060 var $media_object;
00061 var $current_object;
00062 var $meta_data;
00063 var $paragraph;
00064 var $table;
00065 var $lm_tree;
00066 var $pg_into_tree;
00067 var $st_into_tree;
00068 var $container;
00069 var $in_page_object;
00070 var $in_meta_data;
00071 var $in_media_object;
00072 var $in_file_item;
00073 var $in_glossary;
00074 var $in_map_area;
00075 var $content_object;
00076 var $glossary_object;
00077 var $file_item;
00078 var $keyword_language;
00079 var $pages_to_parse;
00080 var $mob_mapping;
00081 var $file_item_mapping;
00082 var $subdir;
00083 var $media_item;
00084 var $loc_type;
00085 var $bib_item;
00086 var $map_area;
00087 var $in_bib_item;
00088 var $link_targets;
00089 var $qst_mapping;
00090
00099 function ilContObjParser(&$a_content_object, $a_xml_file, $a_subdir)
00100 {
00101 global $lng, $tree;
00102
00103 parent::ilSaxParser($a_xml_file);
00104 $this->cnt = array();
00105 $this->current_element = array();
00106 $this->structure_objects = array();
00107 $this->content_object =& $a_content_object;
00108
00109 $this->st_into_tree = array();
00110 $this->pg_into_tree = array();
00111 $this->pages_to_parse = array();
00112 $this->mobs_with_int_links = array();
00113 $this->mob_mapping = array();
00114 $this->file_item_mapping = array();
00115 $this->pg_mapping = array();
00116 $this->link_targets = array();
00117 $this->subdir = $a_subdir;
00118 $this->lng =& $lng;
00119 $this->tree =& $tree;
00120 $this->inside_code = false;
00121 $this->qst_mapping = array();
00122 $this->coType = $this->content_object->getType();
00123
00124 if (($this->coType != "tst") and ($this->coType != "qpl"))
00125 {
00126 $this->lm_tree = new ilTree($this->content_object->getId());
00127 $this->lm_tree->setTreeTablePK("lm_id");
00128 $this->lm_tree->setTableNames('lm_tree','lm_data');
00129 }
00130
00131
00132 }
00133
00139 function setHandlers($a_xml_parser)
00140 {
00141 xml_set_object($a_xml_parser,$this);
00142 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00143 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00144 }
00145
00146 function startParsing()
00147 {
00148
00149 parent::startParsing();
00150
00151 $this->storeTree();
00152
00153 $this->processPagesToParse();
00154
00155 $this->copyMobFiles();
00156
00157 $this->copyFileItems();
00158 }
00159
00163 function storeTree()
00164 {
00165 global $ilLog;
00166
00167
00168 foreach($this->st_into_tree as $st)
00169 {
00170
00171 $this->lm_tree->insertNode($st["id"], $st["parent"]);
00172
00173 if (is_array($this->pg_into_tree[$st["id"]]))
00174 {
00175 foreach($this->pg_into_tree[$st["id"]] as $pg)
00176 {
00177 switch ($pg["type"])
00178 {
00179 case "pg_alias":
00180 if ($this->pg_mapping[$pg["id"]] == "")
00181 {
00182 $ilLog->write("LM Import: No PageObject for PageAlias ".$pg["id"]." found! (Please update export installation to ILIAS 3.3.0)");
00183 continue;
00184 }
00185 $pg_id = $this->pg_mapping[$pg["id"]];
00186 break;
00187
00188 case "pg":
00189 $pg_id = $pg["id"];
00190 break;
00191 }
00192 if (!$this->lm_tree->isInTree($pg_id))
00193 {
00194 $this->lm_tree->insertNode($pg_id, $st["id"]);
00195 }
00196 }
00197 }
00198 }
00199
00200
00201 }
00202
00203
00207 function processPagesToParse()
00208 {
00209
00210
00211
00212
00213
00214
00215
00216
00217 foreach($this->pages_to_parse as $page_id)
00218 {
00219 $page_arr = explode(":", $page_id);
00220
00221 switch($page_arr[0])
00222 {
00223 case "lm":
00224 $page_obj =& new ilPageObject($this->content_object->getType(), $page_arr[1]);
00225 break;
00226
00227 case "gdf":
00228 $page_obj =& new ilPageObject("gdf", $page_arr[1]);
00229 break;
00230 }
00231 $page_obj->buildDom();
00232 $page_obj->resolveIntLinks();
00233 $page_obj->update(false);
00234
00235 if ($page_arr[0] == "gdf")
00236 {
00237 $def =& new ilGlossaryDefinition($page_arr[1]);
00238 $def->updateShortText();
00239 }
00240
00241 unset($page_obj);
00242 }
00243
00244
00245
00246 foreach($this->mobs_with_int_links as $mob_id)
00247 {
00248 ilMediaItem::_resolveMapAreaLinks($mob_id);
00249 }
00250
00251
00252
00253 $done = array();
00254 foreach ($this->link_targets as $link_target)
00255 {
00256
00257 $link_arr = explode("_", $link_target);
00258 $target_inst = $link_arr[1];
00259 $target_type = $link_arr[2];
00260 $target_id = $link_arr[3];
00261 $sources = ilInternalLink::_getSourcesOfTarget($target_type, $target_id, $target_inst);
00262 foreach($sources as $key => $source)
00263 {
00264
00265 if(in_array($key, $done))
00266 {
00267 continue;
00268 }
00269 $type_arr = explode(":", $source["type"]);
00270
00271
00272 if ($type_arr[1] == "pg")
00273 {
00274 $page_object = new ilPageObject($type_arr[0], $source["id"]);
00275 $page_object->buildDom();
00276 $page_object->resolveIntLinks();
00277 $page_object->update();
00278 unset($page_object);
00279 }
00280
00281 if ($type_arr[0] == "qst")
00282 {
00283 require_once "./assessment/classes/class.assQuestion.php";
00284 ASS_Question::_resolveIntLinks($source["id"]);
00285 }
00286
00287 if ($type_arr[0] == "sqst")
00288 {
00289 require_once "./survey/classes/class.SurveyQuestion.php";
00290 ASS_Question::_resolveIntLinks($source["id"]);
00291 }
00292 $done[$key] = $key;
00293 }
00294 }
00295 }
00296
00297
00301 function copyMobFiles()
00302 {
00303 $imp_dir = $this->content_object->getImportDirectory();
00304 foreach ($this->mob_mapping as $origin_id => $mob_id)
00305 {
00306 if(empty($origin_id))
00307 {
00308 continue;
00309 }
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 $obj_dir = $origin_id;
00323 $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
00324 $target_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$mob_id;
00325
00326
00327 if (@is_dir($source_dir))
00328 {
00329
00330 ilUtil::makeDir($target_dir);
00331
00332
00333
00334 if (@is_dir($target_dir))
00335 {
00336 ilUtil::rCopy($source_dir, $target_dir);
00337 }
00338 }
00339 }
00340 }
00341
00345 function copyFileItems()
00346 {
00347 $imp_dir = $this->content_object->getImportDirectory();
00348 foreach ($this->file_item_mapping as $origin_id => $file_id)
00349 {
00350 if(empty($origin_id))
00351 {
00352 continue;
00353 }
00354 $obj_dir = $origin_id;
00355 $source_dir = $imp_dir."/".$this->subdir."/objects/".$obj_dir;
00356 $target_dir = ilUtil::getDataDir()."/files/file_".$file_id;
00357
00358
00359 if (@is_dir($source_dir))
00360 {
00361
00362 ilUtil::makeDir($target_dir);
00363
00364
00365
00366 if (@is_dir($target_dir))
00367 {
00368 ilUtil::rCopy($source_dir, $target_dir);
00369 }
00370 }
00371 }
00372 }
00373
00377 function setQuestionMapping($a_map)
00378 {
00379 $this->qst_mapping = $a_map;
00380 }
00381
00382
00383
00384
00385
00386 function beginElement($a_name)
00387 {
00388 if(!isset($this->status["$a_name"]))
00389 {
00390 $this->cnt[$a_name] == 1;
00391 }
00392 else
00393 {
00394 $this->cnt[$a_name]++;
00395 }
00396 $this->current_element[count($this->current_element)] = $a_name;
00397 }
00398
00399
00400
00401
00402 function endElement($a_name)
00403 {
00404 $this->cnt[$a_name]--;
00405 unset ($this->current_element[count($this->current_element) - 1]);
00406 }
00407
00408
00409
00410
00411 function getCurrentElement()
00412 {
00413 return ($this->current_element[count($this->current_element) - 1]);
00414 }
00415
00416
00417
00418
00419 function getOpenCount($a_name)
00420 {
00421 if (isset($this->cnt[$a_name]))
00422 {
00423 return $this->cnt[$a_name];
00424 }
00425 else
00426 {
00427 return 0;
00428 }
00429
00430 }
00431
00439 function buildTag ($type, $name, $attr="")
00440 {
00441 $tag = "<";
00442
00443 if ($type == "end")
00444 $tag.= "/";
00445
00446 $tag.= $name;
00447
00448 if (is_array($attr))
00449 {
00450 while (list($k,$v) = each($attr))
00451 $tag.= " ".$k."=\"$v\"";
00452 }
00453
00454 $tag.= ">";
00455
00456 return $tag;
00457 }
00458
00462 function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00463 {
00464
00465 switch($a_name)
00466 {
00467 case "ContentObject":
00468 $this->current_object =& $this->content_object;
00469
00470 if ($a_attribs["Type"] == "Glossary")
00471 {
00472 $this->glossary_object =& $this->content_object;
00473 }
00474 break;
00475
00476 case "StructureObject":
00477
00478 $this->structure_objects[count($this->structure_objects)]
00479 =& new ilStructureObject($this->content_object);
00480 $this->current_object =& $this->structure_objects[count($this->structure_objects) - 1];
00481 $this->current_object->setLMId($this->content_object->getId());
00482 break;
00483
00484 case "PageObject":
00485 $this->in_page_object = true;
00486 $this->cur_qid = "";
00487 if (($this->coType != "tst") and ($this->coType != "qpl"))
00488 {
00489 $this->lm_page_object =& new ilLMPageObject($this->content_object);
00490 $this->page_object =& new ilPageObject($this->content_object->getType());
00491 $this->lm_page_object->setLMId($this->content_object->getId());
00492 $this->lm_page_object->assignPageObject($this->page_object);
00493 $this->current_object =& $this->lm_page_object;
00494 }
00495 else
00496 {
00497 $this->page_object =& new ilPageObject("qpl");
00498 }
00499 break;
00500
00501 case "PageAlias":
00502 if (($this->coType != "tst") and ($this->coType != "qpl"))
00503 {
00504 $this->lm_page_object->setAlias(true);
00505 $this->lm_page_object->setOriginID($a_attribs["OriginId"]);
00506 }
00507 break;
00508
00509 case "MediaObject":
00510 $this->in_media_object = true;
00511 $this->media_object =& new ilObjMediaObject();
00512 break;
00513
00514 case "MediaAlias":
00515
00516 $this->media_object->setAlias(true);
00517 $this->media_object->setOriginID($a_attribs["OriginId"]);
00518 if (is_object($this->page_object))
00519 {
00520 $this->page_object->needsImportParsing(true);
00521 }
00522 break;
00523
00524 case "MediaItem":
00525 case "MediaAliasItem":
00526 $this->in_media_item = true;
00527 $this->media_item =& new ilMediaItem();
00528 $this->media_item->setPurpose($a_attribs["Purpose"]);
00529 break;
00530
00531 case "Layout":
00532 if (is_object($this->media_object) && $this->in_media_object)
00533 {
00534 $this->media_item->setWidth($a_attribs["Width"]);
00535 $this->media_item->setHeight($a_attribs["Height"]);
00536 $this->media_item->setHAlign($a_attribs["HorizontalAlign"]);
00537 }
00538 break;
00539
00540 case "Parameter":
00541 if (is_object($this->media_object) && $this->in_media_object)
00542 {
00543 $this->media_item->setParameter($a_attribs["Name"], $a_attribs["Value"]);
00544 }
00545 break;
00546
00547 case "MapArea":
00548 $this->in_map_area = true;
00549 $this->map_area =& new ilMapArea();
00550 $this->map_area->setShape($a_attribs["Shape"]);
00551 $this->map_area->setCoords($a_attribs["Coords"]);
00552 break;
00553
00554 case "Glossary":
00555 $this->in_glossary = true;
00556 if ($this->content_object->getType() != "glo")
00557 {
00558 $this->glossary_object =& new ilObjGlossary();
00559 $this->glossary_object->setTitle("");
00560 $this->glossary_object->setDescription("");
00561 $this->glossary_object->create();
00562 $this->glossary_object->createReference();
00563 $parent =& $this->tree->getParentNodeData($this->content_object->getRefId());
00564 $this->glossary_object->putInTree($parent["child"]);
00565 $this->glossary_object->setPermissions($parent["child"]);
00566 $this->glossary_object->notify("new", $_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$this->glossary_object->getRefId());
00567 }
00568 $this->current_object =& $this->glossary_object;
00569 break;
00570
00571 case "GlossaryItem":
00572 $this->glossary_term =& new ilGlossaryTerm();
00573 $this->glossary_term->setGlossaryId($this->glossary_object->getId());
00574 $this->glossary_term->setLanguage($a_attribs["Language"]);
00575 $this->glossary_term->setImportId($a_attribs["Id"]);
00576 $this->link_targets[$a_attribs["Id"]] = $a_attribs["Id"];
00577 break;
00578
00579 case "Definition":
00580 $this->in_glossary_definition = true;
00581 $this->glossary_definition =& new ilGlossaryDefinition();
00582 $this->page_object =& new ilPageObject("gdf");
00583 $this->glossary_definition->setTermId($this->glossary_term->getId());
00584 $this->glossary_definition->assignPageObject($this->page_object);
00585 $this->current_object =& $this->glossary_definition;
00586 break;
00587
00588 case "FileItem":
00589 $this->in_file_item = true;
00590 $this->file_item =& new ilObjFile();
00591 $this->file_item->setTitle("dummy");
00592 if (is_object($this->page_object))
00593 {
00594 $this->page_object->needsImportParsing(true);
00595 }
00596 break;
00597
00598 case "Paragraph":
00599 if ($a_attribs["Characteristic"] == "Code")
00600 {
00601 $this->inside_code = true;
00602 }
00603 break;
00604
00605
00609 case "MetaData":
00610 $this->in_meta_data = true;
00611
00612 $this->meta_data =& new ilMetaData();
00613 if(!$this->in_media_object)
00614 {
00615
00616 if (($this->coType != "tst") and ($this->coType != "qpl"))
00617 {
00618 $this->current_object->assignMetaData($this->meta_data);
00619 if (strtolower(get_class($this->current_object)) == "ilobjlearningmodule")
00620 {
00621 $this->meta_data->setId($this->content_object->getId());
00622 $this->meta_data->setType("lm");
00623 }
00624 }
00625 }
00626 else
00627 {
00628 $this->media_object->assignMetaData($this->meta_data);
00629 }
00630 break;
00631
00632
00633 case "Identifier":
00634 if ($this->in_meta_data)
00635 {
00636 $this->meta_data->setImportIdentifierEntryID($a_attribs["Entry"]);
00637 $this->link_targets[$a_attribs["Entry"]] = $a_attribs["Entry"];
00638 }
00639 if ($this->in_file_item)
00640 {
00641 if ($this->file_item_mapping[$a_attribs["Entry"]] == "")
00642 {
00643 $this->file_item->create();
00644 $this->file_item->setImportId($a_attribs["Entry"]);
00645 $this->file_item_mapping[$a_attribs["Entry"]] = $this->file_item->getId();
00646 }
00647 }
00648 break;
00649
00650
00651 case "Keyword":
00652
00653 $this->keyword_language = $a_attribs["Language"];
00654 break;
00655
00656
00657 case "IntLink":
00658 if (is_object($this->page_object))
00659 {
00660 $this->page_object->setContainsIntLink(true);
00661 }
00662 if ($this->in_map_area)
00663 {
00664
00665 $this->map_area->setLinkType(IL_INT_LINK);
00666 $this->map_area->setTarget($a_attribs["Target"]);
00667 $this->map_area->setType($a_attribs["Type"]);
00668 $this->map_area->setTargetFrame($a_attribs["TargetFrame"]);
00669 if (is_object($this->media_object))
00670 {
00671
00672 $this->media_object->setContainsIntLink(true);
00673 }
00674 }
00675 break;
00676
00677
00678 case "ExtLink":
00679 if ($this->in_map_area)
00680 {
00681 $this->map_area->setLinkType(IL_EXT_LINK);
00682 $this->map_area->setHref($a_attribs["Href"]);
00683 $this->map_area->setExtTitle($a_attribs["Title"]);
00684 }
00685 break;
00686
00687
00688 case "Question":
00689 $this->cur_qid = $a_attribs["QRef"];
00690 break;
00691
00692
00693 case "Technical":
00694 $this->meta_technical =& new ilMetaTechnical($this->meta_data);
00695 $this->meta_data->addTechnicalSection($this->meta_technical);
00696
00697 break;
00698
00699
00700 case "Size":
00701 $this->meta_technical->setSize($a_attribs["Size"]);
00702 break;
00703
00704 case "Location":
00705 $this->loc_type = $a_attribs["Type"];
00706 break;
00707
00708
00709 case "Requirement":
00710 if (!is_object($this->requirement_set))
00711 {
00712 $this->requirement_set =& new ilMetaTechnicalRequirementSet();
00713 }
00714 $this->requirement =& new ilMetaTechnicalRequirement();
00715 break;
00716
00717
00718 case "OperatingSystem":
00719 $this->requirement->setType("OperatingSystem");
00720 $this->requirement->setName($a_attribs["Name"]);
00721 $this->requirement->setMinVersion($a_attribs["MinimumVersion"]);
00722 $this->requirement->setMaxVersion($a_attribs["MaximumVersion"]);
00723 break;
00724
00725
00726 case "Browser":
00727 $this->requirement->setType("Browser");
00728 $this->requirement->setName($a_attribs["Name"]);
00729 $this->requirement->setMinVersion($a_attribs["MinimumVersion"]);
00730 $this->requirement->setMaxVersion($a_attribs["MaximumVersion"]);
00731 break;
00732
00733
00734 case "OrComposite":
00735 $this->meta_technical->addRequirementSet($this->requirement_set);
00736 unset($this->requirement_set);
00737 break;
00738
00739
00740 case "InstallationRemarks":
00741 $this->meta_technical->setInstallationRemarksLanguage($a_attribs["Language"]);
00742 break;
00743
00744
00745 case "OtherPlatformRequirements":
00746 $this->meta_technical->setOtherRequirementsLanguage($a_attribs["Language"]);
00747 break;
00748
00749 case "Bibliography":
00750 $this->in_bib_item = true;
00751 #echo "<br>---NEW BIBLIOGRAPHY---<br>";
00752 $this->bib_item =& new ilBibItem();
00753 break;
00754
00755 }
00756 $this->beginElement($a_name);
00757
00758
00759
00760 if(($this->in_page_object || $this->in_glossary_definition)
00761 && !$this->in_meta_data && !$this->in_media_object)
00762 {
00763 if ($a_name == "Definition")
00764 {
00765 $app_name = "PageObject";
00766 $app_attribs = array();
00767 }
00768 else
00769 {
00770 $app_name = $a_name;
00771 $app_attribs = $a_attribs;
00772 }
00773
00774
00775 if ($this->in_file_item && $app_name == "Identifier")
00776 {
00777 $app_attribs["Entry"] = "il__file_".$this->file_item_mapping[$a_attribs["Entry"]];
00778
00779 }
00780
00781 $this->page_object->appendXMLContent($this->buildTag("start", $app_name, $app_attribs));
00782
00783 }
00784
00785 if ($this->in_meta_data )
00786 {
00787 $this->meta_data->appendXMLContent("\n".$this->buildTag("start", $a_name, $a_attribs));
00788 }
00789
00790 if ($this->in_bib_item)
00791 {
00792 $this->bib_item->appendXMLContent("\n".$this->buildTag("start", $a_name, $a_attribs));
00793 }
00794 }
00795
00796
00800 function handlerEndTag($a_xml_parser,$a_name)
00801 {
00802
00803
00804 if (($this->in_page_object || $this->in_glossary_definition)
00805 && !$this->in_meta_data && !$this->in_media_object)
00806 {
00807 $app_name = ($a_name == "Definition")
00808 ? "PageObject"
00809 : $a_name;
00810 $this->page_object->appendXMLContent($this->buildTag("end", $app_name));
00811 }
00812
00813 if ($this->in_meta_data)
00814
00815
00816 if($a_name == "MetaData")
00817 {
00818 $this->meta_data->appendXMLContent("\n".$this->buildTag("end", $a_name));
00819 }
00820 else
00821 {
00822 $this->meta_data->appendXMLContent($this->buildTag("end", $a_name));
00823 }
00824
00825
00826 if ($this->in_bib_item)
00827 {
00828 if($a_name == "BibItem")
00829 {
00830 $this->bib_item->appendXMLContent("\n".$this->buildTag("end", $a_name));
00831 }
00832 else
00833 {
00834 $this->bib_item->appendXMLContent($this->buildTag("end", $a_name));
00835 }
00836
00837 }
00838
00839 switch($a_name)
00840 {
00841 case "StructureObject":
00842 unset($this->meta_data);
00843 unset($this->structure_objects[count($this->structure_objects) - 1]);
00844 break;
00845
00846 case "PageObject":
00847
00848 $this->in_page_object = false;
00849 if (($this->coType != "tst") and ($this->coType != "qpl"))
00850 {
00851 if (!$this->lm_page_object->isAlias())
00852 {
00853
00854 $this->page_object->updateFromXML();
00855 $this->pg_mapping[$this->lm_page_object->getImportId()]
00856 = $this->lm_page_object->getId();
00857
00858
00859 if ($this->page_object->containsIntLink())
00860 {
00861
00862 $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
00863 }
00864 if ($this->page_object->needsImportParsing())
00865 {
00866
00867 $this->pages_to_parse["lm:".$this->page_object->getId()] = "lm:".$this->page_object->getId();
00868 }
00869 }
00870 }
00871 else
00872 {
00873 $xml = $this->page_object->getXMLContent();
00874 if ($this->cur_qid != "")
00875 {
00876 $ids = $this->qst_mapping[$this->cur_qid];
00877 if ($ids["pool"] > 0)
00878 {
00879
00880 $page = new ilPageObject("qpl", $ids["pool"]);
00881 $xmlcontent = str_replace($this->cur_qid,
00882 "il__qst_".$ids["pool"], $xml);
00883 $page->setXMLContent($xmlcontent);
00884 $page->saveMobUsage($xmlcontent);
00885 $page->updateFromXML();
00886 unset($page);
00887 }
00888 if ($ids["test"] > 0)
00889 {
00890
00891 $page = new ilPageObject("qpl", $ids["test"]);
00892 $xmlcontent = str_replace($this->cur_qid,
00893 "il__qst_".$ids["test"], $xml);
00894 $page->setXMLContent($xmlcontent);
00895 $page->saveMobUsage($xmlcontent);
00896 $page->updateFromXML();
00897 unset($page);
00898 }
00899 }
00900 }
00901
00902
00903 $cnt = count($this->structure_objects);
00904 if ($cnt > 0)
00905 {
00906 $parent_id = $this->structure_objects[$cnt - 1]->getId();
00907 if ($this->lm_page_object->isAlias())
00908 {
00909 $this->pg_into_tree[$parent_id][] = array("type" => "pg_alias", "id" => $this->lm_page_object->getOriginId());
00910 }
00911 else
00912 {
00913 $this->pg_into_tree[$parent_id][] = array("type" => "pg", "id" => $this->lm_page_object->getId());
00914 }
00915 }
00916
00917
00918 unset($this->meta_data);
00919 unset($this->page_object);
00920 unset($this->lm_page_object);
00921 unset ($this->container[count($this->container) - 1]);
00922 break;
00923
00924 case "MediaObject":
00925 $this->in_media_object = false;
00926
00927
00928 if(empty($this->mob_mapping[$this->media_object->getImportId()]))
00929 {
00930 if ($this->media_object->isAlias())
00931 {
00932
00933
00934 $dummy_meta =& new ilMetaData();
00935 $this->media_object->assignMetaData($dummy_meta);
00936 $this->media_object->setTitle("dummy");
00937
00938 }
00939 else
00940 {
00941
00942 $this->media_object->setTitle($this->meta_data->getTitle());
00943 }
00944
00945
00946
00947
00948 $this->media_object->create();
00949
00950
00951
00952 if ($this->media_object->containsIntLink())
00953 {
00954
00955 $this->mobs_with_int_links[] = $this->media_object->getId();
00956 }
00957
00958 $this->mob_mapping[$this->media_object->getImportId()]
00959 = $this->media_object->getId();
00960
00961 }
00962 else
00963 {
00964
00965 $this->media_object->setId($this->mob_mapping[$this->media_object->getImportId()]);
00966
00967
00968
00969
00970
00971
00972 if (!$this->media_object->isAlias())
00973 {
00974
00975
00976
00977
00978
00979
00980 $this->meta_data->setId($this->media_object->getId());
00981 $this->meta_data->setType("mob");
00982 $this->media_object->assignMetaData($this->meta_data);
00983 $this->media_object->setTitle($this->meta_data->getTitle());
00984 $this->media_object->setDescription($this->meta_data->getDescription());
00985
00986 $this->media_object->update();
00987
00988
00989
00990
00991
00992 if ($this->media_object->containsIntLink())
00993 {
00994
00995 $this->mobs_with_int_links[] = $this->media_object->getId();
00996 }
00997 }
00998 }
00999
01000
01001 if ($this->in_page_object || $this->in_glossary_definition)
01002 {
01003 $this->page_object->appendXMLContent($this->media_object->getXML(IL_MODE_ALIAS));
01004
01005 }
01006
01007 break;
01008
01009 case "MediaItem":
01010 case "MediaAliasItem":
01011 $this->in_media_item = false;
01012 $this->media_object->addMediaItem($this->media_item);
01013
01014 break;
01015
01016 case "MapArea":
01017 $this->in_map_area = false;
01018 $this->media_item->addMapArea($this->map_area);
01019 break;
01020
01021
01022 case "MetaData":
01023 $this->in_meta_data = false;
01024 if(strtolower(get_class($this->current_object)) == "illmpageobject" && !$this->in_media_object)
01025 {
01026
01027 if (is_object($this->lm_page_object))
01028 {
01029 $this->lm_page_object->create(true);
01030
01031
01032 include_once("./classes/class.ilNestedSetXML.php");
01033 $nested = new ilNestedSetXML();
01034 $xml = $this->meta_data->getXMLContent();
01035
01036 $nested->dom = domxml_open_mem($xml);
01037 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
01038 if (is_array($nodes))
01039 {
01040 $nodes[0]["Entry"] = "il__" . $this->current_object->getType() . "_" . $this->current_object->getId();
01041 $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
01042 }
01043 $xml = $nested->dom->dump_mem(0);
01044
01045
01046 $nested->import($xml,$this->lm_page_object->getId(),"pg");
01047 }
01048 }
01049 else if((strtolower(get_class($this->current_object)) == "ilobjquestionpool" ||
01050 strtolower(get_class($this->current_object)) == "ilobjtest") &&
01051 !$this->in_media_object && !$this->in_page_object)
01052 {
01053
01054 include_once("./classes/class.ilNestedSetXML.php");
01055 $nested = new ilNestedSetXML();
01056 $xml = $this->meta_data->getXMLContent();
01057
01058 $nested->dom = domxml_open_mem($xml);
01059 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
01060 if (is_array($nodes))
01061 {
01062 $nodes[0]["Entry"] = "il__" . $this->current_object->getType() . "_" . $this->current_object->getId();
01063 $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
01064 }
01065 $xml = $nested->dom->dump_mem(0);
01066
01067
01068 $nested->import($xml, $this->current_object->getId(), $this->current_object->getType());
01069 }
01070 else if(strtolower(get_class($this->current_object)) == "ilstructureobject")
01071 {
01072
01073 $cnt = count($this->structure_objects);
01074 if ($cnt > 1)
01075 {
01076 $parent_id = $this->structure_objects[$cnt - 2]->getId();
01077 }
01078 else
01079 {
01080 $parent_id = $this->lm_tree->getRootId();
01081 }
01082
01083
01084 $this->current_object->create(true);
01085 $this->st_into_tree[] = array ("id" => $this->current_object->getId(),
01086 "parent" => $parent_id);
01087
01088
01089 include_once("./classes/class.ilNestedSetXML.php");
01090 $nested = new ilNestedSetXML();
01091 $xml = $this->meta_data->getXMLContent();
01092 $nested->dom = domxml_open_mem($xml);
01093 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
01094 if (is_array($nodes))
01095 {
01096 $nodes[0]["Entry"] = "il__" . $this->current_object->getType() . "_" . $this->current_object->getId();
01097 $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
01098 }
01099 $xml = $nested->dom->dump_mem(0);
01100 $nested->import($xml,$this->current_object->getId(),"st");
01101 }
01102 else if(strtolower(get_class($this->current_object)) == "ilobjdlbook" || strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
01103 strtolower(get_class($this->current_object)) == "ilobjcontentobject" ||
01104 (strtolower(get_class($this->current_object)) == "ilobjglossary" && $this->in_glossary))
01105 {
01106
01107 include_once("./classes/class.ilNestedSetXML.php");
01108 $nested = new ilNestedSetXML();
01109 $xml = $this->meta_data->getXMLContent();
01110 $nested->dom = domxml_open_mem($xml);
01111 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
01112 if (is_array($nodes))
01113 {
01114 $nodes[0]["Entry"] = "il__" . $this->current_object->getType() . "_" . $this->current_object->getId();
01115 $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
01116 }
01117 $xml = $nested->dom->dump_mem(0);
01118
01119
01120
01121 $nested->import($xml,$this->current_object->getId(),$this->current_object->getType());
01122 }
01123 else if(strtolower(get_class($this->current_object)) == "ilglossarydefinition" && !$this->in_media_object)
01124 {
01125
01126 $this->glossary_definition->create();
01127
01128 $this->page_object->setId($this->glossary_definition->getId());
01129 $this->page_object->updateFromXML();
01130
01131
01132 include_once("./classes/class.ilNestedSetXML.php");
01133 $nested = new ilNestedSetXML();
01134 $xml = $this->meta_data->getXMLContent();
01135 $nested->dom = domxml_open_mem($xml);
01136 $nodes = $nested->getDomContent("//MetaData/General", "Identifier");
01137 if (is_array($nodes))
01138 {
01139 $nodes[0]["Entry"] = "il__" . $this->current_object->getType() . "_" . $this->current_object->getId();
01140 $nested->updateDomContent("//MetaData/General", "Identifier", 0, $nodes[0]);
01141 }
01142 $xml = $nested->dom->dump_mem(0);
01143
01144
01145 $nested->import($xml,$this->glossary_definition->getId(),"gdf");
01146 }
01147
01148
01149 if(strtolower(get_class($this->current_object)) == "ilobjlearningmodule" ||
01150 strtolower(get_class($this->current_object)) == "ilobjdlbook" ||
01151 strtolower(get_class($this->current_object)) == "ilobjglossary")
01152 {
01153 if (strtolower(get_class($this->current_object)) == "ilobjglossary" &&
01154 $this->content_object->getType() != "glo")
01155 {
01156
01157 $this->current_object->setTitle($this->content_object->getTitle()." - ".
01158 $this->lng->txt("glossary"));
01159 }
01160 $this->current_object->update();
01161 }
01162
01163 # echo "Type: " . $this->current_object->getType() . "<br>\n";
01164 # echo "Obj.-ID: " . $this->current_object->getId() . "<br>\n";
01165 break;
01166
01167 case "FileItem":
01168 $this->in_file_item = false;
01169
01170 if ($this->file_item->getImportId($a_attribs["Entry"] != ""))
01171 {
01172 $this->file_item->update();
01173 }
01174 break;
01175
01176 case "Bibliography":
01177
01178 $this->in_bib_item = false;
01179
01180 $nested = new ilNestedSetXML();
01181 $nested->import($this->bib_item->getXMLContent(),$this->content_object->getId(),"bib");
01182 break;
01183
01184 case "Table":
01185 unset ($this->container[count($this->container) - 1]);
01186 break;
01187
01188 case "Glossary":
01189 $this->in_glossary = false;
01190 break;
01191
01192 case "GlossaryTerm":
01193 $this->glossary_term->setTerm(trim($this->chr_data));
01194 $this->glossary_term->create();
01195 break;
01196
01197 case "Paragraph":
01198 $this->inside_code = false;
01199 break;
01200
01201 case "Definition":
01202 $this->in_glossary_definition = false;
01203 $this->page_object->updateFromXML();
01204 $this->page_object->buildDom();
01205 $this->glossary_definition->setShortText($this->page_object->getFirstParagraphText());
01206 $this->glossary_definition->update();
01207
01208
01209 if ($this->page_object->containsIntLink())
01210 {
01211
01212 $this->pages_to_parse["gdf:".$this->page_object->getId()] = "gdf:".$this->page_object->getId();
01213 }
01214 break;
01215
01216 case "Format":
01217 if ($this->in_media_item)
01218 {
01219 $this->media_item->setFormat(trim($this->chr_data));
01220 }
01221 if ($this->in_meta_data)
01222 {
01223 $this->meta_technical->addFormat($this->chr_data);
01224 }
01225 if ($this->in_file_item)
01226 {
01227 $this->file_item->setFileType(trim($this->chr_data));
01228 }
01229 break;
01230
01231 case "Title":
01232 if (!$this->in_media_object)
01233 {
01234 $this->current_object->setTitle(trim($this->chr_data));
01235 $this->meta_data->setTitle(trim($this->chr_data));
01236 }
01237 else
01238 {
01239 $this->media_object->setTitle(trim($this->chr_data));
01240 $this->meta_data->setTitle(trim($this->chr_data));
01241 }
01242 break;
01243
01244 case "Language":
01245 if (is_object($this->meta_data))
01246 {
01247 $this->meta_data->setLanguage(trim($this->chr_data));
01248 }
01249 else if (is_object($this->bib_item))
01250 {
01251 $this->bib_item->setLanguage(trim($this->chr_data));
01252 }
01253 break;
01254
01255 case "Description":
01256 $this->meta_data->setDescription(trim($this->chr_data));
01257 break;
01258
01259 case "Caption":
01260 if ($this->in_media_object)
01261 {
01262 $this->media_item->setCaption(trim($this->chr_data));
01263 }
01264 break;
01265
01266
01267 case "Location":
01268
01269 if ($this->in_media_item)
01270 {
01271 $this->media_item->setLocationType($this->loc_type);
01272 $this->media_item->setLocation(trim($this->chr_data));
01273 }
01274 if ($this->in_meta_data)
01275 {
01276
01277 }
01278 if ($this->in_file_item)
01279 {
01280
01281 $this->file_item->setFileName(trim($this->chr_data));
01282
01283
01284
01285 if ($this->file_item->getType() == "file" &&
01286 is_int(strpos($this->chr_data, "&")) &&
01287 is_int(strpos($this->chr_data, ";")))
01288 {
01289 $imp_dir = $this->content_object->getImportDirectory();
01290 $source_dir = $imp_dir."/".$this->subdir."/objects/".
01291 $this->file_item->getImportId();
01292
01293
01294 if ($dir = opendir($source_dir))
01295 {
01296 while (false !== ($file = readdir($dir)))
01297 {
01298 if ($file != "." && $file != "..")
01299 {
01300 $this->file_item->setFileName($file);
01301 }
01302 }
01303 closedir($dir);
01304 }
01305 }
01306
01307
01308 $this->file_item->setTitle(trim($this->chr_data));
01309 }
01310 break;
01311
01315
01316
01317
01318
01319
01320
01321
01322 }
01323 $this->endElement($a_name);
01324 $this->chr_data = "";
01325 }
01326
01330 function handlerCharacterData($a_xml_parser,$a_data)
01331 {
01332
01333
01334
01335
01336
01337 if ($this->in_meta_data)
01338 {
01339 $a_data = preg_replace("/&(?!amp;)/","&",$a_data);
01340 }
01341
01342 $a_data = str_replace("<","<",$a_data);
01343 $a_data = str_replace(">",">",$a_data);
01344
01345
01346
01347 $a_data = preg_replace("/\n/","",$a_data);
01348 if (!$this->inside_code)
01349 {
01350 $a_data = preg_replace("/\t+/","",$a_data);
01351 }
01352
01353 $this->chr_data .= $a_data;
01354
01355 if(!empty($a_data))
01356 {
01357
01358
01359 if (($this->in_page_object || $this->in_glossary_definition)
01360 && !$this->in_meta_data && !$this->in_media_object)
01361 {
01362 $this->page_object->appendXMLContent($a_data);
01363 }
01364
01365 if ($this->in_meta_data )
01366 {
01367 $this->meta_data->appendXMLContent($a_data);
01368
01369 }
01370
01371 if ($this->in_bib_item )
01372 {
01373 $this->bib_item->appendXMLContent($a_data);
01374 }
01375
01376 switch($this->getCurrentElement())
01377 {
01378
01379 case "IntLink":
01380 case "ExtLink":
01381 if($this->in_map_area)
01382 {
01383 $this->map_area->appendTitle($a_data);
01384 }
01385 break;
01386
01387 }
01388 }
01389
01390 }
01391
01392 }
01393 ?>