ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 include_once("./Services/AdvancedMetaData/interfaces/interface.ilAdvancedMetaDataSubItems.php");
8 
21 {
25  protected $tpl;
26 
27 
31  protected $db;
32 
36  public $auto_glossaries = array();
37 
41  protected $user;
42 
47  public function __construct($a_id = 0, $a_call_by_reference = true)
48  {
49  global $DIC;
50  $this->error = $DIC["ilErr"];
51  $this->tpl = $DIC["tpl"];
52 
53  $this->db = $DIC->database();
54  $this->user = $DIC->user();
55  $this->type = "glo";
56  parent::__construct($a_id, $a_call_by_reference);
57  }
58 
62  public function create($a_upload = false)
63  {
64  parent::create();
65 
66  // meta data will be created by
67  // import parser
68  if (!$a_upload) {
69  $this->createMetaData();
70  }
71  $this->db->insert(
72  'glossary',
73  array(
74  'id' => array('integer', $this->getId()),
75  'is_online' => array('text', 'n'),
76  'virtual' => array('text', $this->getVirtualMode()),
77  'pres_mode' => array('text', 'table'),
78  'snippet_length' => array('integer', 200)
79  )
80  );
81 
82  $this->setPresentationMode("table");
83  $this->setSnippetLength(200);
84 
85  $this->updateAutoGlossaries();
86 
87  if (((int) $this->getStyleSheetId()) > 0) {
88  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
90  }
91  }
92 
96  public function read()
97  {
98  parent::read();
99  # echo "Glossary<br>\n";
100 
101  $q = "SELECT * FROM glossary WHERE id = " .
102  $this->db->quote($this->getId(), "integer");
103  $gl_set = $this->db->query($q);
104  $gl_rec = $this->db->fetchAssoc($gl_set);
105  $this->setOnline(ilUtil::yn2tf($gl_rec["is_online"]));
106  $this->setVirtualMode($gl_rec["virtual"]);
107  $this->setPublicExportFile("xml", $gl_rec["public_xml_file"]);
108  $this->setPublicExportFile("html", $gl_rec["public_html_file"]);
109  $this->setActiveGlossaryMenu(ilUtil::yn2tf($gl_rec["glo_menu_active"]));
110  $this->setActiveDownloads(ilUtil::yn2tf($gl_rec["downloads_active"]));
111  $this->setPresentationMode($gl_rec["pres_mode"]);
112  $this->setSnippetLength($gl_rec["snippet_length"]);
113  $this->setShowTaxonomy($gl_rec["show_tax"]);
114 
115  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
117 
118  // read auto glossaries
119  $set = $this->db->query(
120  "SELECT * FROM glo_glossaries " .
121  " WHERE id = " . $this->db->quote($this->getId(), "integer")
122  );
123  $glos = array();
124  while ($rec = $this->db->fetchAssoc($set)) {
125  $glos[] = $rec["glo_id"];
126  }
127  $this->setAutoGlossaries($glos);
128  }
129 
135  public function getDescription()
136  {
137  return parent::getDescription();
138  }
139 
143  public function setDescription($a_description)
144  {
145  parent::setDescription($a_description);
146  }
147 
148 
152  public function setVirtualMode($a_mode)
153  {
154  switch ($a_mode) {
155  case "level":
156  case "subtree":
157  // case "fixed":
158  $this->virtual_mode = $a_mode;
159  $this->virtual = true;
160  break;
161 
162  default:
163  $this->virtual_mode = "none";
164  $this->virtual = false;
165  break;
166  }
167  }
168 
172  public function getVirtualMode()
173  {
174  return $this->virtual_mode;
175  }
176 
180  public function isVirtual()
181  {
182  return $this->virtual;
183  }
184 
190  public function getTitle()
191  {
192  return parent::getTitle();
193  }
194 
198  public function setTitle($a_title)
199  {
200  parent::setTitle($a_title);
201  // $this->meta_data->setTitle($a_title);
202  }
203 
209  public function setPresentationMode($a_val)
210  {
211  $this->pres_mode = $a_val;
212  }
213 
219  public function getPresentationMode()
220  {
221  return $this->pres_mode;
222  }
223 
229  public function setSnippetLength($a_val)
230  {
231  $this->snippet_length = $a_val;
232  }
233 
239  public function getSnippetLength()
240  {
241  return ($this->snippet_length > 0)
242  ? $this->snippet_length
243  : null;
244  }
245 
246  public function setOnline($a_online)
247  {
248  $this->online = $a_online;
249  }
250 
251  public function getOnline()
252  {
253  return $this->online;
254  }
255 
259  public static function _lookupOnline($a_id)
260  {
261  global $DIC;
262 
263  $db = $DIC->database();
264 
265  $q = "SELECT is_online FROM glossary WHERE id = " .
266  $db->quote($a_id, "integer");
267  $lm_set = $db->query($q);
268  $lm_rec = $db->fetchAssoc($lm_set);
269 
270  return ilUtil::yn2tf($lm_rec["is_online"]);
271  }
272 
279  protected static function lookup($a_id, $a_property)
280  {
281  global $DIC;
282 
283  $db = $DIC->database();
284 
285  $set = $db->query("SELECT $a_property FROM glossary WHERE id = " .
286  $db->quote($a_id, "integer"));
287  $rec = $db->fetchAssoc($set);
288 
289  return $rec[$a_property];
290  }
291 
298  public static function lookupSnippetLength($a_id)
299  {
300  return ilObjGlossary::lookup($a_id, "snippet_length");
301  }
302 
303 
304  public function setActiveGlossaryMenu($a_act_glo_menu)
305  {
306  $this->glo_menu_active = $a_act_glo_menu;
307  }
308 
309  public function isActiveGlossaryMenu()
310  {
311  return $this->glo_menu_active;
312  }
313 
314  public function setActiveDownloads($a_down)
315  {
316  $this->downloads_active = $a_down;
317  }
318 
319  public function isActiveDownloads()
320  {
321  return $this->downloads_active;
322  }
323 
327  public function getStyleSheetId()
328  {
329  return $this->style_id;
330  }
331 
335  public function setStyleSheetId($a_style_id)
336  {
337  $this->style_id = $a_style_id;
338  }
339 
340 
346  public function setShowTaxonomy($a_val)
347  {
348  $this->show_tax = $a_val;
349  }
350 
356  public function getShowTaxonomy()
357  {
358  return $this->show_tax;
359  }
360 
366  public function setAutoGlossaries($a_val)
367  {
368  $this->auto_glossaries = array();
369  if (is_array($a_val)) {
370  foreach ($a_val as $v) {
371  $this->addAutoGlossary($v);
372  }
373  }
374  }
375 
380  public function addAutoGlossary($glo_id)
381  {
382  $glo_id = (int) $glo_id;
383  if ($glo_id > 0 && ilObject::_lookupType($glo_id) == "glo" &&
384  !in_array($glo_id, $this->auto_glossaries)) {
385  $this->auto_glossaries[] = $glo_id;
386  }
387  }
388 
394  public function getAutoGlossaries()
395  {
396  return $this->auto_glossaries;
397  }
398 
405  public function removeAutoGlossary($a_glo_id)
406  {
407  $glo_ids = array();
408  foreach ($this->getAutoGlossaries() as $g) {
409  if ($g != $a_glo_id) {
410  $glo_ids[] = $g;
411  }
412  }
413  $this->setAutoGlossaries($glo_ids);
414  }
415 
419  public function update()
420  {
421  $this->updateMetaData();
422 
423  $this->db->update(
424  'glossary',
425  array(
426  'is_online' => array('text', ilUtil::tf2yn($this->getOnline())),
427  'virtual' => array('text', $this->getVirtualMode()),
428  'public_xml_file' => array('text', $this->getPublicExportFile("xml")),
429  'public_html_file' => array('text', $this->getPublicExportFile("html")),
430  'glo_menu_active' => array('text', ilUtil::tf2yn($this->isActiveGlossaryMenu())),
431  'downloads_active' => array('text', ilUtil::tf2yn($this->isActiveDownloads())),
432  'pres_mode' => array('text', $this->getPresentationMode()),
433  'show_tax' => array('integer', $this->getShowTaxonomy()),
434  'snippet_length' => array('integer', $this->getSnippetLength())
435  ),
436  array(
437  'id' => array('integer', $this->getId())
438  )
439  );
440  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
442 
443  $this->updateAutoGlossaries();
444  parent::update();
445  }
446 
447 
454  public function updateAutoGlossaries()
455  {
456  // update auto glossaries
457  $this->db->manipulate(
458  "DELETE FROM glo_glossaries WHERE " .
459  " id = " . $this->db->quote($this->getId(), "integer")
460  );
461  foreach ($this->getAutoGlossaries() as $glo_id) {
462  $this->db->insert(
463  'glo_glossaries',
464  array(
465  'id' => array('integer', $this->getId()),
466  'glo_id' => array('integer', $glo_id)
467  )
468  );
469  }
470  }
471 
478  public static function lookupAutoGlossaries($a_id)
479  {
480  global $DIC;
481 
482  $db = $DIC->database();
483 
484  // read auto glossaries
485  $set = $db->query(
486  "SELECT * FROM glo_glossaries " .
487  " WHERE id = " . $db->quote($a_id, "integer")
488  );
489  $glos = array();
490  while ($rec = $db->fetchAssoc($set)) {
491  $glos[] = $rec["glo_id"];
492  }
493  return $glos;
494  }
495 
499  public function getTermList(
500  $searchterm = "",
501  $a_letter = "",
502  $a_def = "",
503  $a_tax_node = 0,
504  $a_include_offline_childs = false,
505  $a_add_amet_fields = false,
506  array $a_amet_filter = null,
507  $a_omit_virtual = false,
508  $a_include_references = false
509  ) {
510  if ($a_omit_virtual) {
511  $glo_ref_ids[] = $this->getRefId();
512  } else {
513  $glo_ref_ids = $this->getAllGlossaryIds($a_include_offline_childs, true);
514  }
516  $glo_ref_ids,
517  $searchterm,
518  $a_letter,
519  $a_def,
520  $a_tax_node,
521  $a_add_amet_fields,
522  $a_amet_filter,
523  $a_include_references
524  );
525  return $list;
526  }
527 
531  public function getFirstLetters($a_tax_node = 0)
532  {
533  $glo_ids = $this->getAllGlossaryIds();
534  $first_letters = ilGlossaryTerm::getFirstLetters($glo_ids, $a_tax_node);
535  return $first_letters;
536  }
537 
544  public function getAllGlossaryIds($a_include_offline_childs = false, $ids_are_ref_ids = false)
545  {
546  global $DIC;
547 
548  $tree = $DIC->repositoryTree();
549 
550  if ($this->isVirtual()) {
551  $glo_ids = array();
552 
553  $virtual_mode = $this->getRefId() ? $this->getVirtualMode() : '';
554  switch ($virtual_mode) {
555  case "level":
556  $glo_arr = $tree->getChildsByType($tree->getParentId($this->getRefId()), "glo");
557  foreach ($glo_arr as $glo) {
558  {
559  if ($ids_are_ref_ids) {
560  $glo_ids[] = $glo['child'];
561  } else {
562  $glo_ids[] = $glo['obj_id'];
563  }
564  }
565  }
566  break;
567 
568  case "subtree":
569  $subtree_nodes = $tree->getSubTree($tree->getNodeData($tree->getParentId($this->getRefId())));
570 
571  foreach ($subtree_nodes as $node) {
572  if ($node['type'] == 'glo') {
573  if ($ids_are_ref_ids) {
574  $glo_ids[] = $node['child'];
575  } else {
576  $glo_ids[] = $node['obj_id'];
577  }
578  }
579  }
580  break;
581  }
582  if (!$a_include_offline_childs) {
583  $glo_ids = ilObjGlossary::removeOfflineGlossaries($glo_ids, $ids_are_ref_ids);
584  }
585  // always show entries of current glossary (if no permission is given, user will not come to the presentation screen)
586  // see bug #14477
587  if ($ids_are_ref_ids) {
588  if (!in_array($this->getRefId(), $glo_ids)) {
589  $glo_ids[] = $this->getRefId();
590  }
591  } else {
592  if (!in_array($this->getId(), $glo_ids)) {
593  $glo_ids[] = $this->getId();
594  }
595  }
596  } else {
597  if ($ids_are_ref_ids) {
598  $glo_ids = $this->getRefId();
599  } else {
600  $glo_ids = $this->getId();
601  }
602  }
603 
604  return $glo_ids;
605  }
606 
612  public function createImportDirectory()
613  {
615 
616  $glo_data_dir = ilUtil::getDataDir() . "/glo_data";
617  ilUtil::makeDir($glo_data_dir);
618  if (!is_writable($glo_data_dir)) {
619  $ilErr->raiseError("Glossary Data Directory (" . $glo_data_dir
620  . ") not writeable.", $ilErr->error_obj->FATAL);
621  }
622 
623  // create glossary directory (data_dir/glo_data/glo_<id>)
624  $glo_dir = $glo_data_dir . "/glo_" . $this->getId();
625  ilUtil::makeDir($glo_dir);
626  if (!@is_dir($glo_dir)) {
627  $ilErr->raiseError("Creation of Glossary Directory failed.", $ilErr->FATAL);
628  }
629  // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
630  $import_dir = $glo_dir . "/import";
631  ilUtil::makeDir($import_dir);
632  if (!@is_dir($import_dir)) {
633  $ilErr->raiseError("Creation of Export Directory failed.", $ilErr->FATAL);
634  }
635  }
636 
640  public function getImportDirectory()
641  {
642  $export_dir = ilUtil::getDataDir() . "/glo_data" . "/glo_" . $this->getId() . "/import";
643 
644  return $export_dir;
645  }
646 
650  public function createExportDirectory($a_type = "xml")
651  {
652  include_once("./Services/Export/classes/class.ilExport.php");
653  return ilExport::_createExportDirectory($this->getId(), $a_type, $this->getType());
654  }
655 
659  public function getExportDirectory($a_type = "xml")
660  {
661  include_once("./Services/Export/classes/class.ilExport.php");
662  return ilExport::_getExportDirectory($this->getId(), $a_type, $this->getType());
663  }
664 
668  public function getExportFiles()
669  {
670  include_once("./Services/Export/classes/class.ilExport.php");
671  return ilExport::_getExportFiles($this->getId(), array("xml", "html"), $this->getType());
672  }
673 
680  public function setPublicExportFile($a_type, $a_file)
681  {
682  $this->public_export_file[$a_type] = $a_file;
683  }
684 
692  public function getPublicExportFile($a_type)
693  {
694  return $this->public_export_file[$a_type];
695  }
696 
700  public function exportHTML($a_target_dir, $log)
701  {
702  $tpl = $this->tpl;
703 
704  // initialize temporary target directory
705  ilUtil::delDir($a_target_dir);
706  ilUtil::makeDir($a_target_dir);
707 
708  // init mathjax rendering for export
709  include_once './Services/MathJax/classes/class.ilMathJax.php';
711 
712  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
713  $this->co_page_html_export = new ilCOPageHTMLExport($a_target_dir);
714  $this->co_page_html_export->createDirectories();
715 
716  // export system style sheet
717  $location_stylesheet = ilUtil::getStyleSheetLocation("filesystem");
718  $style_name = $this->user->prefs["style"] . ".css";
719  copy($location_stylesheet, $a_target_dir . "/" . $style_name);
720  $location_stylesheet = ilUtil::getStyleSheetLocation();
721 
722  if ($this->getStyleSheetId() < 1) {
723  $cont_stylesheet = "Services/COPage/css/content.css";
724  copy($cont_stylesheet, $a_target_dir . "/content.css");
725  } else {
726  $content_style_img_dir = $a_target_dir . "/images";
727  ilUtil::makeDir($content_style_img_dir);
728  $style = new ilObjStyleSheet($this->getStyleSheetId());
729  $style->writeCSSFile($a_target_dir . "/content.css", "images");
730  $style->copyImagesToDir($content_style_img_dir);
731  }
732 
733  // export syntax highlighting style
734  $syn_stylesheet = ilObjStyleSheet::getSyntaxStylePath();
735  copy($syn_stylesheet, $a_target_dir . "/syntaxhighlight.css");
736 
737  // get glossary presentation gui class
738  include_once("./Modules/Glossary/classes/class.ilGlossaryPresentationGUI.php");
739  $_GET["cmd"] = "nop";
740  $glo_gui = new ilGlossaryPresentationGUI();
741  $glo_gui->setOfflineMode(true);
742  $glo_gui->setOfflineDirectory($a_target_dir);
743 
744  // could be implemented in the future if other export
745  // formats are supported (e.g. scorm)
746  //$glo_gui->setExportFormat($a_export_format);
747 
748  // export terms
749  $this->exportHTMLGlossaryTerms($glo_gui, $a_target_dir);
750 
751  // export all media objects
752  foreach ($this->offline_mobs as $mob) {
753  $this->exportHTMLMOB($a_target_dir, $glo_gui, $mob, "_blank");
754  }
755  $_GET["obj_type"] = "MediaObject";
756  $_GET["obj_id"] = $a_mob_id;
757  $_GET["cmd"] = "";
758 
759  // export all file objects
760  foreach ($this->offline_files as $file) {
761  $this->exportHTMLFile($a_target_dir, $file);
762  }
763 
764  // export images
765  $image_dir = $a_target_dir . "/images";
766  ilUtil::makeDir($image_dir);
767  ilUtil::makeDir($image_dir . "/browser");
768  copy(
769  ilUtil::getImagePath("enlarge.svg", false, "filesystem"),
770  $image_dir . "/enlarge.svg"
771  );
772  copy(
773  ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
774  $image_dir . "/browser/plus.png"
775  );
776  copy(
777  ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
778  $image_dir . "/browser/minus.png"
779  );
780  copy(
781  ilUtil::getImagePath("browser/blank.png", false, "filesystem"),
782  $image_dir . "/browser/blank.png"
783  );
784  copy(
785  ilUtil::getImagePath("icon_st.svg", false, "filesystem"),
786  $image_dir . "/icon_st.svg"
787  );
788  copy(
789  ilUtil::getImagePath("icon_pg.svg", false, "filesystem"),
790  $image_dir . "/icon_pg.svg"
791  );
792  copy(
793  ilUtil::getImagePath("nav_arr_L.png", false, "filesystem"),
794  $image_dir . "/nav_arr_L.png"
795  );
796  copy(
797  ilUtil::getImagePath("nav_arr_R.png", false, "filesystem"),
798  $image_dir . "/nav_arr_R.png"
799  );
800 
801  // template workaround: reset of template
802  $tpl = new ilTemplate("tpl.main.html", true, true);
803  $tpl->setVariable("LOCATION_STYLESHEET", $location_stylesheet);
804  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
805 
806  // zip everything
807  if (true) {
808  // zip it all
809  $date = time();
810  $zip_file = $this->getExportDirectory("html") . "/" . $date . "__" . IL_INST_ID . "__" .
811  $this->getType() . "_" . $this->getId() . ".zip";
812  //echo "zip-".$a_target_dir."-to-".$zip_file;
813  ilUtil::zip($a_target_dir, $zip_file);
814  ilUtil::delDir($a_target_dir);
815  }
816  }
817 
818 
822  public function exportHTMLGlossaryTerms(&$a_glo_gui, $a_target_dir)
823  {
824  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
825  $copage_export = new ilCOPageHTMLExport($a_target_dir);
826  $copage_export->exportSupportScripts();
827 
828  // index.html file
829  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
830  $style_name = $this->user->prefs["style"] . ".css";
831  ;
832  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET", "./" . $style_name);
833  $a_glo_gui->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
834  $a_glo_gui->tpl->setTitle($this->getTitle());
835 
836  $content = $a_glo_gui->listTerms();
837  $file = $a_target_dir . "/index.html";
838 
839  // open file
840  if (!($fp = @fopen($file, "w+"))) {
841  die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
842  " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
843  }
844  chmod($file, 0770);
845  fwrite($fp, $content);
846  fclose($fp);
847 
848  $terms = $this->getTermList();
849 
850  $this->offline_mobs = array();
851  $this->offline_files = array();
852 
853  foreach ($terms as $term) {
854  $a_glo_gui->tpl = new ilTemplate("tpl.main.html", true, true);
855  $a_glo_gui->tpl = $copage_export->getPreparedMainTemplate();
856  //$tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
857 
858  // set style
859  $style_name = $this->user->prefs["style"] . ".css";
860  ;
861  $a_glo_gui->tpl->setVariable("LOCATION_STYLESHEET", "./" . $style_name);
862 
863  $_GET["term_id"] = $term["id"];
864  $_GET["frame"] = "_blank";
865  $content = $a_glo_gui->listDefinitions($_GET["ref_id"], $term["id"], false);
866  $file = $a_target_dir . "/term_" . $term["id"] . ".html";
867 
868  // open file
869  if (!($fp = @fopen($file, "w+"))) {
870  die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
871  " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
872  }
873  chmod($file, 0770);
874  fwrite($fp, $content);
875  fclose($fp);
876 
877  // store linked/embedded media objects of glosssary term
878  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
879  $defs = ilGlossaryDefinition::getDefinitionList($term["id"]);
880  foreach ($defs as $def) {
881  $def_mobs = ilObjMediaObject::_getMobsOfObject("gdf:pg", $def["id"]);
882  foreach ($def_mobs as $def_mob) {
883  $this->offline_mobs[$def_mob] = $def_mob;
884  }
885 
886  // get all files of page
887  include_once("./Modules/File/classes/class.ilObjFile.php");
888  $def_files = ilObjFile::_getFilesOfObject("gdf:pg", $def["id"]);
889  $this->offline_files = array_merge($this->offline_files, $def_files);
890  }
891  }
892  }
893 
897  public function exportHTMLMOB($a_target_dir, &$a_glo_gui, $a_mob_id)
898  {
899  $tpl = $this->tpl;
900 
901  $mob_dir = $a_target_dir . "/mobs";
902 
903  $source_dir = ilUtil::getWebspaceDir() . "/mobs/mm_" . $a_mob_id;
904  if (@is_dir($source_dir)) {
905  ilUtil::makeDir($mob_dir . "/mm_" . $a_mob_id);
906  ilUtil::rCopy($source_dir, $mob_dir . "/mm_" . $a_mob_id);
907  }
908 
909  $tpl = new ilTemplate("tpl.main.html", true, true);
910  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
911  $_GET["obj_type"] = "MediaObject";
912  $_GET["mob_id"] = $a_mob_id;
913  $_GET["cmd"] = "";
914  $content = $a_glo_gui->media();
915  $file = $a_target_dir . "/media_" . $a_mob_id . ".html";
916 
917  // open file
918  if (!($fp = @fopen($file, "w+"))) {
919  die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
920  " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
921  }
922  chmod($file, 0770);
923  fwrite($fp, $content);
924  fclose($fp);
925 
926  // fullscreen
927  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
928  $mob_obj = new ilObjMediaObject($a_mob_id);
929  if ($mob_obj->hasFullscreenItem()) {
930  $tpl = new ilTemplate("tpl.main.html", true, true);
931  $tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
932  $_GET["mob_id"] = $a_mob_id;
933  $_GET["cmd"] = "fullscreen";
934  $content = $a_glo_gui->fullscreen();
935  $file = $a_target_dir . "/fullscreen_" . $a_mob_id . ".html";
936 
937  // open file
938  if (!($fp = @fopen($file, "w+"))) {
939  die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
940  " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
941  }
942  chmod($file, 0770);
943  fwrite($fp, $content);
944  fclose($fp);
945  }
946  }
947 
951  public function exportHTMLFile($a_target_dir, $a_file_id)
952  {
953  $file_dir = $a_target_dir . "/files/file_" . $a_file_id;
954  ilUtil::makeDir($file_dir);
955  include_once("./Modules/File/classes/class.ilObjFile.php");
956  $file_obj = new ilObjFile($a_file_id, false);
957  $source_file = $file_obj->getDirectory($file_obj->getVersion()) . "/" . $file_obj->getFileName();
958  if (!is_file($source_file)) {
959  $source_file = $file_obj->getDirectory() . "/" . $file_obj->getFileName();
960  }
961  copy($source_file, $file_dir . "/" . $file_obj->getFileName());
962  }
963 
964 
971  public function exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
972  {
973  // export glossary
974  $attrs = array();
975  $attrs["Type"] = "Glossary";
976  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
977 
978  // MetaData
979  $this->exportXMLMetaData($a_xml_writer);
980 
981  // collect media objects
982  $terms = $this->getTermList();
983  $this->mob_ids = array();
984  $this->file_ids = array();
985  foreach ($terms as $term) {
986  include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php";
987 
988  $defs = ilGlossaryDefinition::getDefinitionList($term[id]);
989 
990  foreach ($defs as $def) {
991  $this->page_object = new ilGlossaryDefPage($def["id"]);
992  $this->page_object->buildDom();
993  $this->page_object->insertInstIntoIDs(IL_INST_ID);
994  $mob_ids = $this->page_object->collectMediaObjects(false);
995  include_once("./Services/COPage/classes/class.ilPCFileList.php");
996  $file_ids = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
997  foreach ($mob_ids as $mob_id) {
998  $this->mob_ids[$mob_id] = $mob_id;
999  }
1000  foreach ($file_ids as $file_id) {
1001  $this->file_ids[$file_id] = $file_id;
1002  }
1003  }
1004  }
1005 
1006  // export media objects
1007  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Media Objects");
1008  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
1009  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Media Objects");
1010 
1011  // FileItems
1012  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export File Items");
1013  $this->exportFileItems($a_target_dir, $expLog);
1014  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export File Items");
1015 
1016  // Glossary
1017  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Glossary Items");
1018  $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
1019  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Glossary Items");
1020 
1021  $a_xml_writer->xmlEndTag("ContentObject");
1022  }
1023 
1030  public function exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
1031  {
1032  $attrs = array();
1033  $a_xml_writer->xmlStartTag("Glossary", $attrs);
1034 
1035  // MetaData
1036  $this->exportXMLMetaData($a_xml_writer);
1037 
1038  $terms = $this->getTermList();
1039 
1040  // export glossary terms
1041  reset($terms);
1042  foreach ($terms as $term) {
1043  $expLog->write(date("[y-m-d H:i:s] ") . "Page Object " . $page["obj_id"]);
1044 
1045  // export xml to writer object
1046  $glo_term = new ilGlossaryTerm($term["id"]);
1047  $glo_term->exportXML($a_xml_writer, $a_inst);
1048 
1049  unset($glo_term);
1050  }
1051 
1052  $a_xml_writer->xmlEndTag("Glossary");
1053  }
1054 
1061  public function exportXMLMetaData(&$a_xml_writer)
1062  {
1063  include_once("Services/MetaData/classes/class.ilMD2XML.php");
1064  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
1065  $md2xml->setExportMode(true);
1066  $md2xml->startExport();
1067  $a_xml_writer->appendXML($md2xml->getXML());
1068  }
1069 
1076  public function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
1077  {
1078  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1079 
1080  foreach ($this->mob_ids as $mob_id) {
1081  $expLog->write(date("[y-m-d H:i:s] ") . "Media Object " . $mob_id);
1082  $media_obj = new ilObjMediaObject($mob_id);
1083  $media_obj->exportXML($a_xml_writer, $a_inst);
1084  $media_obj->exportFiles($a_target_dir);
1085  unset($media_obj);
1086  }
1087  }
1088 
1093  public function exportFileItems($a_target_dir, &$expLog)
1094  {
1095  include_once("./Modules/File/classes/class.ilObjFile.php");
1096 
1097  foreach ($this->file_ids as $file_id) {
1098  $expLog->write(date("[y-m-d H:i:s] ") . "File Item " . $file_id);
1099  $file_obj = new ilObjFile($file_id, false);
1100  $file_obj->export($a_target_dir);
1101  unset($file_obj);
1102  }
1103  }
1104 
1105 
1106 
1110  public function modifyExportIdentifier($a_tag, $a_param, $a_value)
1111  {
1112  if ($a_tag == "Identifier" && $a_param == "Entry") {
1113  $a_value = "il_" . IL_INST_ID . "_glo_" . $this->getId();
1114  }
1115 
1116  return $a_value;
1117  }
1118 
1119 
1120 
1121 
1132  public function delete()
1133  {
1134  // always call parent delete function first!!
1135  if (!parent::delete()) {
1136  return false;
1137  }
1138 
1139  // delete terms
1140  if (!$this->isVirtual()) {
1141  $terms = $this->getTermList();
1142  foreach ($terms as $term) {
1143  $term_obj = new ilGlossaryTerm($term["id"]);
1144  $term_obj->delete();
1145  }
1146  }
1147 
1148  // delete term references
1149  include_once("./Modules/Glossary/classes/class.ilGlossaryTermReferences.php");
1150  $refs = new ilGlossaryTermReferences($this->getId());
1151  $refs->delete();
1152 
1153  // delete glossary data entry
1154  $q = "DELETE FROM glossary WHERE id = " . $this->db->quote($this->getId());
1155  $this->db->query($q);
1156 
1157  // delete meta data
1158  $this->deleteMetaData();
1159 
1160  return true;
1161  }
1162 
1166  public function getXMLZip()
1167  {
1168  include_once("./Modules/Glossary/classes/class.ilGlossaryExport.php");
1169  $glo_exp = new ilGlossaryExport($this);
1170  return $glo_exp->buildExportFile();
1171  }
1172 
1177  public static function getDeletionDependencies($a_obj_id)
1178  {
1179  global $DIC;
1180 
1181  $lng = $DIC->language();
1182 
1183  $dep = array();
1184  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
1186  foreach ($sms as $sm) {
1187  $lng->loadLanguageModule("content");
1188  $dep[$sm] = $lng->txt("glo_used_in_scorm");
1189  }
1190  //echo "-".$a_obj_id."-";
1191  //var_dump($dep);
1192  return $dep;
1193  }
1194 
1200  public function getTaxonomyId()
1201  {
1202  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1203  $tax_ids = ilObjTaxonomy::getUsageOfObject($this->getId());
1204  if (count($tax_ids) > 0) {
1205  // glossaries handle max. one taxonomy
1206  return $tax_ids[0];
1207  }
1208  return 0;
1209  }
1210 
1211 
1218  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1219  {
1220  $new_obj = parent::cloneObject($a_target_id, $a_copy_id, $a_omit_tree);
1221  $this->cloneMetaData($new_obj);
1222 
1223  //copy online status if object is not the root copy object
1224  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1225 
1226  if (!$cp_options->isRootNode($this->getRefId())) {
1227  $new_obj->setOnline($this->getOnline());
1228  }
1229 
1230  // $new_obj->setTitle($this->getTitle());
1231  $new_obj->setDescription($this->getDescription());
1232  $new_obj->setVirtualMode($this->getVirtualMode());
1233  $new_obj->setPresentationMode($this->getPresentationMode());
1234  $new_obj->setSnippetLength($this->getSnippetLength());
1235  $new_obj->setAutoGlossaries($this->getAutoGlossaries());
1236  $new_obj->update();
1237 
1238  // set/copy stylesheet
1239  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
1240  $style_id = $this->getStyleSheetId();
1241  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) {
1242  include_once("./Services/Object/classes/class.ilObjectFactory.php");
1243  $style_obj = ilObjectFactory::getInstanceByObjId($style_id);
1244  $new_id = $style_obj->ilClone();
1245  $new_obj->setStyleSheetId($new_id);
1246  $new_obj->update();
1247  }
1248 
1249  // copy taxonomy
1250  if (($tax_id = $this->getTaxonomyId()) > 0) {
1251  // clone it
1252  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
1253  $tax = new ilObjTaxonomy($tax_id);
1254  $new_tax = $tax->cloneObject(0, 0, true);
1255  $map = $tax->getNodeMapping();
1256 
1257  // assign new taxonomy to new glossary
1258  ilObjTaxonomy::saveUsage($new_tax->getId(), $new_obj->getId());
1259  }
1260 
1261  // assign new tax/new glossary
1262  // handle mapping
1263 
1264  // prepare tax node assignments objects
1265  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
1266  if ($tax_id > 0) {
1267  $tax_ass = new ilTaxNodeAssignment("glo", $this->getId(), "term", $tax_id);
1268  $new_tax_ass = new ilTaxNodeAssignment("glo", $new_obj->getId(), "term", $new_tax->getId());
1269  }
1270 
1271  // copy terms
1272  $term_mappings = array();
1273  foreach (ilGlossaryTerm::getTermList($this->getRefId()) as $term) {
1274  $new_term_id = ilGlossaryTerm::_copyTerm($term["id"], $new_obj->getId());
1275  $term_mappings[$term["id"]] = $new_term_id;
1276 
1277  // copy tax node assignments
1278  if ($tax_id > 0) {
1279  $assignmts = $tax_ass->getAssignmentsOfItem($term["id"]);
1280  foreach ($assignmts as $a) {
1281  if ($map[$a["node_id"]] > 0) {
1282  $new_tax_ass->addAssignment($map[$a["node_id"]], $new_term_id);
1283  }
1284  }
1285  }
1286  }
1287 
1288  // add mapping of term_ids to copy wizard options
1289  if (!empty($term_mappings)) {
1290  $cp_options->appendMapping($this->getRefId() . '_glo_terms', (array) $term_mappings);
1291  }
1292 
1293 
1294  return $new_obj;
1295  }
1296 
1303  public function removeOfflineGlossaries($a_glo_ids, $ids_are_ref_ids = false)
1304  {
1305  $glo_ids = $a_glo_ids;
1306  if ($ids_are_ref_ids) {
1307  $glo_ids = array_map(function ($id) {
1309  }, $a_glo_ids);
1310  }
1311 
1312  $set = $this->db->query(
1313  "SELECT id FROM glossary " .
1314  " WHERE " . $this->db->in("id", $glo_ids, false, "integer") .
1315  " AND is_online = " . $this->db->quote("y", "text")
1316  );
1317  $online_glo_ids = array();
1318  while ($rec = $this->db->fetchAssoc($set)) {
1319  $online_glo_ids[] = $rec["id"];
1320  }
1321 
1322  if (!$ids_are_ref_ids) {
1323  return $online_glo_ids;
1324  }
1325 
1326  $online_ref_ids = array_filter($a_glo_ids, function ($ref_id) use ($online_glo_ids) {
1327  return in_array(ilObject::_lookupObjectId($ref_id), $online_glo_ids);
1328  });
1329 
1330 
1331  return $online_ref_ids;
1332  }
1333 
1334  public static function getAdvMDSubItemTitle($a_obj_id, $a_sub_type, $a_sub_id)
1335  {
1336  global $DIC;
1337 
1338  $lng = $DIC->language();
1339 
1340  if ($a_sub_type == "term") {
1341  $lng->loadLanguageModule("glo");
1342 
1343  include_once "Modules/Glossary/classes/class.ilGlossaryTerm.php";
1344  return $lng->txt("glo_term") . ' "' . ilGlossaryTerm::_lookGlossaryTerm($a_sub_id) . '"';
1345  }
1346  }
1347 
1354  public function autoLinkGlossaryTerms($a_glo_ref_id)
1355  {
1356  // get terms of target glossary
1357  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
1358  $terms = ilGlossaryTerm::getTermList($a_glo_ref_id);
1359 
1360  // for each get page: get content
1361  $source_terms = ilGlossaryTerm::getTermList($this->getRefId());
1362  $found_pages = array();
1363  foreach ($source_terms as $source_term) {
1364  $source_defs = ilGlossaryDefinition::getDefinitionList($source_term["id"]);
1365 
1366  for ($j = 0; $j < count($source_defs); $j++) {
1367  $def = $source_defs[$j];
1368  $pg = new ilGlossaryDefPage($def["id"]);
1369 
1370  $c = $pg->getXMLContent();
1371  foreach ($terms as $t) {
1372  if (is_int(stripos($c, $t["term"]))) {
1373  $found_pages[$def["id"]]["terms"][] = $t;
1374  if (!is_object($found_pages[$def["id"]]["page"])) {
1375  $found_pages[$def["id"]]["page"] = $pg;
1376  }
1377  }
1378  }
1379  reset($terms);
1380  }
1381  }
1382 
1383  // ilPCParagraph autoLinkGlossariesPage with page and terms
1384  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
1385  foreach ($found_pages as $id => $fp) {
1386  ilPCParagraph::autoLinkGlossariesPage($fp["page"], $fp["terms"]);
1387  }
1388  }
1389 
1395  public function supportsLongTextQuery()
1396  {
1397  return true;
1398  }
1399 }
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
setStyleSheetId($a_style_id)
Set ID of assigned style sheet object.
read()
read data of content object
getAssignmentsOfItem($a_item_id)
Get assignments for item.
setAutoGlossaries($a_val)
Set auto glossaries.
static tf2yn($a_tf)
convert true/false to "y"/"n"
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
static getDefinitionList($a_term_id)
static
exportXMLGlossaryItems(&$a_xml_writer, $a_inst, &$expLog)
export page objects to xml (see ilias_co.dtd)
$style
Definition: example_012.php:70
Class ilGlossaryPresentationGUI.
Taxonomy node <-> item assignment.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
getDescription()
get description of glossary object
getTermList( $searchterm="", $a_letter="", $a_def="", $a_tax_node=0, $a_include_offline_childs=false, $a_add_amet_fields=false, array $a_amet_filter=null, $a_omit_virtual=false, $a_include_references=false)
Get term list.
static getAdvMDSubItemTitle($a_obj_id, $a_sub_type, $a_sub_id)
setShowTaxonomy($a_val)
Set show taxonomy.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $DIC
Definition: saml.php:7
HTML export class for pages.
setPresentationMode($a_val)
Set presentation mode.
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
$_GET["client_id"]
Class ilGlossaryTerm.
Class ilObjGlossary.
static _getExportFiles($a_obj_id, $a_export_types="", $a_obj_type="")
Get Export Files for a repository object.
updateMetaData()
update meta data entry
exportHTMLFile($a_target_dir, $a_file_id)
export file object
exportHTML($a_target_dir, $log)
export html package
autoLinkGlossaryTerms($a_glo_ref_id)
Auto link glossary terms.
createMetaData()
create meta data entry
getPublicExportFile($a_type)
get public export file
setDescription($a_description)
set description of glossary object
setPublicExportFile($a_type, $a_file)
specify public export file for type
static lookupObjectStyle($a_obj_id)
Lookup object style.
user()
Definition: user.php:4
$ilErr
Definition: raiseError.php:18
createExportDirectory($a_type="xml")
Creates export directory.
setActiveGlossaryMenu($a_act_glo_menu)
static _lookupObjectId($a_ref_id)
lookup object id
static _lookupStandard($a_id)
Lookup standard flag.
getFirstLetters($a_tax_node=0)
Get term list.
getTitle()
get title of glossary object
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
getAllGlossaryIds($a_include_offline_childs=false, $ids_are_ref_ids=false)
Get all glossary ids.
$a_type
Definition: workflow.php:92
static autoLinkGlossariesPage($a_page, $a_terms)
Auto link glossary of whole page.
getExportDirectory($a_type="xml")
Get export directory of glossary.
exportXMLMetaData(&$a_xml_writer)
export content objects meta data to xml (see ilias_co.dtd)
getVirtualMode()
get glossary type (normal or virtual)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
Interface for repository objects to use adv md with subitems.
setVirtualMode($a_mode)
set glossary type (virtual: fixed/level/subtree, normal:none)
createImportDirectory()
creates data directory for import files (data_dir/glo_data/glo_<id>/import, depending on data directo...
getId()
get object id public
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone glossary.
exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
export media objects to xml (see ilias_co.dtd)
static getFirstLetters($a_glo_id, $a_tax_node=0)
Get all terms for given set of glossary ids.
getTaxonomyId()
Get taxonomy.
__construct($a_id=0, $a_call_by_reference=true)
Constructor public.
special template class to simplify handling of ITX/PEAR
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
exportXML(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
export object to xml (see ilias_co.dtd)
getXMLZip()
Get zipped xml file for glossary.
updateAutoGlossaries()
Update auto glossaries.
static getTermList( $a_glo_ref_id, $searchterm="", $a_first_letter="", $a_def="", $a_tax_node=0, $a_add_amet_fields=false, array $a_amet_filter=null, $a_include_references=false)
Get all terms for given set of glossary ids.
removeOfflineGlossaries($a_glo_ids, $ids_are_ref_ids=false)
Remove offline glossaries from obj id array.
cloneMetaData($target_obj)
Copy meta data.
getPresentationMode()
Get presentation mode.
Class ilObjMediaObject.
static getSyntaxStylePath()
get syntax style path
getSnippetLength()
Get snippet length.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
getType()
get object type public
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
Glossary definition page object.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
const PURPOSE_EXPORT
static _lookupType($a_id, $a_reference=false)
lookup object type
getShowTaxonomy()
Get show taxonomy.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
getImportDirectory()
get import directory of glossary
getAutoGlossaries()
Get auto glossaries.
update($pash, $contents, Config $config)
create($a_upload=false)
create glossary object
removeAutoGlossary($a_glo_id)
Remove auto glossary.
static _copyTerm($a_term_id, $a_glossary_id)
Copy a term to a glossary.
exportHTMLMOB($a_target_dir, &$a_glo_gui, $a_mob_id)
export media object to html
static lookup($a_id, $a_property)
Lookup glossary property.
static getScormModulesForGlossary($a_glo_id)
Get SCORM modules that assign a certain glossary.
static getDataDir()
get data directory (outside webspace)
getStyleSheetId()
Get ID of assigned style sheet object.
$lm_set
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static getInstance()
Singleton: get instance.
Class ilObjStyleSheet.
modifyExportIdentifier($a_tag, $a_param, $a_value)
addAutoGlossary($glo_id)
Add auto glossary.
getRefId()
get reference id public
exportFileItems($a_target_dir, &$expLog)
export files of file itmes
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
$def
Definition: croninfo.php:21
deleteMetaData()
delete meta data entry
isVirtual()
returns true if glossary type is virtual (any mode)
Export class for content objects.
static getDeletionDependencies($a_obj_id)
Get deletion dependencies.
setTitle($a_title)
set title of glossary object
getExportFiles()
Get export files.
static yn2tf($a_yn)
convert "y"/"n" to true/false
setSnippetLength($a_val)
Set snippet length.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
update()
Update object.
exportHTMLGlossaryTerms(&$a_glo_gui, $a_target_dir)
export glossary terms
static _lookGlossaryTerm($term_id)
get glossary term
supportsLongTextQuery()
Is long text search supported.
static lookupAutoGlossaries($a_id)
Lookup auto glossaries.
static _lookupOnline($a_id)
check wether content object is online
static lookupSnippetLength($a_id)
Lookup snippet length.