ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryTermGUI.php
Go to the documentation of this file.
1<?php
2
26{
28 protected int $ref_id;
29 protected \ILIAS\Glossary\Editing\EditingGUIRequest $request;
30 protected string $offline_directory;
31 protected ilCtrl $ctrl;
33 protected ilHelpGUI $help;
34 protected \ILIAS\COPage\PageLinker $page_linker;
39 protected ilLogger $log;
40 protected ?ilObjGlossary $term_glossary = null;
42 protected \ILIAS\Style\Content\GUIService $content_style_gui;
43 protected \ILIAS\Style\Content\DomainService $content_style_domain;
44 protected \ILIAS\Glossary\InternalDomainService $domain;
45 protected \ILIAS\UI\Renderer $ui_ren;
46
47 public function __construct(
48 int $a_id = 0
49 ) {
50 global $DIC;
51
52 $this->help = $DIC["ilHelp"];
53 $lng = $DIC->language();
54 $tpl = $DIC["tpl"];
55 $ilCtrl = $DIC->ctrl();
56 $ilTabs = $DIC->tabs();
57
58 $this->lng = $lng;
59 $this->tpl = $tpl;
60 $this->ctrl = $ilCtrl;
61 $this->ctrl->saveParameter($this, array("term_id"));
62 $this->tabs_gui = $ilTabs;
63 $this->request = $DIC->glossary()
64 ->internal()
65 ->gui()
66 ->editing()
67 ->request();
68 $this->domain = $DIC->glossary()->internal()->domain();
69 $this->ui_ren = $DIC->ui()->renderer();
70
71 $this->log = ilLoggerFactory::getLogger('glo');
72
73 $this->toolbar = $DIC->toolbar();
74
75 $this->ref_id = $this->request->getRefId();
76
77 if ($a_id != 0) {
78 $this->term = new ilGlossaryTerm($a_id);
80 $this->term_glossary = new ilObjGlossary($this->ref_id, true);
81 } else {
82 $this->term_glossary = new ilObjGlossary(ilGlossaryTerm::_lookGlossaryID($a_id), false);
83 }
84 }
85 $cs = $DIC->contentStyle();
86 $this->content_style_gui = $cs->gui();
87 $this->content_style_domain = $cs->domain();
88 }
89
90 public function executeCommand(): void
91 {
92 $ilTabs = $this->tabs_gui;
93
94 $next_class = $this->ctrl->getNextClass($this);
95 $cmd = $this->ctrl->getCmd();
96
97 $this->log->debug("glossary term, next class " . $next_class . ", cmd: " . $cmd);
98
99 switch ($next_class) {
100 case "iltermdefinitioneditorgui":
101 $def_edit = new ilTermDefinitionEditorGUI();
102 $this->ctrl->forwardCommand($def_edit);
103 break;
104
105 case "ilpropertyformgui":
106 $form = $this->getEditTermForm();
107 $this->ctrl->forwardCommand($form);
108 break;
109
110 case "ilobjectmetadatagui":
111 $this->setTabs();
112 $ilTabs->activateTab('meta_data');
113 $md_gui = new ilObjectMetaDataGUI(
114 $this->term_glossary,
115 'term',
116 $this->term->getId()
117 );
118 $this->ctrl->forwardCommand($md_gui);
119 break;
120
121 default:
122 $ret = $this->$cmd();
123 break;
124 }
125 }
126
127 public function setOfflineDirectory(string $offdir): void
128 {
129 $this->offline_directory = $offdir;
130 }
131
132 public function getOfflineDirectory(): string
133 {
135 }
136
137
138 public function setGlossary(ilObjGlossary $a_glossary): void
139 {
140 $this->glossary = $a_glossary;
141 if (!is_object($this->term_glossary)) {
142 $this->term_glossary = $a_glossary;
143 }
144 }
145
146 public function setPageLinker(\ILIAS\COPage\PageLinker $page_linker): void
147 {
148 $this->page_linker = $page_linker;
149 }
150
151 public function editTerm(
152 ?ilPropertyFormGUI $a_form = null
153 ): void {
154 $ilTabs = $this->tabs_gui;
155 $ilCtrl = $this->ctrl;
156
157 // $this->getTemplate();
158 $this->displayLocator();
159 $this->setTabs();
160 $ilTabs->activateTab("properties");
161
162 $this->tpl->setTitle($this->lng->txt("cont_term") . ": " . $this->term->getTerm());
163 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_glo.svg"));
164
165 if (!$a_form) {
166 $a_form = $this->getEditTermForm();
167 }
168
169 $this->tpl->setContent($ilCtrl->getHTML($a_form));
170 }
171
173 {
174 $form = new ilPropertyFormGUI();
175 $form->setFormAction($this->ctrl->getFormAction($this, "updateTerm"));
176 $form->setTitle($this->lng->txt("cont_edit_term"));
177
178 $term = new ilTextInputGUI($this->lng->txt("cont_term"), "term");
179 $term->setRequired(true);
180 $term->setValue($this->term->getTerm());
181 $form->addItem($term);
182
183 $lang = new ilSelectInputGUI($this->lng->txt("language"), "term_language");
184 $lang->setRequired(true);
185 $lang->setOptions($this->domain->metadata()->getLOMLanguagesForSelectInputs());
186 $lang->setValue($this->term->getLanguage());
187 $form->addItem($lang);
188
189 // taxonomy
190 if ($this->term_glossary->getTaxonomyId() > 0) {
191 $tax_node_assign = new ilTaxSelectInputGUI($this->term_glossary->getTaxonomyId(), "tax_node", true);
192
193 $ta = new ilTaxNodeAssignment("glo", $this->term_glossary->getId(), "term", $this->term_glossary->getTaxonomyId());
194 $assgnmts = $ta->getAssignmentsOfItem($this->term->getId());
195 $node_ids = array();
196 foreach ($assgnmts as $a) {
197 $node_ids[] = $a["node_id"];
198 }
199 $tax_node_assign->setValue($node_ids);
200
201 $form->addItem($tax_node_assign);
202 }
203
204 // advanced metadata
205 $this->record_gui = new ilAdvancedMDRecordGUI(
207 'glo',
208 $this->term_glossary->getId(),
209 'term',
210 $this->term->getId()
211 );
212 $this->record_gui->setPropertyForm($form);
213 $this->record_gui->parse();
214
215 $form->addCommandButton("updateTerm", $this->lng->txt("save"));
216
217 return $form;
218 }
219
220 public function updateTerm(): void
221 {
222 $form = $this->getEditTermForm();
223 if ($form->checkInput() &&
224 $this->record_gui->importEditFormPostValues()) {
225 // update term
226 $this->term->setTerm($form->getInput("term"));
227 $this->term->setLanguage($form->getInput("term_language"));
228 $this->term->update();
229
230 // update taxonomy assignment
231 if ($this->term_glossary->getTaxonomyId() > 0) {
232 $ta = new ilTaxNodeAssignment("glo", $this->term_glossary->getId(), "term", $this->term_glossary->getTaxonomyId());
233 $ta->deleteAssignmentsOfItem($this->term->getId());
234 foreach ($this->request->getTaxNodes() as $node_id) {
235 $ta->addAssignment($node_id, $this->term->getId());
236 }
237 }
238
239 $this->record_gui->writeEditForm();
240 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
241 $this->ctrl->redirect($this, "editTerm");
242 }
243
244 $form->setValuesByPost();
245 $this->editTerm($form);
246 }
247
248 public function getOverlayHTML(
249 string $a_close_el_id,
250 string $a_glo_ov_id = "",
251 string $a_lang = "",
252 string $a_outputmode = "offline"
253 ): string {
254 $lng = $this->lng;
255
256 if ($a_lang == "") {
257 $a_lang = $lng->getLangKey();
258 }
259
260 $tpl = new ilTemplate("tpl.glossary_overlay.html", true, true, "components/ILIAS/Glossary");
261 // $this->output(true, $tpl);
262 if ($a_outputmode == "preview") {
263 $a_outputmode = "presentation";
264 }
265 if ($a_outputmode == "offline") {
266 $this->output(true, $tpl, $a_outputmode);
267 } else {
268 $this->output(false, $tpl, $a_outputmode);
269 }
270 if ($a_glo_ov_id != "") {
271 $tpl->setCurrentBlock("glovlink");
272 $tpl->setVariable("TXT_LINK", $lng->txtlng("content", "cont_sco_glossary", $a_lang));
273 $tpl->setVariable("ID_LINK", $a_glo_ov_id);
274 $tpl->parseCurrentBlock();
275 }
276 $tpl->setVariable("TXT_CLOSE", $lng->txtlng("common", "close", $a_lang));
277 $tpl->setVariable("ID_CLOSE", $a_close_el_id);
278 return $tpl->get();
279 }
280
285 public function output(
286 bool $a_offline = false,
287 ?ilGlobalTemplateInterface $a_tpl = null,
288 string $a_outputmode = "presentation"
289 ): void {
290 if ($a_tpl != null) {
291 $tpl = $a_tpl;
292 } else {
293 $tpl = $this->tpl;
294 }
295
296 $tpl->setVariable("TXT_TERM", $this->term->getTerm());
297
298 $page_gui = new ilGlossaryDefPageGUI($this->term->getId());
299 $page_gui->setTemplate($tpl);
300 $page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=" . $this->ref_id);
301 if ($a_offline) {
302 $page_gui->setFullscreenLink("fullscreen.html"); // id is set by xslt
303 }
304 $page_gui->setFileDownloadLink("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;cmd=downloadFile&amp;ref_id=" . $this->ref_id);
305
306 if (!$a_offline) {
307 $page_gui->setOutputMode($a_outputmode);
308 } else {
309 $page_gui->setOutputMode("offline");
310 $page_gui->setOfflineDirectory($this->getOfflineDirectory());
311 }
312
313 //$page_gui->setOutputMode("edit");
314 //$page_gui->setPresentationTitle($this->term->getTerm());
315 $page_gui->setPageLinker($this->page_linker);
316 $page_gui->setTemplateOutput(false);
317 $output = $page_gui->presentation($page_gui->getOutputMode());
318
319 $tpl->setCurrentBlock("definition");
320 $tpl->setVariable("PAGE_CONTENT", $output);
321 $tpl->parseCurrentBlock();
322 }
323
324 public function getInternalLinks(): array
325 {
326 $term_links = array();
327 $page = new ilGlossaryDefPage($this->term->getId());
328 $page->buildDom();
329 $page_links = $page->getInternalLinks();
330 foreach ($page_links as $key => $page_link) {
331 $term_links[$key] = $page_link;
332 }
333
334 return $term_links;
335 }
336
337 public function setTabs(): void
338 {
339 $this->getTabs();
340 }
341
342 public function displayLocator(): void
343 {
344 $gloss_loc = new ilGlossaryLocatorGUI();
345 $gloss_loc->setGlossary($this->glossary);
346 $gloss_loc->display();
347 }
348
349 public function getTabs(): void
350 {
352 $ilHelp = $this->help;
353
354 $ilHelp->setScreenIdComponent("glo_term");
355
356 $term_id = 0;
357 if (!empty($this->request->getTableGlossaryTermListIds())
358 && $this->request->getTableGlossaryTermListIds()[0] > 0) {
359 $term_id = $this->request->getTableGlossaryTermListIds()[0];
360 } elseif ($this->request->getTermId() > 0) {
361 $term_id = $this->request->getTermId();
362 }
363 if ($term_id > 0) {
364 $this->tabs_gui->addTab(
365 "properties",
366 $lng->txt("term"),
367 $this->ctrl->getLinkTarget($this, "editTerm")
368 );
369
370 $this->tabs_gui->addTab(
371 "usage",
372 $lng->txt("cont_usage") . " (" . ilGlossaryTerm::getNumberOfUsages($term_id) . ")",
373 $this->ctrl->getLinkTarget($this, "listUsages")
374 );
375
376 $mdgui = new ilObjectMetaDataGUI(
377 $this->term_glossary,
378 "term",
379 $this->term->getId()
380 );
381 $mdtab = $mdgui->getTab();
382 if ($mdtab) {
383 $this->tabs_gui->addTab(
384 "meta_data",
385 $lng->txt("meta_data"),
386 $mdtab
387 );
388 }
389
390 $this->tabs_gui->addNonTabbedLink(
391 "presentation_view",
392 $this->lng->txt("glo_presentation_view"),
393 ILIAS_HTTP_PATH .
394 "/goto.php?target=" .
395 "git" .
396 "_" . $term_id . "_" . $this->request->getRefId() . "&client_id=" . CLIENT_ID
397 );
398 }
399
400 // back to glossary
401 $this->tabs_gui->setBackTarget(
402 $this->lng->txt("glossary"),
403 $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "listTerms")
404 );
405 }
406
407 public static function _goto(
408 string $a_target,
409 int $a_ref_id = 0
410 ): void {
411 global $DIC;
412 $main_tpl = $DIC->ui()->mainTemplate();
413
414 $ctrl = $DIC->ctrl();
415 $lng = $DIC->language();
416 $ilAccess = $DIC->access();
417
418 $glo_id = ilGlossaryTerm::_lookGlossaryID($a_target);//::_lookupContObjID($a_target);
419
420 // get all references
421 if ($a_ref_id > 0) {
422 $ref_ids = array($a_ref_id);
423 } else {
424 $ref_ids = ilObject::_getAllReferences($glo_id);
425 }
426
427 // check read permissions
428 foreach ($ref_ids as $ref_id) {
429 // Permission check
430 if ($ilAccess->checkAccess("read", "", $ref_id)) {
431 $ctrl->setParameterByClass("ilGlossaryPresentationGUI", "term_id", $a_target);
432 $ctrl->setParameterByClass("ilGlossaryPresentationGUI", "ref_id", $ref_id);
433 $ctrl->redirectByClass("ilGlossaryPresentationGUI", "listDefinitions");
434 }
435 }
436 if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
437 $main_tpl->setOnScreenMessage('failure', sprintf(
438 $lng->txt("msg_no_perm_read_item"),
440 ), true);
442 }
443
444 throw new ilPermissionException($lng->txt("msg_no_perm_read_lm"));
445 }
446
447 public function listUsages(): void
448 {
449 $ilTabs = $this->tabs_gui;
450 $tpl = $this->tpl;
451
452 //$this->displayLocator();
453 // $this->getTemplate();
454 $this->displayLocator();
455 $this->setTabs();
456 $ilTabs->activateTab("usage");
457
458 $this->tpl->setTitle($this->lng->txt("cont_term") . ": " . $this->term->getTerm());
459 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_glo.svg"));
460
461 $table = $this->domain->table()->getTermUsagesTable($this->request->getTermId())->getComponent();
462
463 $tpl->setContent($this->ui_ren->render($table));
464 }
465}
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS UI Renderer $ui_ren
ILIAS Style Content DomainService $content_style_domain
ilGlobalTemplateInterface $tpl
output(bool $a_offline=false, ?ilGlobalTemplateInterface $a_tpl=null, string $a_outputmode="presentation")
output glossary term definitions used in ilLMPresentationGUI->ilGlossary()
editTerm(?ilPropertyFormGUI $a_form=null)
static _goto(string $a_target, int $a_ref_id=0)
setOfflineDirectory(string $offdir)
ILIAS Style Content GUIService $content_style_gui
setGlossary(ilObjGlossary $a_glossary)
ILIAS COPage PageLinker $page_linker
ilAdvancedMDRecordGUI $record_gui
ILIAS Glossary InternalDomainService $domain
getOverlayHTML(string $a_close_el_id, string $a_glo_ov_id="", string $a_lang="", string $a_outputmode="offline")
setPageLinker(\ILIAS\COPage\PageLinker $page_linker)
ILIAS Glossary Editing EditingGUIRequest $request
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNumberOfUsages(int $a_term_id)
static _lookGlossaryID(int $term_id)
get glossary id form term id
Help GUI class.
language handling
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
Class ilObjectMetaDataGUI.
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
This class represents a selection list property in a property form.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const CLIENT_ID
Definition: constants.php:41
const ROOT_FOLDER_ID
Definition: constants.php:32
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
setContent(string $a_html)
Sets content for standard template.
$ref_id
Definition: ltiauth.php:66
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25