ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjGlossary.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  protected \ILIAS\Glossary\Term\TermManager $term_manager;
25  protected \ILIAS\Style\Content\DomainService $content_style_domain;
27  protected array $file_ids = [];
28  protected array $mob_ids = [];
29  protected bool $show_tax = false;
30  protected int $style_id = 0;
31  protected bool $downloads_active = false;
32  protected bool $glo_menu_active = false;
33  protected bool $online = false;
34  protected int $snippet_length = 0;
35  protected string $pres_mode = "";
36  protected bool $virtual = false;
37  protected string $virtual_mode = "";
38  protected bool $flashcards_active = false;
39  protected string $flashcards_mode = "";
41  public array $auto_glossaries = array();
42  protected ilObjUser $user;
43  protected array $public_export_file = [];
44 
45 
46  public function __construct(
47  int $a_id = 0,
48  bool $a_call_by_reference = true
49  ) {
50  global $DIC;
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  $this->content_style_domain = $DIC
58  ->contentStyle()
59  ->domain();
60  $this->term_manager = $DIC->glossary()->internal()->domain()->term($this);
61  }
62 
63  public function create(bool $a_upload = false): int
64  {
65  $id = parent::create();
66 
67  // meta data will be created by
68  // import parser
69  if (!$a_upload) {
70  $this->createMetaData();
71  }
72  $this->db->insert(
73  'glossary',
74  array(
75  'id' => array('integer', $this->getId()),
76  'is_online' => array('text', 'n'),
77  'virtual' => array('text', $this->getVirtualMode()),
78  'pres_mode' => array('text', 'table'),
79  'snippet_length' => array('integer', 200)
80  )
81  );
82 
83  $this->setPresentationMode("table");
84  $this->setSnippetLength(200);
85 
86  $this->updateAutoGlossaries();
87 
88  return $id;
89  }
90 
91  public function read(): void
92  {
93  parent::read();
94 
95  $q = "SELECT * FROM glossary WHERE id = " .
96  $this->db->quote($this->getId(), "integer");
97  $gl_set = $this->db->query($q);
98  $gl_rec = $this->db->fetchAssoc($gl_set);
99  $this->setOnline(ilUtil::yn2tf($gl_rec["is_online"]));
100  $this->setVirtualMode((string) ($gl_rec["virtual"] ?? ""));
101  if (isset($gl_rec["public_xml_file"]) && $gl_rec["public_xml_file"] != "") {
102  $this->setPublicExportFile("xml", $gl_rec["public_xml_file"]);
103  }
104  if (isset($gl_rec["public_html_file"]) && $gl_rec["public_html_file"] != "") {
105  $this->setPublicExportFile("html", $gl_rec["public_html_file"]);
106  }
107  $this->setActiveGlossaryMenu(ilUtil::yn2tf($gl_rec["glo_menu_active"]));
108  $this->setActiveDownloads(ilUtil::yn2tf($gl_rec["downloads_active"]));
109  $this->setPresentationMode((string) $gl_rec["pres_mode"]);
110  $this->setSnippetLength((int) $gl_rec["snippet_length"]);
111  $this->setShowTaxonomy((bool) $gl_rec["show_tax"]);
112  $this->setActiveFlashcards(ilUtil::yn2tf($gl_rec["flash_active"]));
113  $this->setFlashcardsMode($gl_rec["flash_mode"]);
114 
115  // read auto glossaries
116  $set = $this->db->query(
117  "SELECT * FROM glo_glossaries " .
118  " WHERE id = " . $this->db->quote($this->getId(), "integer")
119  );
120  $glos = array();
121  while ($rec = $this->db->fetchAssoc($set)) {
122  $glos[] = $rec["glo_id"];
123  }
124  $this->setAutoGlossaries($glos);
125  }
126 
127  public function setVirtualMode(string $a_mode): void
128  {
129  switch ($a_mode) {
130  case "coll":
131  $this->virtual_mode = $a_mode;
132  $this->virtual = true;
133  break;
134 
135  default:
136  $this->virtual_mode = "none";
137  $this->virtual = false;
138  break;
139  }
140  }
141 
142  public function getVirtualMode(): string
143  {
144  return $this->virtual_mode;
145  }
146 
147  public function isVirtual(): bool
148  {
149  return $this->virtual;
150  }
151 
152  public function setPresentationMode(string $a_val): void
153  {
154  $this->pres_mode = $a_val;
155  }
156 
157  public function getPresentationMode(): string
158  {
159  return $this->pres_mode;
160  }
161 
163  public function setSnippetLength(int $a_val): void
164  {
165  $this->snippet_length = $a_val;
166  }
167 
168  public function getSnippetLength(): int
169  {
170  return ($this->snippet_length > 0)
171  ? $this->snippet_length
172  : 200;
173  }
174 
175  public function setOnline(bool $a_online): void
176  {
177  $this->online = $a_online;
178  }
179 
180  public function getOnline(): bool
181  {
182  return $this->online;
183  }
184 
185  public static function _lookupOnline(
186  int $a_id
187  ): bool {
188  global $DIC;
189 
190  $db = $DIC->database();
191 
192  $q = "SELECT is_online FROM glossary WHERE id = " .
193  $db->quote($a_id, "integer");
194  $lm_set = $db->query($q);
195  $lm_rec = $db->fetchAssoc($lm_set);
196 
197  return ilUtil::yn2tf($lm_rec["is_online"]);
198  }
199 
203  protected static function lookup(
204  int $a_id,
205  string $a_property
206  ): string {
207  global $DIC;
208 
209  $db = $DIC->database();
210 
211  $set = $db->query("SELECT $a_property FROM glossary WHERE id = " .
212  $db->quote($a_id, "integer"));
213  $rec = $db->fetchAssoc($set);
214 
215  return $rec[$a_property];
216  }
217 
218  public static function lookupSnippetLength(int $a_id): int
219  {
220  return (int) self::lookup($a_id, "snippet_length");
221  }
222 
223 
224  public function setActiveGlossaryMenu(bool $a_act_glo_menu): void
225  {
226  $this->glo_menu_active = $a_act_glo_menu;
227  }
228 
229  public function isActiveGlossaryMenu(): bool
230  {
231  return $this->glo_menu_active;
232  }
233 
234  public function setActiveDownloads(bool $a_down): void
235  {
236  $this->downloads_active = $a_down;
237  }
238 
239  public function isActiveDownloads(): bool
240  {
242  }
243 
244  public function setShowTaxonomy(bool $a_val): void
245  {
246  $this->show_tax = $a_val;
247  }
248 
249  public function getShowTaxonomy(): bool
250  {
251  return $this->show_tax;
252  }
253 
254  public function setActiveFlashcards(bool $a_flash): void
255  {
256  $this->flashcards_active = $a_flash;
257  }
258 
259  public function isActiveFlashcards(): bool
260  {
262  }
263 
264  public function setFlashcardsMode(string $a_flash): void
265  {
266  $this->flashcards_mode = $a_flash;
267  }
268 
269  public function getFlashcardsMode(): string
270  {
271  return $this->flashcards_mode;
272  }
273 
277  public function setAutoGlossaries(
278  array $a_val
279  ): void {
280  $this->auto_glossaries = array();
281  foreach ($a_val as $v) {
282  $this->addAutoGlossary($v);
283  }
284  }
285 
286  public function addAutoGlossary(int $glo_id): void
287  {
288  if ($glo_id > 0 && ilObject::_lookupType($glo_id) == "glo" &&
289  !in_array($glo_id, $this->auto_glossaries)) {
290  $this->auto_glossaries[] = $glo_id;
291  }
292  }
293 
297  public function getAutoGlossaries(): array
298  {
299  return $this->auto_glossaries;
300  }
301 
302  public function removeAutoGlossary(
303  int $a_glo_id
304  ): void {
305  $glo_ids = array();
306  foreach ($this->getAutoGlossaries() as $g) {
307  if ($g != $a_glo_id) {
308  $glo_ids[] = $g;
309  }
310  }
311  $this->setAutoGlossaries($glo_ids);
312  }
313 
314  public function update(): bool
315  {
316  $this->updateMetaData();
317 
318  $this->db->update(
319  'glossary',
320  array(
321  'is_online' => array('text', ilUtil::tf2yn($this->getOnline())),
322  'virtual' => array('text', $this->getVirtualMode()),
323  'public_xml_file' => array('text', $this->getPublicExportFile("xml")),
324  'public_html_file' => array('text', $this->getPublicExportFile("html")),
325  'glo_menu_active' => array('text', ilUtil::tf2yn($this->isActiveGlossaryMenu())),
326  'downloads_active' => array('text', ilUtil::tf2yn($this->isActiveDownloads())),
327  'pres_mode' => array('text', $this->getPresentationMode()),
328  'show_tax' => array('integer', $this->getShowTaxonomy()),
329  'snippet_length' => array('integer', $this->getSnippetLength()),
330  'flash_active' => array('text', ilUtil::tf2yn($this->isActiveFlashcards())),
331  'flash_mode' => array('text', $this->getFlashcardsMode())
332  ),
333  array(
334  'id' => array('integer', $this->getId())
335  )
336  );
337 
338  $this->updateAutoGlossaries();
339  return parent::update();
340  }
341 
342  public function updateAutoGlossaries(): void
343  {
344  // update auto glossaries
345  $this->db->manipulate(
346  "DELETE FROM glo_glossaries WHERE " .
347  " id = " . $this->db->quote($this->getId(), "integer")
348  );
349  foreach ($this->getAutoGlossaries() as $glo_id) {
350  $this->db->insert(
351  'glo_glossaries',
352  array(
353  'id' => array('integer', $this->getId()),
354  'glo_id' => array('integer', $glo_id)
355  )
356  );
357  }
358  }
359 
360  public static function lookupAutoGlossaries(
361  int $a_id
362  ): array {
363  global $DIC;
364 
365  $db = $DIC->database();
366 
367  // read auto glossaries
368  $set = $db->query(
369  "SELECT * FROM glo_glossaries " .
370  " WHERE id = " . $db->quote($a_id, "integer")
371  );
372  $glos = array();
373  while ($rec = $db->fetchAssoc($set)) {
374  $glos[] = (int) $rec["glo_id"];
375  }
376  return $glos;
377  }
378 
382  public function getGlossariesForCollection(): array
383  {
384  $set = $this->db->query(
385  "SELECT * FROM glossary_collection " .
386  " WHERE id = " . $this->db->quote($this->getId(), "integer")
387  );
388  $glos = [];
389  while ($rec = $this->db->fetchAssoc($set)) {
390  $glos[] = (int) $rec["glo_id"];
391  }
392 
393  return $glos;
394  }
395 
396  public function addGlossaryForCollection(int $glo_id): void
397  {
398  $this->db->replace(
399  "glossary_collection",
400  [
401  "id" => ["integer", $this->getId()],
402  "glo_id" => ["integer", $glo_id]
403  ],
404  []
405  );
406  }
407 
408  public function removeGlossaryFromCollection(int $glo_id): void
409  {
410  $this->db->manipulate(
411  "DELETE FROM glossary_collection WHERE " .
412  " id = " . $this->db->quote($this->getId(), "integer") .
413  " AND glo_id = " . $this->db->quote($glo_id, "integer")
414  );
415  }
416 
417  public function getTermList(
418  string $searchterm = "",
419  string $a_letter = "",
420  string $a_def = "",
421  int $a_tax_node = 0,
422  bool $a_include_offline_childs = false,
423  bool $a_add_amet_fields = false,
424  array $a_amet_filter = null,
425  bool $a_omit_virtual = false,
426  bool $a_include_references = false
427  ): array {
428  if ($a_omit_virtual) {
429  $glo_ref_ids[] = $this->getRefId();
430  } else {
431  $glo_ref_ids = $this->getAllGlossaryIds($a_include_offline_childs, true);
432  }
434  $glo_ref_ids,
435  $searchterm,
436  $a_letter,
437  $a_def,
438  $a_tax_node,
439  $a_add_amet_fields,
440  $a_amet_filter,
441  $a_include_references
442  );
443  return $list;
444  }
445 
446  public function getFirstLetters(
447  int $a_tax_node = 0
448  ): array {
449  $glo_ids = $this->getAllGlossaryIds();
450  $first_letters = ilGlossaryTerm::getFirstLetters($glo_ids, $a_tax_node);
451  return $first_letters;
452  }
453 
458  public function getAllGlossaryIds(
459  bool $a_include_offline_childs = false,
460  bool $ids_are_ref_ids = false
461  ): array {
462  global $DIC;
463 
464  $tree = $DIC->repositoryTree();
465 
466  if ($this->isVirtual()) {
467  $glo_ids = array();
468 
469  $virtual_mode = $this->getRefId() ? $this->getVirtualMode() : '';
470  if ($virtual_mode === "coll") {
471  $glo_ids = $this->getGlossariesForCollection();
472  if ($ids_are_ref_ids) {
473  $glo_ref_ids = [];
474  foreach ($glo_ids as $obj_id) {
475  $glo_ref_ids[] = current(ilObject::_getAllReferences($obj_id));
476  }
477  $glo_ids = $glo_ref_ids;
478  }
479  }
480  if (!$a_include_offline_childs) {
481  $glo_ids = $this->removeOfflineGlossaries($glo_ids, $ids_are_ref_ids);
482  }
483  // always show entries of current glossary (if no permission is given, user will not come to the presentation screen)
484  // see bug #14477
485  if ($ids_are_ref_ids) {
486  if (!in_array($this->getRefId(), $glo_ids)) {
487  $glo_ids[] = $this->getRefId();
488  }
489  } elseif (!in_array($this->getId(), $glo_ids)) {
490  $glo_ids[] = $this->getId();
491  }
492  } elseif ($ids_are_ref_ids) {
493  $glo_ids = [$this->getRefId()];
494  } else {
495  $glo_ids = [$this->getId()];
496  }
497 
498  return $glo_ids;
499  }
500 
506  public function createImportDirectory(): void
507  {
508  $glo_data_dir = ilFileUtils::getDataDir() . "/glo_data";
509  ilFileUtils::makeDir($glo_data_dir);
510  if (!is_writable($glo_data_dir)) {
511  throw new ilGlossaryException("Glossary Data Directory (" . $glo_data_dir
512  . ") not writeable.");
513  }
514 
515  // create glossary directory (data_dir/glo_data/glo_<id>)
516  $glo_dir = $glo_data_dir . "/glo_" . $this->getId();
517  ilFileUtils::makeDir($glo_dir);
518  if (!is_dir($glo_dir)) {
519  throw new ilGlossaryException("Creation of Glossary Directory failed.");
520  }
521  // create Import subdirectory (data_dir/glo_data/glo_<id>/import)
522  $import_dir = $glo_dir . "/import";
523  ilFileUtils::makeDir($import_dir);
524  if (!is_dir($import_dir)) {
525  throw new ilGlossaryException("Creation of Export Directory failed.");
526  }
527  }
528 
529  public function getImportDirectory(): string
530  {
531  $export_dir = ilFileUtils::getDataDir() . "/glo_data" . "/glo_" . $this->getId() . "/import";
532 
533  return $export_dir;
534  }
535 
536  public function createExportDirectory(string $a_type = "xml"): string
537  {
538  return ilExport::_createExportDirectory($this->getId(), $a_type, $this->getType());
539  }
540 
541  public function getExportDirectory(string $a_type = "xml"): string
542  {
543  return ilExport::_getExportDirectory($this->getId(), $a_type, $this->getType());
544  }
545 
549  public function getExportFiles(): array
550  {
551  return ilExport::_getExportFiles($this->getId(), array("xml", "html"), $this->getType());
552  }
553 
559  public function setPublicExportFile(
560  string $a_type,
561  string $a_file
562  ): void {
563  $this->public_export_file[$a_type] = $a_file;
564  }
565 
570  public function getPublicExportFile(string $a_type): string
571  {
572  return $this->public_export_file[$a_type] ?? "";
573  }
574 
575  public function exportXML(
576  ilXmlWriter $a_xml_writer,
577  int $a_inst,
578  string $a_target_dir,
579  ilLog $expLog
580  ): void {
581  // export glossary
582  $attrs = array();
583  $attrs["Type"] = "Glossary";
584  $a_xml_writer->xmlStartTag("ContentObject", $attrs);
585 
586  // MetaData
587  $this->exportXMLMetaData($a_xml_writer);
588 
589  // collect media objects
590  $terms = $this->getTermList();
591  $this->mob_ids = array();
592  $this->file_ids = array();
593  foreach ($terms as $term) {
594  $this->page_object = new ilGlossaryDefPage($term["id"]);
595  $this->page_object->buildDom();
596  $this->page_object->insertInstIntoIDs(IL_INST_ID);
597  $mob_ids = $this->page_object->collectMediaObjects(false);
598  $file_ids = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
599  foreach ($mob_ids as $mob_id) {
600  $this->mob_ids[$mob_id] = $mob_id;
601  }
602  foreach ($file_ids as $file_id) {
603  $this->file_ids[$file_id] = $file_id;
604  }
605  }
606 
607  // export media objects
608  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Media Objects");
609  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
610  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Media Objects");
611 
612  // FileItems
613  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export File Items");
614  $this->exportFileItems($a_target_dir, $expLog);
615  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export File Items");
616 
617  // Glossary
618  $expLog->write(date("[y-m-d H:i:s] ") . "Start Export Glossary Items");
619  $this->exportXMLGlossaryItems($a_xml_writer, $a_inst, $expLog);
620  $expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Glossary Items");
621 
622  $a_xml_writer->xmlEndTag("ContentObject");
623  }
624 
625  public function exportXMLGlossaryItems(
626  ilXmlWriter $a_xml_writer,
627  int $a_inst,
628  ilLog $expLog
629  ): void {
630  $attrs = array();
631  $a_xml_writer->xmlStartTag("Glossary", $attrs);
632 
633  // MetaData
634  $this->exportXMLMetaData($a_xml_writer);
635 
636  $terms = $this->getTermList();
637 
638  // export glossary terms
639  reset($terms);
640  foreach ($terms as $term) {
641  $expLog->write(date("[y-m-d H:i:s] ") . "Page Object " . $term["obj_id"]);
642 
643  // export xml to writer object
644  $glo_term = new ilGlossaryTerm($term["id"]);
645  $glo_term->exportXML($a_xml_writer, $a_inst);
646 
647  unset($glo_term);
648  }
649 
650  $a_xml_writer->xmlEndTag("Glossary");
651  }
652 
653  public function exportXMLMetaData(
654  ilXmlWriter $a_xml_writer
655  ): void {
656  $md2xml = new ilMD2XML($this->getId(), 0, $this->getType());
657  $md2xml->setExportMode(true);
658  $md2xml->startExport();
659  $a_xml_writer->appendXML($md2xml->getXML());
660  }
661 
662  public function exportXMLMediaObjects(
663  ilXmlWriter $a_xml_writer,
664  int $a_inst,
665  string $a_target_dir,
666  ilLog $expLog
667  ): void {
668  foreach ($this->mob_ids as $mob_id) {
669  $expLog->write(date("[y-m-d H:i:s] ") . "Media Object " . $mob_id);
670  $media_obj = new ilObjMediaObject($mob_id);
671  $media_obj->exportXML($a_xml_writer, $a_inst);
672  $media_obj->exportFiles($a_target_dir);
673  unset($media_obj);
674  }
675  }
676 
677  public function exportFileItems(
678  string $a_target_dir,
679  ilLog $expLog
680  ): void {
681  foreach ($this->file_ids as $file_id) {
682  $expLog->write(date("[y-m-d H:i:s] ") . "File Item " . $file_id);
683  $file_obj = new ilObjFile($file_id, false);
684  $file_obj->export($a_target_dir);
685  unset($file_obj);
686  }
687  }
688 
689  public function modifyExportIdentifier(
690  string $a_tag,
691  string $a_param,
692  string $a_value
693  ): string {
694  if ($a_tag == "Identifier" && $a_param == "Entry") {
695  $a_value = "il_" . IL_INST_ID . "_glo_" . $this->getId();
696  }
697  return $a_value;
698  }
699 
700  public function delete(): bool
701  {
702  // always call parent delete function first!!
703  if (!parent::delete()) {
704  return false;
705  }
706 
707  // delete terms
708  if (!$this->isVirtual()) {
709  $terms = $this->getTermList();
710  foreach ($terms as $term) {
711  $this->term_manager->deleteTerm((int) $term["id"]);
712  }
713  }
714 
715  // delete term references
716  $refs = new ilGlossaryTermReferences($this->getId());
717  $refs->delete();
718 
719  // delete glossary data entry
720  $q = "DELETE FROM glossary WHERE id = " . $this->db->quote($this->getId());
721  $this->db->query($q);
722 
723  // delete meta data
724  $this->deleteMetaData();
725 
726  return true;
727  }
728 
729  public function getXMLZip(): string
730  {
731  $glo_exp = new ilGlossaryExport($this);
732  return $glo_exp->buildExportFile();
733  }
734 
735  public static function getDeletionDependencies(int $obj_id): array
736  {
737  global $DIC;
738 
739  $lng = $DIC->language();
740 
741  $dep = array();
743  foreach ($sms as $sm) {
744  $lng->loadLanguageModule("content");
745  $dep[$sm] = $lng->txt("glo_used_in_scorm");
746  }
747  return $dep;
748  }
749 
750  public function getTaxonomyId(): int
751  {
752  $tax_ids = ilObjTaxonomy::getUsageOfObject($this->getId());
753  if (count($tax_ids) > 0) {
754  // glossaries handle max. one taxonomy
755  return (int) $tax_ids[0];
756  }
757  return 0;
758  }
759 
760 
761  public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree = false): ?ilObject
762  {
763  $new_obj = parent::cloneObject($target_id, $copy_id, $omit_tree);
764  $this->cloneMetaData($new_obj);
765 
766  $tax_ass = null;
767  $new_tax_ass = null;
768  $map = [];
769 
770  //copy online status if object is not the root copy object
771  $cp_options = ilCopyWizardOptions::_getInstance($copy_id);
772 
773  if (!$cp_options->isRootNode($this->getRefId())) {
774  $new_obj->setOnline($this->getOnline());
775  }
776 
777  // $new_obj->setTitle($this->getTitle());
778  $new_obj->setDescription($this->getDescription());
779  $new_obj->setVirtualMode($this->getVirtualMode());
780  $new_obj->setPresentationMode($this->getPresentationMode());
781  $new_obj->setSnippetLength($this->getSnippetLength());
782  $new_obj->setAutoGlossaries($this->getAutoGlossaries());
783  $new_obj->setActiveFlashcards($this->isActiveFlashcards());
784  $new_obj->setFlashcardsMode($this->getFlashcardsMode());
785  $new_obj->update();
786 
787  // set/copy stylesheet
788  $this->content_style_domain->styleForRefId($this->getRefId())->cloneTo($new_obj->getId());
789 
790  // copy taxonomy
791  if (($tax_id = $this->getTaxonomyId()) > 0) {
792  // clone it
793  $tax = new ilObjTaxonomy($tax_id);
794  $new_tax = $tax->cloneObject(0, 0, true);
795  $map = $tax->getNodeMapping();
796 
797  // assign new taxonomy to new glossary
798  ilObjTaxonomy::saveUsage($new_tax->getId(), $new_obj->getId());
799 
800  $tax_ass = new ilTaxNodeAssignment("glo", $this->getId(), "term", $tax_id);
801  $new_tax_ass = new ilTaxNodeAssignment("glo", $new_obj->getId(), "term", $new_tax->getId());
802  }
803 
804  // copy terms
805  $term_mappings = array();
806  foreach (ilGlossaryTerm::getTermList([$this->getRefId()]) as $term) {
807  $new_term_id = ilGlossaryTerm::_copyTerm($term["id"], $new_obj->getId());
808  $term_mappings[$term["id"]] = $new_term_id;
809 
810  // copy tax node assignments
811  if ($tax_id > 0) {
812  $assignmts = $tax_ass->getAssignmentsOfItem($term["id"]);
813  foreach ($assignmts as $a) {
814  if ($map[$a["node_id"]] > 0) {
815  $new_tax_ass->addAssignment($map[$a["node_id"]], $new_term_id);
816  }
817  }
818  }
819  }
820 
821  // add mapping of term_ids to copy wizard options
822  if (!empty($term_mappings)) {
823  $cp_options->appendMapping($this->getRefId() . '_glo_terms', $term_mappings);
824  }
825 
826  // copy collection glossaries
827  foreach ($this->getGlossariesForCollection() as $glo_id) {
828  $new_obj->addGlossaryForCollection($glo_id);
829  }
830 
831  return $new_obj;
832  }
833 
837  public function removeOfflineGlossaries(
838  array $a_glo_ids,
839  bool $ids_are_ref_ids = false
840  ): array {
841  $glo_ids = $a_glo_ids;
842  if ($ids_are_ref_ids) {
843  $glo_ids = array_map(static function ($id): int {
845  }, $a_glo_ids);
846  }
847 
848  $set = $this->db->query(
849  "SELECT id FROM glossary " .
850  " WHERE " . $this->db->in("id", $glo_ids, false, "integer") .
851  " AND is_online = " . $this->db->quote("y", "text")
852  );
853  $online_glo_ids = array();
854  while ($rec = $this->db->fetchAssoc($set)) {
855  $online_glo_ids[] = $rec["id"];
856  }
857 
858  if (!$ids_are_ref_ids) {
859  return $online_glo_ids;
860  }
861 
862  $online_ref_ids = array_filter($a_glo_ids, static function ($ref_id) use ($online_glo_ids): bool {
863  return in_array(ilObject::_lookupObjectId($ref_id), $online_glo_ids);
864  });
865 
866 
867  return $online_ref_ids;
868  }
869 
870  public static function getAdvMDSubItemTitle(int $a_obj_id, string $a_sub_type, int $a_sub_id): string
871  {
872  global $DIC;
873 
874  $lng = $DIC->language();
875 
876  if ($a_sub_type == "term") {
877  $lng->loadLanguageModule("glo");
878 
879  return $lng->txt("glo_term") . ' "' . ilGlossaryTerm::_lookGlossaryTerm($a_sub_id) . '"';
880  }
881  return "";
882  }
883 
887  public function autoLinkGlossaryTerms(
888  int $a_glo_ref_id
889  ): void {
890  // get terms of target glossary
891  $terms = ilGlossaryTerm::getTermList([$a_glo_ref_id]);
892 
893  // for each get page: get content
894  $source_terms = ilGlossaryTerm::getTermList([$this->getRefId()]);
895  $found_pages = array();
896  foreach ($source_terms as $source_term) {
897  $pg = new ilGlossaryDefPage($source_term["id"]);
898  $c = $pg->getXMLContent();
899  foreach ($terms as $t) {
900  if (is_int(stripos($c, $t["term"]))) {
901  $found_pages[$source_term["id"]]["terms"][] = $t;
902  if (!isset($found_pages[$source_term["id"]]["page"])) {
903  $found_pages[$source_term["id"]]["page"] = $pg;
904  }
905  }
906  }
907  reset($terms);
908  }
909 
910  // ilPCParagraph autoLinkGlossariesPage with page and terms
911  foreach ($found_pages as $id => $fp) {
912  ilPCParagraph::autoLinkGlossariesPage($fp["page"], $fp["terms"]);
913  }
914  }
915 
919  public function supportsLongTextQuery(): bool
920  {
921  return true;
922  }
923 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSnippetLength(int $a_val)
Set definition snippet length (in overview)
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
getAllGlossaryIds(bool $a_include_offline_childs=false, bool $ids_are_ref_ids=false)
Get all glossary ids.
setAutoGlossaries(array $a_val)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
removeAutoGlossary(int $a_glo_id)
ilGlossaryDefPage $page_object
addGlossaryForCollection(int $glo_id)
fetchAssoc(ilDBStatement $statement)
setActiveFlashcards(bool $a_flash)
setPresentationMode(string $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static autoLinkGlossariesPage(ilPageObject $a_page, array $a_terms)
Auto link glossary of whole page.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOnline(bool $a_online)
static _lookupOnline(int $a_id)
static _getAllReferences(int $id)
get all reference ids for object ID
ilTree $tree
static getScormModulesForGlossary(int $a_glo_id)
Get SCORM modules that assign a certain glossary.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
quote($value, string $type)
exportFileItems(string $a_target_dir, ilLog $expLog)
loadLanguageModule(string $a_module)
Load language module.
appendXML(string $a_str)
append xml string to document
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:30
static getAdvMDSubItemTitle(int $a_obj_id, string $a_sub_type, int $a_sub_id)
static tf2yn(bool $a_tf)
static getTermList(array $a_glo_ref_id, string $searchterm="", string $a_first_letter="", string $a_def="", int $a_tax_node=0, bool $a_add_amet_fields=false, array $a_amet_filter=null, bool $a_include_references=false)
Get all terms for given set of glossary ids.
addAutoGlossary(int $glo_id)
setActiveGlossaryMenu(bool $a_act_glo_menu)
exportXMLMediaObjects(ilXmlWriter $a_xml_writer, int $a_inst, string $a_target_dir, ilLog $expLog)
setFlashcardsMode(string $a_flash)
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
setPublicExportFile(string $a_type, string $a_file)
specify public export file for type
static _copyTerm(int $a_term_id, int $a_glossary_id)
Copy a term to a glossary.
ilGlobalTemplateInterface $tpl
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
getExportDirectory(string $a_type="xml")
static collectFileItems(ilPageObject $a_page, DOMDocument $a_domdoc)
Get all file items that are used within the page.
create(bool $a_upload=false)
__construct(int $a_id=0, bool $a_call_by_reference=true)
cloneMetaData(ilObject $target_obj)
Copy meta data.
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createImportDirectory()
creates data directory for import files (data_dir/glo_data/glo_<id>/import, depending on data directo...
getTermList(string $searchterm="", string $a_letter="", string $a_def="", int $a_tax_node=0, bool $a_include_offline_childs=false, bool $a_add_amet_fields=false, array $a_amet_filter=null, bool $a_omit_virtual=false, bool $a_include_references=false)
exportXMLMetaData(ilXmlWriter $a_xml_writer)
ilLanguage $lng
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
getPublicExportFile(string $a_type)
get public export file
ilDBInterface $db
static _getExportFiles(int $a_obj_id, $a_export_types="", string $a_obj_type="")
static _lookGlossaryTerm(int $term_id)
get glossary term
Class ilObjFile.
static _lookupObjectId(int $ref_id)
query(string $query)
Run a (read-only) Query on the database.
removeOfflineGlossaries(array $a_glo_ids, bool $ids_are_ref_ids=false)
Remove offline glossaries from obj id array.
static getDataDir()
get data directory (outside webspace)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAssignmentsOfItem(int $a_item_id)
Get assignments for item.
setActiveDownloads(bool $a_down)
exportXML(ilXmlWriter $a_xml_writer, int $a_inst, string $a_target_dir, ilLog $expLog)
static saveUsage(int $a_tax_id, int $a_obj_id)
$lm_set
createExportDirectory(string $a_type="xml")
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static lookupSnippetLength(int $a_id)
setVirtualMode(string $a_mode)
$q
Definition: shib_logout.php:21
autoLinkGlossaryTerms(int $a_glo_ref_id)
Auto link glossary terms.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
setShowTaxonomy(bool $a_val)
static yn2tf(string $a_yn)
static lookupAutoGlossaries(int $a_id)
removeGlossaryFromCollection(int $glo_id)
static _getInstance(int $a_copy_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
write(string $a_msg, $a_log_level=null)
logging
static getDeletionDependencies(int $obj_id)
getExportFiles()
Get export files.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
modifyExportIdentifier(string $a_tag, string $a_param, string $a_value)
static _lookupType(int $id, bool $reference=false)
getFirstLetters(int $a_tax_node=0)
ILIAS Style Content DomainService $content_style_domain
static getFirstLetters(array $a_glo_id, int $a_tax_node=0)
supportsLongTextQuery()
Is long text search supported.
ILIAS Glossary Term TermManager $term_manager
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static lookup(int $a_id, string $a_property)
Lookup glossary property.
exportXMLGlossaryItems(ilXmlWriter $a_xml_writer, int $a_inst, ilLog $expLog)