ILIAS  Release_4_4_x_branch Revision 61816
 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  $a_add_amet_fields = false, $a_amet_filter = "")
354  {
355  $glo_ids = $this->getAllGlossaryIds($a_include_offline_childs);
356  $list = ilGlossaryTerm::getTermList($glo_ids, $searchterm, $a_letter, $a_def, $a_tax_node,
357  $a_add_amet_fields, $a_amet_filter);
358  return $list;
359  }
360 
364  function getFirstLetters($a_tax_node = 0)
365  {
366  $glo_ids = $this->getAllGlossaryIds();
367  $first_letters = ilGlossaryTerm::getFirstLetters($glo_ids, $a_tax_node);
368  return $first_letters;
369  }
370 
377  function getAllGlossaryIds($a_include_offline_childs = false)
378  {
379  global $tree;
380 
381  if ($this->isVirtual())
382  {
383  $glo_ids = array();
384 
385  $virtual_mode = $this->getRefId() ? $this->getVirtualMode() : '';
386  switch ($virtual_mode)
387  {
388  case "level":
389  $glo_arr = $tree->getChildsByType($tree->getParentId($this->getRefId()),"glo");
390  $glo_ids[] = $this->getId();
391  foreach ($glo_arr as $glo)
392  {
393  {
394  $glo_ids[] = $glo['obj_id'];
395  }
396  }
397  if (!$a_include_offline_childs)
398  {
399  $glo_ids = ilObjGlossary::removeOfflineGlossaries($glo_ids);
400  }
401  break;
402 
403  case "subtree":
404  $subtree_nodes = $tree->getSubTree($tree->getNodeData($tree->getParentId($this->getRefId())));
405 
406  foreach ($subtree_nodes as $node)
407  {
408  if ($node['type'] == 'glo')
409  {
410  $glo_ids[] = $node['obj_id'];
411  }
412  }
413  if (!$a_include_offline_childs)
414  {
415  $glo_ids = ilObjGlossary::removeOfflineGlossaries($glo_ids);
416  }
417  break;
418 
419  // fallback to none virtual mode in case of error
420  default:
421  $glo_ids[] = $this->getId();
422  break;
423  }
424  }
425  else
426  {
427  $glo_ids = $this->getId();
428  }
429 
430  return $glo_ids;
431  }
432 
439  {
440  $glo_data_dir = ilUtil::getDataDir()."/glo_data";
441  ilUtil::makeDir($glo_data_dir);
442  if(!is_writable($glo_data_dir))
443  {
444  $this->ilias->raiseError("Glossary Data Directory (".$glo_data_dir
445  .") not writeable.",$this->ilias->error_obj->FATAL);
446  }
447 
448  // create glossary directory (data_dir/glo_data/glo_<id>)
449  $glo_dir = $glo_data_dir."/glo_".$this->getId();
450  ilUtil::makeDir($glo_dir);
451  if(!@is_dir($glo_dir))
452  {
453  $this->ilias->raiseError("Creation of Glossary Directory failed.",$this->ilias->error_obj->FATAL);
454  }
455  // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
456  $import_dir = $glo_dir."/import";
457  ilUtil::makeDir($import_dir);
458  if(!@is_dir($import_dir))
459  {
460  $this->ilias->raiseError("Creation of Export Directory failed.",$this->ilias->error_obj->FATAL);
461  }
462  }
463 
468  {
469  $export_dir = ilUtil::getDataDir()."/glo_data"."/glo_".$this->getId()."/import";
470 
471  return $export_dir;
472  }
473 
477  function createExportDirectory($a_type = "xml")
478  {
479  include_once("./Services/Export/classes/class.ilExport.php");
480  return ilExport::_createExportDirectory($this->getId(), $a_type, $this->getType());
481  }
482 
486  function getExportDirectory($a_type = "xml")
487  {
488  include_once("./Services/Export/classes/class.ilExport.php");
489  return ilExport::_getExportDirectory($this->getId(), $a_type, $this->getType());
490  }
491 
495  function getExportFiles()
496  {
497  include_once("./Services/Export/classes/class.ilExport.php");
498  return ilExport::_getExportFiles($this->getId(), array("xml", "html"), $this->getType());
499  }
500 
507  function setPublicExportFile($a_type, $a_file)
508  {
509  $this->public_export_file[$a_type] = $a_file;
510  }
511 
519  function getPublicExportFile($a_type)
520  {
521  return $this->public_export_file[$a_type];
522  }
523 
527  function exportHTML($a_target_dir, $log)
528  {
529  global $ilias, $tpl;
530 
531  // initialize temporary target directory
532  ilUtil::delDir($a_target_dir);
533  ilUtil::makeDir($a_target_dir);
534 
535  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
536  $this->co_page_html_export = new ilCOPageHTMLExport($a_target_dir);
537  $this->co_page_html_export->createDirectories();
538 
539  // export system style sheet
540  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
541  $style_name = $ilias->account->prefs["style"].".css";
542  copy($location_stylesheet, $a_target_dir."/".$style_name);
543  $location_stylesheet = ilUtil::getStyleSheetLocation();
544 
545  if ($this->getStyleSheetId() < 1)
546  {
547  $cont_stylesheet = "Services/COPage/css/content.css";
548  copy($cont_stylesheet, $a_target_dir."/content.css");
549  }
550  else
551  {
552  $content_style_img_dir = $a_target_dir."/images";
553  ilUtil::makeDir($content_style_img_dir);
554  $style = new ilObjStyleSheet($this->getStyleSheetId());
555  $style->writeCSSFile($a_target_dir."/content.css", "images");
556  $style->copyImagesToDir($content_style_img_dir);
557  }
558 
559  // export syntax highlighting style
560  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
561  copy($syn_stylesheet, $a_target_dir."/syntaxhighlight.css");
562 
563  // get glossary presentation gui class
564  include_once("./Modules/Glossary/classes/class.ilGlossaryPresentationGUI.php");
565  $_GET["cmd"] = "nop";
566  $glo_gui =& new ilGlossaryPresentationGUI();
567  $glo_gui->setOfflineMode(true);
568  $glo_gui->setOfflineDirectory($a_target_dir);
569 
570  // could be implemented in the future if other export
571  // formats are supported (e.g. scorm)
572  //$glo_gui->setExportFormat($a_export_format);
573 
574  // export terms
575  $this->exportHTMLGlossaryTerms($glo_gui, $a_target_dir);
576 
577  // export all media objects
578  foreach ($this->offline_mobs as $mob)
579  {
580  $this->exportHTMLMOB($a_target_dir, $glo_gui, $mob, "_blank");
581  }
582  $_GET["obj_type"] = "MediaObject";
583  $_GET["obj_id"] = $a_mob_id;
584  $_GET["cmd"] = "";
585 
586  // export all file objects
587  foreach ($this->offline_files as $file)
588  {
589  $this->exportHTMLFile($a_target_dir, $file);
590  }
591 
592  // export images
593  $image_dir = $a_target_dir."/images";
594  ilUtil::makeDir($image_dir);
595  ilUtil::makeDir($image_dir."/browser");
596  copy(ilUtil::getImagePath("enlarge.png", false, "filesystem"),
597  $image_dir."/enlarge.png");
598  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
599  $image_dir."/browser/plus.png");
600  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
601  $image_dir."/browser/minus.png");
602  copy(ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
603  $image_dir."/browser/blank.png");
604  copy(ilUtil::getImagePath("icon_st.png", false, "filesystem"),
605  $image_dir."/icon_st.png");
606  copy(ilUtil::getImagePath("icon_pg.png", false, "filesystem"),
607  $image_dir."/icon_pg.png");
608  copy(ilUtil::getImagePath("nav_arr_L.png", false, "filesystem"),
609  $image_dir."/nav_arr_L.png");
610  copy(ilUtil::getImagePath("nav_arr_R.png", false, "filesystem"),
611  $image_dir."/nav_arr_R.png");
612 
613  // template workaround: reset of template
614  $tpl = new ilTemplate("tpl.main.html", true, true);
615  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
616  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
617 
618  // zip everything
619  if (true)
620  {
621  // zip it all
622  $date = time();
623  $zip_file = $this->getExportDirectory("html")."/".$date."__".IL_INST_ID."__".
624  $this->getType()."_".$this->getId().".zip";
625 //echo "zip-".$a_target_dir."-to-".$zip_file;
626  ilUtil::zip($a_target_dir, $zip_file);
627  ilUtil::delDir($a_target_dir);
628  }
629  }
630 
631 
635  function exportHTMLGlossaryTerms(&$a_glo_gui, $a_target_dir)
636  {
637  global $ilUser;
638 
639  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
640  $copage_export = new ilCOPageHTMLExport($a_target_dir);
641  $copage_export->exportSupportScripts();
642 
643  // index.html file
644  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
645  $style_name = $ilUser->prefs["style"].".css";;
646  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
647  $a_glo_gui->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
648  $a_glo_gui->tpl->setTitle($this->getTitle());
649 
650  $content = $a_glo_gui->listTerms();
651  $file = $a_target_dir."/index.html";
652 
653  // open file
654  if (!($fp = @fopen($file,"w+")))
655  {
656  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
657  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
658  }
659  chmod($file, 0770);
660  fwrite($fp, $content);
661  fclose($fp);
662 
663  $terms = $this->getTermList();
664 
665  $this->offline_mobs = array();
666  $this->offline_files = array();
667 
668  foreach($terms as $term)
669  {
670  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
671  $a_glo_gui->tpl = $copage_export->getPreparedMainTemplate();
672  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
673 
674  // set style
675  $style_name = $ilUser->prefs["style"].".css";;
676  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET","./".$style_name);
677 
678  $_GET["term_id"] = $term["id"];
679  $_GET["frame"] = "_blank";
680  $content =& $a_glo_gui->listDefinitions($_GET["ref_id"],$term["id"],false);
681  $file = $a_target_dir."/term_".$term["id"].".html";
682 
683  // open file
684  if (!($fp = @fopen($file,"w+")))
685  {
686  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
687  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
688  }
689  chmod($file, 0770);
690  fwrite($fp, $content);
691  fclose($fp);
692 
693  // store linked/embedded media objects of glosssary term
694  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
695  $defs = ilGlossaryDefinition::getDefinitionList($term["id"]);
696  foreach($defs as $def)
697  {
698  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
699  foreach($def_mobs as $def_mob)
700  {
701  $this->offline_mobs[$def_mob] = $def_mob;
702  }
703 
704  // get all files of page
705  include_once("./Modules/File/classes/class.ilObjFile.php");
706  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $def["id"]);
707  $this->offline_files = array_merge($this->offline_files, $def_files);
708 
709  }
710  }
711  }
712 
716  function exportHTMLMOB($a_target_dir, &$a_glo_gui, $a_mob_id)
717  {
718  global $tpl;
719 
720  $mob_dir = $a_target_dir."/mobs";
721 
722  $source_dir = ilUtil::getWebspaceDir()."/mobs/mm_".$a_mob_id;
723  if (@is_dir($source_dir))
724  {
725  ilUtil::makeDir($mob_dir."/mm_".$a_mob_id);
726  ilUtil::rCopy($source_dir, $mob_dir."/mm_".$a_mob_id);
727  }
728 
729  $tpl = new ilTemplate("tpl.main.html", true, true);
730  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
731  $_GET["obj_type"] = "MediaObject";
732  $_GET["mob_id"] = $a_mob_id;
733  $_GET["cmd"] = "";
734  $content =& $a_glo_gui->media();
735  $file = $a_target_dir."/media_".$a_mob_id.".html";
736 
737  // open file
738  if (!($fp = @fopen($file,"w+")))
739  {
740  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
741  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
742  }
743  chmod($file, 0770);
744  fwrite($fp, $content);
745  fclose($fp);
746 
747  // fullscreen
748  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
749  $mob_obj = new ilObjMediaObject($a_mob_id);
750  if ($mob_obj->hasFullscreenItem())
751  {
752  $tpl = new ilTemplate("tpl.main.html", true, true);
753  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
754  $_GET["mob_id"] = $a_mob_id;
755  $_GET["cmd"] = "fullscreen";
756  $content = $a_glo_gui->fullscreen();
757  $file = $a_target_dir."/fullscreen_".$a_mob_id.".html";
758 
759  // open file
760  if (!($fp = @fopen($file,"w+")))
761  {
762  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
763  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
764  }
765  chmod($file, 0770);
766  fwrite($fp, $content);
767  fclose($fp);
768  }
769  }
770 
774  function exportHTMLFile($a_target_dir, $a_file_id)
775  {
776  $file_dir = $a_target_dir."/files/file_".$a_file_id;
777  ilUtil::makeDir($file_dir);
778  include_once("./Modules/File/classes/class.ilObjFile.php");
779  $file_obj = new ilObjFile($a_file_id, false);
780  $source_file = $file_obj->getDirectory($file_obj->getVersion())."/".$file_obj->getFileName();
781  if (!is_file($source_file))
782  {
783  $source_file = $file_obj->getDirectory()."/".$file_obj->getFileName();
784  }
785  copy($source_file, $file_dir."/".$file_obj->getFileName());
786  }
787 
788 
795  function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
796  {
797  global $ilBench;
798 
799  // export glossary
800  $attrs = array();
801  $attrs["Type"] = "Glossary";
802  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
803 
804  // MetaData
805  $this->exportXMLMetaData($a_xml_writer);
806 
807  // collect media objects
808  $terms = $this->getTermList();
809  $this->mob_ids = array();
810  $this->file_ids = array();
811  foreach ($terms as $term)
812  {
813  include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
814 
815  $defs = ilGlossaryDefinition::getDefinitionList($term[id]);
816 
817  foreach($defs as $def)
818  {
819  $this->page_object = new ilGlossaryDefPage($def["id"]);
820  $this->page_object->buildDom();
821  $this->page_object->insertInstIntoIDs(IL_INST_ID);
822  $mob_ids = $this->page_object->collectMediaObjects(false);
823  include_once("./Services/COPage/classes/class.ilPCFileList.php");
824  $file_ids = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
825  foreach($mob_ids as $mob_id)
826  {
827  $this->mob_ids[$mob_id] = $mob_id;
828  }
829  foreach($file_ids as $file_id)
830  {
831  $this->file_ids[$file_id] = $file_id;
832  }
833  }
834  }
835 
836  // export media objects
837  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Media Objects");
838  $ilBench->start("GlossaryExport", "exportMediaObjects");
839  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
840  $ilBench->stop("GlossaryExport", "exportMediaObjects");
841  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Media Objects");
842 
843  // FileItems
844  $expLog->write(date("[y-m-d H:i:s] ")."Start Export File Items");
845  $ilBench->start("ContentObjectExport", "exportFileItems");
846  $this->exportFileItems($a_target_dir, $expLog);
847  $ilBench->stop("ContentObjectExport", "exportFileItems");
848  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export File Items");
849 
850  // Glossary
851  $expLog->write(date("[y-m-d H:i:s] ")."Start Export Glossary Items");
852  $ilBench->start("GlossaryExport", "exportGlossaryItems");
853  $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
854  $ilBench->stop("GlossaryExport", "exportGlossaryItems");
855  $expLog->write(date("[y-m-d H:i:s] ")."Finished Export Glossary Items");
856 
857  $a_xml_writer->xmlEndTag("ContentObject");
858  }
859 
866  function exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
867  {
868  global $ilBench;
869 
870  $attrs = array();
871  $a_xml_writer->xmlStartTag("Glossary", $attrs);
872 
873  // MetaData
874  $this->exportXMLMetaData($a_xml_writer);
875 
876  $terms = $this->getTermList();
877 
878  // export glossary terms
879  reset($terms);
880  foreach ($terms as $term)
881  {
882  $ilBench->start("GlossaryExport", "exportGlossaryItem");
883  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
884 
885  // export xml to writer object
886  $ilBench->start("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
887  $glo_term = new ilGlossaryTerm($term["id"]);
888  $ilBench->stop("GlossaryExport", "exportGlossaryItem_getGlossaryTerm");
889  $ilBench->start("GlossaryExport", "exportGlossaryItem_XML");
890  $glo_term->exportXML($a_xml_writer, $a_inst);
891  $ilBench->stop("GlossaryExport", "exportGlossaryItem_XML");
892 
893  unset($glo_term);
894 
895  $ilBench->stop("GlossaryExport", "exportGlossaryItem");
896  }
897 
898  $a_xml_writer->xmlEndTag("Glossary");
899  }
900 
907  function exportXMLMetaData(&$a_xml_writer)
908  {
909  include_once("Services/MetaData/classes/class.ilMD2XML.php");
910  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
911  $md2xml->setExportMode(true);
912  $md2xml->startExport();
913  $a_xml_writer->appendXML($md2xml->getXML());
914  }
915 
922  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
923  {
924  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
925 
926  foreach ($this->mob_ids as $mob_id)
927  {
928  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
929  $media_obj = new ilObjMediaObject($mob_id);
930  $media_obj->exportXML($a_xml_writer, $a_inst);
931  $media_obj->exportFiles($a_target_dir);
932  unset($media_obj);
933  }
934  }
935 
940  function exportFileItems($a_target_dir, &$expLog)
941  {
942  include_once("./Modules/File/classes/class.ilObjFile.php");
943 
944  foreach ($this->file_ids as $file_id)
945  {
946  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
947  $file_obj = new ilObjFile($file_id, false);
948  $file_obj->export($a_target_dir);
949  unset($file_obj);
950  }
951  }
952 
953 
954 
958  function modifyExportIdentifier($a_tag, $a_param, $a_value)
959  {
960  if ($a_tag == "Identifier" && $a_param == "Entry")
961  {
962  $a_value = "il_".IL_INST_ID."_glo_".$this->getId();
963  }
964 
965  return $a_value;
966  }
967 
968 
969 
970 
981  function delete()
982  {
983  global $ilDB;
984 
985  // always call parent delete function first!!
986  if (!parent::delete())
987  {
988  return false;
989  }
990 
991  // delete terms
992  if (!$this->isVirtual())
993  {
994  $terms = $this->getTermList();
995  foreach ($terms as $term)
996  {
997  $term_obj =& new ilGlossaryTerm($term["id"]);
998  $term_obj->delete();
999  }
1000  }
1001 
1002  // delete glossary data entry
1003  $q = "DELETE FROM glossary WHERE id = ".$ilDB->quote($this->getId());
1004  $ilDB->query($q);
1005 
1006  // delete meta data
1007  $this->deleteMetaData();
1008 /*
1009  $nested = new ilNestedSetXML();
1010  $nested->init($this->getId(), $this->getType());
1011  $nested->deleteAllDBData();
1012 */
1013 
1014  return true;
1015  }
1016 
1027  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1028  {
1029  global $tree;
1030 
1031  switch ($a_event)
1032  {
1033  case "link":
1034 
1035  //var_dump("<pre>",$a_params,"</pre>");
1036  //echo "Glossary ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
1037  //exit;
1038  break;
1039 
1040  case "cut":
1041 
1042  //echo "Glossary ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
1043  //exit;
1044  break;
1045 
1046  case "copy":
1047 
1048  //var_dump("<pre>",$a_params,"</pre>");
1049  //echo "Glossary ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
1050  //exit;
1051  break;
1052 
1053  case "paste":
1054 
1055  //echo "Glossary ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
1056  //exit;
1057  break;
1058 
1059  case "new":
1060 
1061  //echo "Glossary ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
1062  //exit;
1063  break;
1064  }
1065 
1066  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
1067  if ($a_node_id==$_GET["ref_id"])
1068  {
1069  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1070  $parent_type = $parent_obj->getType();
1071  if($parent_type == $this->getType())
1072  {
1073  $a_node_id = (int) $tree->getParentId($a_node_id);
1074  }
1075  }
1076 
1077  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
1078  }
1079 
1080 
1084  function getXMLZip()
1085  {
1086  include_once("./Modules/Glossary/classes/class.ilGlossaryExport.php");
1087  $glo_exp = new ilGlossaryExport($this);
1088  return $glo_exp->buildExportFile();
1089  }
1090 
1095  static function getDeletionDependencies($a_obj_id)
1096  {
1097  global $lng;
1098 
1099  $dep = array();
1100  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
1102  foreach ($sms as $sm)
1103  {
1104  $lng->loadLanguageModule("content");
1105  $dep[$sm] = $lng->txt("glo_used_in_scorm");
1106  }
1107 //echo "-".$a_obj_id."-";
1108 //var_dump($dep);
1109  return $dep;
1110  }
1111 
1117  function getTaxonomyId()
1118  {
1119  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1120  $tax_ids = ilObjTaxonomy::getUsageOfObject($this->getId());
1121  if (count($tax_ids) > 0)
1122  {
1123  // glossaries handle max. one taxonomy
1124  return $tax_ids[0];
1125  }
1126  return 0;
1127  }
1128 
1129 
1136  public function cloneObject($a_target_id,$a_copy_id = 0)
1137  {
1138  global $ilDB, $ilUser, $ilias;
1139 
1140  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
1141  $this->cloneMetaData($new_obj);
1142 
1143  $new_obj->setTitle($this->getTitle());
1144  $new_obj->setDescription($this->getDescription());
1145  $new_obj->setVirtualMode($this->getVirtualMode());
1146  $new_obj->setPresentationMode($this->getPresentationMode());
1147  $new_obj->setSnippetLength($this->getSnippetLength());
1148  $new_obj->update();
1149 
1150  // set/copy stylesheet
1151  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
1152  $style_id = $this->getStyleSheetId();
1153  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
1154  {
1155  $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
1156  $new_id = $style_obj->ilClone();
1157  $new_obj->setStyleSheetId($new_id);
1158  $new_obj->update();
1159  }
1160 
1161  // copy taxonomy
1162  if (($tax_id = $this->getTaxonomyId()) > 0)
1163  {
1164  // clone it
1165  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1166  $tax = new ilObjTaxonomy($tax_id);
1167  $new_tax = $tax->cloneObject(0,0,true);
1168  $map = $tax->getNodeMapping();
1169 
1170  // assign new taxonomy to new glossary
1171  ilObjTaxonomy::saveUsage($new_tax->getId(), $new_obj->getId());
1172  }
1173 
1174  // assign new tax/new glossary
1175  // handle mapping
1176 
1177  // prepare tax node assignments objects
1178  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
1179  if ($tax_id > 0)
1180  {
1181  $tax_ass = new ilTaxNodeAssignment("glo", $this->getId(), "term", $tax_id);
1182  $new_tax_ass = new ilTaxNodeAssignment("glo", $new_obj->getId(), "term", $new_tax->getId());
1183  }
1184 
1185  // copy terms
1186  foreach (ilGlossaryTerm::getTermList($this->getId()) as $term)
1187  {
1188  $new_term_id = ilGlossaryTerm::_copyTerm($term["id"], $new_obj->getId());
1189 
1190  // copy tax node assignments
1191  if ($tax_id > 0)
1192  {
1193  $assignmts = $tax_ass->getAssignmentsOfItem($term["id"]);
1194  foreach ($assignmts as $a)
1195  {
1196  if ($map[$a["node_id"]] > 0)
1197  {
1198  $new_tax_ass->addAssignment($map[$a["node_id"]] ,$new_term_id);
1199  }
1200  }
1201  }
1202  }
1203 
1204  return $new_obj;
1205  }
1206 
1213  function removeOfflineGlossaries($a_glo_ids)
1214  {
1215  global $ilDB;
1216 
1217  $set = $ilDB->query("SELECT id FROM glossary ".
1218  " WHERE ".$ilDB->in("id", $a_glo_ids, false, "integer").
1219  " AND is_online = ".$ilDB->quote("y", "text")
1220  );
1221  $glo_ids = array();
1222  while ($rec = $ilDB->fetchAssoc($set))
1223  {
1224  $glo_ids[] = $rec["id"];
1225  }
1226  return $glo_ids;
1227  }
1228 
1229 }
1230 
1231 ?>