ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjGlossary.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Services/Object/classes/class.ilObject.php");
6 require_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
7 
19 class ilObjGlossary extends ilObject
20 {
21 
26  function ilObjGlossary($a_id = 0,$a_call_by_reference = true)
27  {
28  $this->type = "glo";
29  $this->ilObject($a_id,$a_call_by_reference);
30  }
31 
35  function create($a_upload = false)
36  {
37  global $ilDB;
38 
40 
41  // meta data will be created by
42  // import parser
43  if (!$a_upload)
44  {
45  $this->createMetaData();
46  }
47 
48  $ilDB->manipulate("INSERT INTO glossary (id, is_online, virtual, pres_mode, snippet_length) VALUES (".
49  $ilDB->quote($this->getId(), "integer").",".
50  $ilDB->quote("n", "text").",".
51  $ilDB->quote($this->getVirtualMode(), "text").",".
52  $ilDB->quote("table", "text").",".
53  $ilDB->quote(200, "integer").
54  ")");
55  $this->setPresentationMode("table");
56  $this->setSnippetLength(200);
57 
58  if (((int) $this->getStyleSheetId()) > 0)
59  {
60  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
62  }
63 
64  }
65 
69  function read()
70  {
71  global $ilDB;
72 
73  parent::read();
74 # echo "Glossary<br>\n";
75 
76  $q = "SELECT * FROM glossary WHERE id = ".
77  $ilDB->quote($this->getId(), "integer");
78  $gl_set = $ilDB->query($q);
79  $gl_rec = $ilDB->fetchAssoc($gl_set);
80  $this->setOnline(ilUtil::yn2tf($gl_rec["is_online"]));
81  $this->setVirtualMode($gl_rec["virtual"]);
82  $this->setPublicExportFile("xml", $gl_rec["public_xml_file"]);
83  $this->setPublicExportFile("html", $gl_rec["public_html_file"]);
84  $this->setActiveGlossaryMenu(ilUtil::yn2tf($gl_rec["glo_menu_active"]));
85  $this->setActiveDownloads(ilUtil::yn2tf($gl_rec["downloads_active"]));
86  $this->setPresentationMode($gl_rec["pres_mode"]);
87  $this->setSnippetLength($gl_rec["snippet_length"]);
88  $this->setShowTaxonomy($gl_rec["show_tax"]);
89 
90  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
92 
93  }
94 
100  function getDescription()
101  {
102  return parent::getDescription();
103  }
104 
108  function setDescription($a_description)
109  {
110  parent::setDescription($a_description);
111  }
112 
113 
117  function setVirtualMode($a_mode)
118  {
119  switch ($a_mode)
120  {
121  case "level":
122  case "subtree":
123  // case "fixed":
124  $this->virtual_mode = $a_mode;
125  $this->virtual = true;
126  break;
127 
128  default:
129  $this->virtual_mode = "none";
130  $this->virtual = false;
131  break;
132  }
133  }
134 
138  function getVirtualMode()
139  {
140  return $this->virtual_mode;
141  }
142 
146  function isVirtual()
147  {
148  return $this->virtual;
149  }
150 
156  function getTitle()
157  {
158  return parent::getTitle();
159  }
160 
164  function setTitle($a_title)
165  {
166  parent::setTitle($a_title);
167 // $this->meta_data->setTitle($a_title);
168  }
169 
175  function setPresentationMode($a_val)
176  {
177  $this->pres_mode = $a_val;
178  }
179 
186  {
187  return $this->pres_mode;
188  }
189 
195  function setSnippetLength($a_val)
196  {
197  $this->snippet_length = $a_val;
198  }
199 
205  function getSnippetLength()
206  {
207  return $this->snippet_length;
208  }
209 
210  function setOnline($a_online)
211  {
212  $this->online = $a_online;
213  }
214 
215  function getOnline()
216  {
217  return $this->online;
218  }
219 
223  function _lookupOnline($a_id)
224  {
225  global $ilDB;
226 
227  $q = "SELECT is_online FROM glossary WHERE id = ".
228  $ilDB->quote($a_id, "integer");
229  $lm_set = $ilDB->query($q);
230  $lm_rec = $ilDB->fetchAssoc($lm_set);
231 
232  return ilUtil::yn2tf($lm_rec["is_online"]);
233  }
234 
241  static protected function lookup($a_id, $a_property)
242  {
243  global $ilDB;
244 
245  $set = $ilDB->query("SELECT $a_property FROM glossary WHERE id = ".
246  $ilDB->quote($a_id, "integer"));
247  $rec = $ilDB->fetchAssoc($set);
248 
249  return $rec[$a_property];
250  }
251 
258  static function lookupSnippetLength($a_id)
259  {
260  return ilObjGlossary::lookup($a_id, "snippet_length");
261  }
262 
263 
264  function setActiveGlossaryMenu($a_act_glo_menu)
265  {
266  $this->glo_menu_active = $a_act_glo_menu;
267  }
268 
270  {
271  return $this->glo_menu_active;
272  }
273 
274  function setActiveDownloads($a_down)
275  {
276  $this->downloads_active = $a_down;
277  }
278 
279  function isActiveDownloads()
280  {
281  return $this->downloads_active;
282  }
283 
287  function getStyleSheetId()
288  {
289  return $this->style_id;
290  }
291 
295  function setStyleSheetId($a_style_id)
296  {
297  $this->style_id = $a_style_id;
298  }
299 
300 
306  function setShowTaxonomy($a_val)
307  {
308  $this->show_tax = $a_val;
309  }
310 
316  function getShowTaxonomy()
317  {
318  return $this->show_tax;
319  }
320 
324  function update()
325  {
326  global $ilDB;
327 
328  $this->updateMetaData();
329 
330  $ilDB->manipulate("UPDATE glossary SET ".
331  " is_online = ".$ilDB->quote(ilUtil::tf2yn($this->getOnline()), "text").",".
332  " virtual = ".$ilDB->quote($this->getVirtualMode(), "text").",".
333  " public_xml_file = ".$ilDB->quote($this->getPublicExportFile("xml"), "text").",".
334  " public_html_file = ".$ilDB->quote($this->getPublicExportFile("html"), "text").",".
335  " glo_menu_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveGlossaryMenu()), "text").",".
336  " downloads_active = ".$ilDB->quote(ilUtil::tf2yn($this->isActiveDownloads()), "text").", ".
337  " pres_mode = ".$ilDB->quote($this->getPresentationMode(), "text").", ".
338  " show_tax = ".$ilDB->quote((int) $this->getShowTaxonomy(), "integer").", ".
339  " snippet_length = ".$ilDB->quote($this->getSnippetLength(), "integer")." ".
340  " WHERE id = ".$ilDB->quote($this->getId(), "integer"));
341 
342  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
344 
345  parent::update();
346  }
347 
348 
352  function getTermList($searchterm = "", $a_letter = "", $a_def = "", $a_tax_node = 0, $a_include_offline_childs = false)
353  {
354  $glo_ids = $this->getAllGlossaryIds($a_include_offline_childs);
355 
356  $list = ilGlossaryTerm::getTermList($glo_ids, $searchterm, $a_letter, $a_def, $a_tax_node);
357  return $list;
358  }
359 
363  function getFirstLetters($a_tax_node = 0)
364  {
365  $glo_ids = $this->getAllGlossaryIds();
366  $first_letters = ilGlossaryTerm::getFirstLetters($glo_ids, $a_tax_node);
367  return $first_letters;
368  }
369 
376  function getAllGlossaryIds($a_include_offline_childs = false)
377  {
378  global $tree;
379 
380  if ($this->isVirtual())
381  {
382  $glo_ids = array();
383 
384  $virtual_mode = $this->getRefId() ? $this->getVirtualMode() : '';
385  switch ($virtual_mode)
386  {
387  case "level":
388  $glo_arr = $tree->getChildsByType($tree->getParentId($this->getRefId()),"glo");
389  $glo_ids[] = $this->getId();
390  foreach ($glo_arr as $glo)
391  {
392  {
393  $glo_ids[] = $glo['obj_id'];
394  }
395  }
396  if (!$a_include_offline_childs)
397  {
398  $glo_ids = ilObjGlossary::removeOfflineGlossaries($glo_ids);
399  }
400  break;
401 
402  case "subtree":
403  $subtree_nodes = $tree->getSubTree($tree->getNodeData($tree->getParentId($this->getRefId())));
404 
405  foreach ($subtree_nodes as $node)
406  {
407  if ($node['type'] == 'glo')
408  {
409  $glo_ids[] = $node['obj_id'];
410  }
411  }
412  if (!$a_include_offline_childs)
413  {
414  $glo_ids = ilObjGlossary::removeOfflineGlossaries($glo_ids);
415  }
416  break;
417 
418  // fallback to none virtual mode in case of error
419  default:
420  $glo_ids[] = $this->getId();
421  break;
422  }
423  }
424  else
425  {
426  $glo_ids = $this->getId();
427  }
428 
429  return $glo_ids;
430  }
431 
438  {
439  $glo_data_dir = ilUtil::getDataDir()."/glo_data";
440  ilUtil::makeDir($glo_data_dir);
441  if(!is_writable($glo_data_dir))
442  {
443  $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
444  .") not writeable.",$this->ilias->error_obj->FATAL);
445  }
446 
447  // create glossary directory (data_dir/glo_data/glo_<id>)
448  $glo_dir = $glo_data_dir."/glo_".$this->getId();
449  ilUtil::makeDir($glo_dir);
450  if(!@is_dir($glo_dir))
451  {
452  $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
453  }
454  // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
455  $import_dir = $glo_dir."/import";
456  ilUtil::makeDir($import_dir);
457  if(!@is_dir($import_dir))
458  {
459  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
460  }
461  }
462 
467  {
468  $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/import";
469 
470  return $export_dir;
471  }
472 
476  function createExportDirectory($a_type = "xml")
477  {
478  include_once("./Services/Export/classes/class.ilExport.php");
479  return ilExport::_createExportDirectory($this->getId(), $a_type, $this->getType());
480  }
481 
485  function getExportDirectory($a_type = "xml")
486  {
487  include_once("./Services/Export/classes/class.ilExport.php");
488  return ilExport::_getExportDirectory($this->getId(), $a_type, $this->getType());
489  }
490 
494  function getExportFiles()
495  {
496  include_once("./Services/Export/classes/class.ilExport.php");
497  return ilExport::_getExportFiles($this->getId(), array("xml", "html"), $this->getType());
498  }
499 
506  function setPublicExportFile($a_type, $a_file)
507  {
508  $this->public_export_file[$a_type] = $a_file;
509  }
510 
518  function getPublicExportFile($a_type)
519  {
520  return $this->public_export_file[$a_type];
521  }
522 
526  function exportHTML($a_target_dir, $log)
527  {
528  global $ilias, $tpl;
529 
530  // initialize temporary target directory
531  ilUtil::delDir($a_target_dir);
532  ilUtil::makeDir($a_target_dir);
533 
534  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
535  $this->co_page_html_export = new ilCOPageHTMLExport($a_target_dir);
536  $this->co_page_html_export->createDirectories();
537 
538  // export system style sheet
539  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
540  $style_name = $ilias->account->prefs["style"].".css";
541  copy($location_stylesheet, $a_target_dir."/".$style_name);
542  $location_stylesheet = ilUtil::getStyleSheetLocation();
543 
544  if ($this->getStyleSheetId() < 1)
545  {
546  $cont_stylesheet = "Services/COPage/css/content.css";
547  copy($cont_stylesheet, $a_target_dir."/content.css");
548  }
549  else
550  {
551  $content_style_img_dir = $a_target_dir."/images";
552  ilUtil::makeDir($content_style_img_dir);
553  $style = new ilObjStyleSheet($this->getStyleSheetId());
554  $style->writeCSSFile($a_target_dir."/content.css", "images");
555  $style->copyImagesToDir($content_style_img_dir);
556  }
557 
558  // export syntax highlighting style
559  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
560  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
561 
562  // get glossary presentation gui class
563  include_once("./Modules/Glossary/classes/class.ilGlossaryPresentationGUI.php");
564  $_GET["cmd"] = "nop";
565  $glo_gui =& new ilGlossaryPresentationGUI();
566  $glo_gui->setOfflineMode(true);
567  $glo_gui->setOfflineDirectory($a_target_dir);
568 
569  // could be implemented in the future if other export
570  // formats are supported (e.g. scorm)
571  //$glo_gui->setExportFormat($a_export_format);
572 
573  // export terms
574  $this->exportHTMLGlossaryTerms($glo_gui, $a_target_dir);
575 
576  // export all media objects
577  foreach ($this->offline_mobs as $mob)
578  {
579  $this->exportHTMLMOB($a_target_dir, $glo_gui, $mob, "_blank");
580  }
581  $_GET["obj_type"] = "MediaObject";
582  $_GET["obj_id"] = $a_mob_id;
583  $_GET["cmd"] = "";
584 
585  // export all file objects
586  foreach ($this->offline_files as $file)
587  {
588  $this->exportHTMLFile($a_target_dir, $file);
589  }
590 
591  // export images
592  $image_dir = $a_target_dir."/images";
593  ilUtil::makeDir($image_dir);
594  ilUtil::makeDir($image_dir."/browser");
595  copy(ilUtil::getImagePath("enlarge.png", false, "filesystem"),
596  $image_dir."/enlarge.png");
597  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
598  $image_dir."/browser/plus.png");
599  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
600  $image_dir."/browser/minus.png");
601  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
602  $image_dir."/browser/blank.png");
603  copy(ilUtil::getImagePath("icon_st.png", false, "filesystem"),
604  $image_dir."/icon_st.png");
605  copy(ilUtil::getImagePath("icon_pg.png", false, "filesystem"),
606  $image_dir."/icon_pg.png");
607  copy(ilUtil::getImagePath("nav_arr_L.png", false, "filesystem"),
608  $image_dir."/nav_arr_L.png");
609  copy(ilUtil::getImagePath("nav_arr_R.png", false, "filesystem"),
610  $image_dir."/nav_arr_R.png");
611 
612  // template workaround: reset of template
613  $tpl = new ilTemplate("tpl.main.html", true, true);
614  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
615  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
616 
617  // zip everything
618  if (true)
619  {
620  // zip it all
621  $date = time();
622  $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
623  $this->getType()."_".$this->getId().".zip";
624 //echo "zip-".$a_target_dir."-to-".$zip_file;
625  ilUtil::zip($a_target_dir, $zip_file);
626  ilUtil::delDir($a_target_dir);
627  }
628  }
629 
630 
634  function exportHTMLGlossaryTerms(&$a_glo_gui, $a_target_dir)
635  {
636  global $ilUser;
637 
638  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
639  $copage_export = new ilCOPageHTMLExport($a_target_dir);
640  $copage_export->exportSupportScripts();
641 
642  // index.html file
643  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
644  $style_name = $ilUser->prefs["style"].".css";;
645  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
646  $a_glo_gui->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
647  $a_glo_gui->tpl->setTitle($this->getTitle());
648 
649  $content = $a_glo_gui->listTerms();
650  $file = $a_target_dir."/index.html";
651 
652  // open file
653  if (!($fp = @fopen($file,"w+")))
654  {
655  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
656  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
657  }
658  chmod($file, 0770);
659  fwrite($fp, $content);
660  fclose($fp);
661 
662  $terms = $this->getTermList();
663 
664  $this->offline_mobs = array();
665  $this->offline_files = array();
666 
667  foreach($terms as $term)
668  {
669  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
670  $a_glo_gui->tpl = $copage_export->getPreparedMainTemplate();
671  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
672 
673  // set style
674  $style_name = $ilUser->prefs["style"].".css";;
675  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
676 
677  $_GET["term_id"] = $term["id"];
678  $_GET["frame"] = "_blank";
679  $content =& $a_glo_gui->listDefinitions($_GET["ref_id"],$term["id"],false);
680  $file = $a_target_dir."/term_".$term["id"].".html";
681 
682  // open file
683  if (!($fp = @fopen($file,"w+")))
684  {
685  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
686  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
687  }
688  chmod($file, 0770);
689  fwrite($fp, $content);
690  fclose($fp);
691 
692  // store linked/embedded media objects of glosssary term
693  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
694  $defs = ilGlossaryDefinition::getDefinitionList($term["id"]);
695  foreach($defs as $def)
696  {
697  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
698  foreach($def_mobs as $def_mob)
699  {
700  $this->offline_mobs[$def_mob] = $def_mob;
701  }
702 
703  // get all files of page
704  include_once("./Modules/File/classes/class.ilObjFile.php");
705  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $def["id"]);
706  $this->offline_files = array_merge($this->offline_files, $def_files);
707 
708  }
709  }
710  }
711 
715  function exportHTMLMOB($a_target_dir, &$a_glo_gui, $a_mob_id)
716  {
717  global $tpl;
718 
719  $mob_dir = $a_target_dir."/mobs";
720 
721  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
722  if (@is_dir($source_dir))
723  {
724  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
725  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
726  }
727 
728  $tpl = new ilTemplate("tpl.main.html", true, true);
729  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
730  $_GET["obj_type"] = "MediaObject";
731  $_GET["mob_id"] = $a_mob_id;
732  $_GET["cmd"] = "";
733  $content =& $a_glo_gui->media();
734  $file = $a_target_dir."/media_".$a_mob_id.".html";
735 
736  // open file
737  if (!($fp = @fopen($file,"w+")))
738  {
739  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
740  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
741  }
742  chmod($file, 0770);
743  fwrite($fp, $content);
744  fclose($fp);
745 
746  // fullscreen
747  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
748  $mob_obj = new ilObjMediaObject($a_mob_id);
749  if ($mob_obj->hasFullscreenItem())
750  {
751  $tpl = new ilTemplate("tpl.main.html", true, true);
752  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
753  $_GET["mob_id"] = $a_mob_id;
754  $_GET["cmd"] = "fullscreen";
755  $content = $a_glo_gui->fullscreen();
756  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
757 
758  // open file
759  if (!($fp = @fopen($file,"w+")))
760  {
761  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
762  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
763  }
764  chmod($file, 0770);
765  fwrite($fp, $content);
766  fclose($fp);
767  }
768  }
769 
773  function exportHTMLFile($a_target_dir, $a_file_id)
774  {
775  $file_dir = $a_target_dir."/files/file_".$a_file_id;
776  ilUtil::makeDir($file_dir);
777  include_once("./Modules/File/classes/class.ilObjFile.php");
778  $file_obj = new ilObjFile($a_file_id, false);
779  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
780  if (!is_file($source_file))
781  {
782  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
783  }
784  copy($source_file, $file_dir."/".$file_obj->getFileName());
785  }
786 
787 
794  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
795  {
796  global $ilBench;
797 
798  // export glossary
799  $attrs = array();
800  $attrs["Type"] = "Glossary";
801  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
802 
803  // MetaData
804  $this->exportXMLMetaData($a_xml_writer);
805 
806  // collect media objects
807  $terms = $this->getTermList();
808  $this->mob_ids = array();
809  $this->file_ids = array();
810  foreach ($terms as $term)
811  {
812  include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
813 
814  $defs = ilGlossaryDefinition::getDefinitionList($term[id]);
815 
816  foreach($defs as $def)
817  {
818  $this->page_object =& new ilPageObject("gdf",
819  $def["id"], $this->halt_on_error);
820  $this->page_object->buildDom();
821  $this->page_object->insertInstIntoIDs(IL_INST_ID);
822  $mob_ids = $this->page_object->collectMediaObjects(false);
823  $file_ids = $this->page_object->collectFileItems();
824  foreach($mob_ids as $mob_id)
825  {
826  $this->mob_ids[$mob_id] = $mob_id;
827  }
828  foreach($file_ids as $file_id)
829  {
830  $this->file_ids[$file_id] = $file_id;
831  }
832  }
833  }
834 
835  // export media objects
836  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
837  $ilBench->start("GlossaryExport", "exportMediaObjects");
838  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
839  $ilBench->stop("GlossaryExport", "exportMediaObjects");
840  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
841 
842  // FileItems
843  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
844  $ilBench->start("ContentObjectExport", "exportFileItems");
845  $this->exportFileItems($a_target_dir, $expLog);
846  $ilBench->stop("ContentObjectExport", "exportFileItems");
847  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
848 
849  // Glossary
850  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Glossary Items");
851  $ilBench->start("GlossaryExport", "exportGlossaryItems");
852  $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
853  $ilBench->stop("GlossaryExport", "exportGlossaryItems");
854  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Glossary Items");
855 
856  $a_xml_writer->xmlEndTag("ContentObject");
857  }
858 
865  function exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
866  {
867  global $ilBench;
868 
869  $attrs = array();
870  $a_xml_writer->xmlStartTag("Glossary", $attrs);
871 
872  // MetaData
873  $this->exportXMLMetaData($a_xml_writer);
874 
875  $terms = $this->getTermList();
876 
877  // export glossary terms
878  reset($terms);
879  foreach ($terms as $term)
880  {
881  $ilBench->start("GlossaryExport", "exportGlossaryItem");
882  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
883 
884  // export xml to writer object
885  $ilBench->start("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
886  $glo_term = new ilGlossaryTerm($term["id"]);
887  $ilBench->stop("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
888  $ilBench->start("GlossaryExport", "exportGlossaryItem_XML");
889  $glo_term->exportXML($a_xml_writer, $a_inst);
890  $ilBench->stop("GlossaryExport", "exportGlossaryItem_XML");
891 
892  // collect all file items
893  /*
894  $ilBench->start("GlossaryExport", "exportGlossaryItem_CollectFileItems");
895  $file_ids = $page_obj->getFileItemIds();
896  foreach($file_ids as $file_id)
897  {
898  $this->file_ids[$file_id] = $file_id;
899  }
900  $ilBench->stop("GlossaryExport", "exportGlossaryItem_CollectFileItems");
901  */
902 
903  unset($glo_term);
904 
905  $ilBench->stop("GlossaryExport", "exportGlossaryItem");
906  }
907 
908  $a_xml_writer->xmlEndTag("Glossary");
909  }
910 
917  function exportXMLMetaData(&$a_xml_writer)
918  {
919  include_once("Services/MetaData/classes/class.ilMD2XML.php");
920  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
921  $md2xml->setExportMode(true);
922  $md2xml->startExport();
923  $a_xml_writer->appendXML($md2xml->getXML());
924  }
925 
932  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
933  {
934  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
935 
936  foreach ($this->mob_ids as $mob_id)
937  {
938  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
939  $media_obj = new ilObjMediaObject($mob_id);
940  $media_obj->exportXML($a_xml_writer, $a_inst);
941  $media_obj->exportFiles($a_target_dir);
942  unset($media_obj);
943  }
944  }
945 
950  function exportFileItems($a_target_dir, &$expLog)
951  {
952  include_once("./Modules/File/classes/class.ilObjFile.php");
953 
954  foreach ($this->file_ids as $file_id)
955  {
956  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
957  $file_obj = new ilObjFile($file_id, false);
958  $file_obj->export($a_target_dir);
959  unset($file_obj);
960  }
961  }
962 
963 
964 
968  function modifyExportIdentifier($a_tag, $a_param, $a_value)
969  {
970  if ($a_tag == "Identifier" && $a_param == "Entry")
971  {
972  $a_value = "il_".IL_INST_ID."_glo_".$this->getId();
973  }
974 
975  return $a_value;
976  }
977 
978 
979 
980 
991  function delete()
992  {
993  global $ilDB;
994 
995  // always call parent delete function first!!
996  if (!parent::delete())
997  {
998  return false;
999  }
1000 
1001  // delete terms
1002  if (!$this->isVirtual())
1003  {
1004  $terms = $this->getTermList();
1005  foreach ($terms as $term)
1006  {
1007  $term_obj =& new ilGlossaryTerm($term["id"]);
1008  $term_obj->delete();
1009  }
1010  }
1011 
1012  // delete glossary data entry
1013  $q = "DELETE FROM glossary WHERE id = ".$ilDB->quote($this->getId());
1014  $ilDB->query($q);
1015 
1016  // delete meta data
1017  $this->deleteMetaData();
1018 /*
1019  $nested = new ilNestedSetXML();
1020  $nested->init($this->getId(), $this->getType());
1021  $nested->deleteAllDBData();
1022 */
1023 
1024  return true;
1025  }
1026 
1037  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1038  {
1039  global $tree;
1040 
1041  switch ($a_event)
1042  {
1043  case "link":
1044 
1045  //var_dump("<pre>",$a_params,"</pre>");
1046  //echo "Glossary ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1047  //exit;
1048  break;
1049 
1050  case "cut":
1051 
1052  //echo "Glossary ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1053  //exit;
1054  break;
1055 
1056  case "copy":
1057 
1058  //var_dump("<pre>",$a_params,"</pre>");
1059  //echo "Glossary ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1060  //exit;
1061  break;
1062 
1063  case "paste":
1064 
1065  //echo "Glossary ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1066  //exit;
1067  break;
1068 
1069  case "new":
1070 
1071  //echo "Glossary ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1072  //exit;
1073  break;
1074  }
1075 
1076  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1077  if ($a_node_id==$_GET["ref_id"])
1078  {
1079  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1080  $parent_type = $parent_obj->getType();
1081  if($parent_type == $this->getType())
1082  {
1083  $a_node_id = (int) $tree->getParentId($a_node_id);
1084  }
1085  }
1086 
1087  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1088  }
1089 
1090 
1094  function getXMLZip()
1095  {
1096  include_once("./Modules/Glossary/classes/class.ilGlossaryExport.php");
1097  $glo_exp = new ilGlossaryExport($this);
1098  return $glo_exp->buildExportFile();
1099  }
1100 
1105  static function getDeletionDependencies($a_obj_id)
1106  {
1107  global $lng;
1108 
1109  $dep = array();
1110  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
1112  foreach ($sms as $sm)
1113  {
1114  $lng->loadLanguageModule("content");
1115  $dep[$sm] = $lng->txt("glo_used_in_scorm");
1116  }
1117 //echo "-".$a_obj_id."-";
1118 //var_dump($dep);
1119  return $dep;
1120  }
1121 
1127  function getTaxonomyId()
1128  {
1129  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1130  $tax_ids = ilObjTaxonomy::getUsageOfObject($this->getId());
1131  if (count($tax_ids) > 0)
1132  {
1133  // glossaries handle max. one taxonomy
1134  return $tax_ids[0];
1135  }
1136  return 0;
1137  }
1138 
1139 
1146  public function cloneObject($a_target_id,$a_copy_id = 0)
1147  {
1148  global $ilDB, $ilUser, $ilias;
1149 
1150  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
1151  $this->cloneMetaData($new_obj);
1152 
1153  $new_obj->setTitle($this->getTitle());
1154  $new_obj->setDescription($this->getDescription());
1155  $new_obj->setVirtualMode($this->getVirtualMode());
1156  $new_obj->setPresentationMode($this->getPresentationMode());
1157  $new_obj->setSnippetLength($this->getSnippetLength());
1158  $new_obj->update();
1159 
1160  // set/copy stylesheet
1161  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1162  $style_id = $this->getStyleSheetId();
1163  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
1164  {
1165  $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
1166  $new_id = $style_obj->ilClone();
1167  $new_obj->setStyleSheetId($new_id);
1168  $new_obj->update();
1169  }
1170 
1171  // copy taxonomy
1172  if (($tax_id = $this->getTaxonomyId()) > 0)
1173  {
1174  // clone it
1175  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1176  $tax = new ilObjTaxonomy($tax_id);
1177  $new_tax = $tax->cloneObject(0,0,true);
1178  $map = $tax->getNodeMapping();
1179 
1180  // assign new taxonomy to new glossary
1181  ilObjTaxonomy::saveUsage($new_tax->getId(), $new_obj->getId());
1182  }
1183 
1184  // assign new tax/new glossary
1185  // handle mapping
1186 
1187  // prepare tax node assignments objects
1188  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
1189  if ($tax_id > 0)
1190  {
1191  $tax_ass = new ilTaxNodeAssignment("glo", "term", $tax_id);
1192  $new_tax_ass = new ilTaxNodeAssignment("glo", "term", $new_tax->getId());
1193  }
1194 
1195  // copy terms
1196  foreach (ilGlossaryTerm::getTermList($this->getId()) as $term)
1197  {
1198  $new_term_id = ilGlossaryTerm::_copyTerm($term["id"], $new_obj->getId());
1199 
1200  // copy tax node assignments
1201  if ($tax_id > 0)
1202  {
1203  $assignmts = $tax_ass->getAssignmentsOfItem($term["id"]);
1204  foreach ($assignmts as $a)
1205  {
1206  if ($map[$a["node_id"]] > 0)
1207  {
1208  $new_tax_ass->addAssignment($map[$a["node_id"]] ,$new_term_id);
1209  }
1210  }
1211  }
1212  }
1213 
1214  return $new_obj;
1215  }
1216 
1223  function removeOfflineGlossaries($a_glo_ids)
1224  {
1225  global $ilDB;
1226 
1227  $set = $ilDB->query("SELECT id FROM glossary ".
1228  " WHERE ".$ilDB->in("id", $a_glo_ids, false, "integer").
1229  " AND is_online = ".$ilDB->quote("y", "text")
1230  );
1231  $glo_ids = array();
1232  while ($rec = $ilDB->fetchAssoc($set))
1233  {
1234  $glo_ids[] = $rec["id"];
1235  }
1236  return $glo_ids;
1237  }
1238 
1239 }
1240 
1241 ?>