ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryForeignTermCollectorGUI.php
Go to the documentation of this file.
1<?php
2
24{
26 protected \ILIAS\Glossary\Editing\EditingGUIRequest $request;
27 protected \ILIAS\Glossary\Term\TermManager $term_manager;
28 protected \ILIAS\components\ILIAS\Glossary\Table\TableManager $table_manager;
31 protected int $fglo_ref_id;
32 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
35 protected ilObjUser $user;
36 protected \ILIAS\UI\Renderer $ui_ren;
38
43
44 protected function __construct(
45 ilObjGlossaryGUI $a_glossary_gui
46 ) {
47 global $DIC;
48
49 $this->tpl = $DIC["tpl"];
50 $this->ctrl = $DIC->ctrl();
51 $this->lng = $DIC->language();
52 $this->user = $DIC->user();
53 $this->ui_ren = $DIC->ui()->renderer();
54
55 $this->glossary_gui = $a_glossary_gui;
57 $glossary = $a_glossary_gui->getObject();
58 $this->glossary = $glossary;
59
60 $this->term_manager = $DIC->glossary()
61 ->internal()
62 ->domain()
63 ->term(
64 $this->glossary,
65 $this->user->getId()
66 );
67 $this->table_manager = $DIC->glossary()
68 ->internal()
69 ->domain()
70 ->table();
71 $this->request = $DIC->glossary()
72 ->internal()
73 ->gui()
74 ->editing()
75 ->request();
76 $this->requested_table_glossary_foreign_term_action = $this->request->getTableGlossaryForeignTermAction();
77 $this->requested_table_glossary_foreign_term_ids = $this->request->getTableGlossaryForeignTermIds();
78
79 $this->fglo_ref_id = $this->request->getForeignGlossaryRefId();
80 if ($this->fglo_ref_id > 0 && ilObject::_lookupType($this->fglo_ref_id, true) == "glo") {
81 $this->foreign_glossary = new ilObjGlossary($this->fglo_ref_id, true);
82 }
83
84 $this->ctrl->saveParameter($this, "fglo_ref_id");
85 }
86
87 public static function getInstance(ilObjGlossaryGUI $a_glossary_gui): self
88 {
89 return new self($a_glossary_gui);
90 }
91
92 public function executeCommand(): void
93 {
94 $next_class = $this->ctrl->getNextClass($this);
95 $cmd = $this->ctrl->getCmd("showGlossarySelector");
96
97 switch ($next_class) {
98 default:
99 if (in_array($cmd, array("showGlossarySelector", "setForeignGlossary", "showTerms", "copyTerms", "referenceTerms"))) {
100 $this->$cmd();
101 }
102 }
103 }
104
105 public function showGlossarySelector(): void
106 {
107 $this->tpl->setOnScreenMessage('info', $this->lng->txt("glo_select_source_glo"));
109 $this,
110 "showGlossarySelector",
111 $this,
112 "setForeignGlossary",
113 "fglo_ref_id"
114 );
115 $exp->setTypeWhiteList(array("root", "cat", "grp", "crs", "glo", "fold"));
116 $exp->setClickableTypes(array("glo"));
117 if (!$exp->handleCommand()) {
118 $this->tpl->setContent($exp->getHTML());
119 }
120 }
121
122 public function setForeignGlossary(): void
123 {
124 $ilCtrl = $this->ctrl;
126
127 $ref_id = $this->request->getForeignGlossaryRefId();
128
129 if ($ref_id == $this->glossary->getRefId()) {
130 $this->tpl->setOnScreenMessage('failure', $lng->txt("glo_please_select_other_glo"), true);
131 $ilCtrl->redirect($this, "showGlossarySelector");
132 }
133
134 $ilCtrl->redirect($this, "showTerms");
135 }
136
137 public function showTerms(): void
138 {
139 $table = $this->table_manager->getGlossaryForeignTermTable(
140 $this->glossary,
141 $this->foreign_glossary
142 )->getComponent();
143
144 $this->tpl->setContent($this->ui_ren->render($table));
145 }
146
147 public function copyTerms(): void
148 {
149 if ($this->requested_table_glossary_foreign_term_action === "copyTerms"
150 && !empty($this->requested_table_glossary_foreign_term_ids)
151 && $this->requested_table_glossary_foreign_term_ids[0] === "ALL_OBJECTS"
152 ) {
153 foreach ($this->foreign_glossary->getTermList() as $term) {
154 $this->term_manager->copyTermFromOtherGlossary(
155 $this->foreign_glossary->getRefId(),
156 (int) $term["id"]
157 );
158 }
159 } elseif ($this->requested_table_glossary_foreign_term_action === "copyTerms") {
160 foreach ($this->requested_table_glossary_foreign_term_ids as $term_id) {
161 $this->term_manager->copyTermFromOtherGlossary(
162 $this->foreign_glossary->getRefId(),
163 (int) $term_id
164 );
165 }
166 }
167 if (empty($this->requested_table_glossary_foreign_term_ids)) {
168 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
169 $this->ctrl->redirect($this, "showTerms");
170 }
171
172 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
173 $this->ctrl->returnToParent($this);
174 }
175
176 public function referenceTerms(): void
177 {
178 $term_ids = [];
179 if ($this->requested_table_glossary_foreign_term_action === "referenceTerms"
180 && !empty($this->requested_table_glossary_foreign_term_ids)
181 && $this->requested_table_glossary_foreign_term_ids[0] === "ALL_OBJECTS"
182 ) {
183 foreach ($this->foreign_glossary->getTermList() as $term) {
184 $term_ids[] = (int) $term["id"];
185 }
186 } elseif ($this->requested_table_glossary_foreign_term_action === "referenceTerms") {
187 $term_ids = array_map("intval", $this->requested_table_glossary_foreign_term_ids);
188 }
189 if (empty($term_ids)) {
190 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"), true);
191 $this->ctrl->redirect($this, "showTerms");
192 }
193
194 $this->term_manager->referenceTermsFromOtherGlossary(
195 $this->foreign_glossary->getRefId(),
196 $term_ids
197 );
198
199 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
200 $this->ctrl->returnToParent($this);
201 }
202}
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Glossary Editing EditingGUIRequest $request
static getInstance(ilObjGlossaryGUI $a_glossary_gui)
ILIAS components ILIAS Glossary Table TableManager $table_manager
language handling
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...
GUI class for ilGlossary.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupType(int $id, bool $reference=false)
Explorer for selecting repository items.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26