ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTermListTableGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected \ILIAS\Glossary\InternalGUIService $gui;
27  protected array $selected_cols;
28  protected array $adv_cols_order;
29  protected array $selectable_cols;
30  protected array $adv_fields;
31  protected int $tax_node;
34  protected array $filter;
35 
36  public function __construct(
37  object $a_parent_obj,
38  string $a_parent_cmd,
39  int $a_tax_node
40  ) {
41  global $DIC;
42 
43  $this->glossary = $a_parent_obj->getObject();
44  $this->setId("glotl" . $this->glossary->getId());
45  $this->tax_node = $a_tax_node;
46 
47  $this->lng = $DIC->language();
48  $this->ctrl = $DIC->ctrl();
49 
50  $this->selectable_cols = array();
51 
52  $this->term_perm = ilGlossaryTermPermission::getInstance();
53 
54  $adv_ad = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId());
55  $this->adv_fields = $adv_ad->getAllFields();
56  foreach ($this->adv_fields as $f) {
57  $this->selectable_cols["md_" . $f["id"]] = array(
58  "txt" => $f["title"],
59  "default" => false
60  );
61  }
62 
63  // selectable columns
64  $this->selectable_cols["language"] = array(
65  "txt" => $this->lng->txt("language"),
66  "default" => true);
67  $this->selectable_cols["usage"] = array(
68  "txt" => $this->lng->txt("cont_usage"),
69  "default" => true);
70 
71  // selectable columns of advanced metadata
72 
73  parent::__construct($a_parent_obj, $a_parent_cmd);
74  $this->setTitle($this->lng->txt("cont_terms"));
75 
76  $this->addColumn("", "", "1", true);
77  //$this->addColumn($this->lng->txt("cont_term"));
78 
79  $adv_ap = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId());
80  $this->adv_cols_order = $adv_ap->getColumnOrder();
81  $this->selected_cols = $this->getSelectedColumns();
82  foreach ($this->adv_cols_order as $c) {
83  if ($c["id"] == 0) {
84  $this->addColumn($this->lng->txt("cont_term"), "term");
85  } elseif (in_array("md_" . $c["id"], $this->selected_cols)) {
86  $this->addColumn($c["text"], "md_" . $c["id"]);
87  }
88  }
89 
90  foreach (array("language", "usage") as $c) {
91  if (in_array($c, $this->selected_cols)) {
92  $this->addColumn($this->selectable_cols[$c]["txt"]);
93  }
94  }
95 
96  $this->setDefaultOrderDirection("asc");
97  $this->setDefaultOrderField("term");
98  $this->addColumn($this->lng->txt("cont_definitions"));
99 
100  if ($this->showGlossaryColumn()) {
101  $this->addColumn($this->lng->txt("obj_glo"));
102  }
103 
104  $this->addColumn($this->lng->txt("actions"));
105 
106  $this->setEnableHeader(true);
107  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
108  $this->setRowTemplate("tpl.term_tbl_row.html", "Modules/Glossary");
109  $this->setEnableTitle(true);
110 
111  $this->addMultiCommand("copyTerms", $this->lng->txt("copy"));
112  $this->addMultiCommand("referenceTerms", $this->lng->txt("glo_reference"));
113  $this->addMultiCommand("confirmTermDeletion", $this->lng->txt("delete"));
114 
115  $this->setShowRowsSelector(true);
116 
117  $this->initFilter();
118  $this->setData($this->glossary->getTermList(
119  $this->filter["term"],
120  "",
121  $this->filter["definition"],
122  $this->tax_node,
123  true,
124  true,
125  null,
126  false,
127  true
128  ));
129  $this->gui = $DIC->glossary()
130  ->internal()
131  ->gui();
132  }
133 
134  public function showGlossaryColumn(): bool
135  {
136  return ($this->glossary->getVirtualMode() === "coll"
137  || ilGlossaryTermReferences::hasReferences($this->glossary->getId())
138  );
139  }
140 
141 
142  public function getSelectableColumns(): array
143  {
144  return $this->selectable_cols;
145  }
146 
147  public function numericOrdering(string $a_field): bool
148  {
149  if (strpos($a_field, "md_") === 0) {
150  $md_id = (int) substr($a_field, 3);
151  if ($this->adv_fields[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
152  return true;
153  }
154  }
155  return false;
156  }
157 
158  public function initFilter(): void
159  {
160  // term
161  $ti = new ilTextInputGUI($this->lng->txt("cont_term"), "term");
162  $ti->setMaxLength(64);
163  $ti->setSize(20);
164  $ti->setSubmitFormOnEnter(true);
165  $this->addFilterItem($ti);
166  $ti->readFromSession();
167  $this->filter["term"] = $ti->getValue();
168 
169  // definition
170  if ($this->glossary->supportsLongTextQuery()) {
171  $ti = new ilTextInputGUI($this->lng->txt("cont_definition"), "defintion");
172  $ti->setMaxLength(64);
173  $ti->setSize(20);
174  $ti->setSubmitFormOnEnter(true);
175  $this->addFilterItem($ti);
176  $ti->readFromSession();
177  $this->filter["definition"] = $ti->getValue();
178  }
179  }
180 
181  protected function fillRow(array $a_set): void
182  {
183  $ui_factory = $this->gui->ui()->factory();
184  $ui_renderer = $this->gui->ui()->renderer();
185 
186  $term_id = $a_set["id"];
187  $this->ctrl->setParameterByClass("ilobjglossarygui", "term_id", $term_id);
188  $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term_id);
189  $this->ctrl->setParameterByClass("ilglossarydefpagegui", "term_id", $term_id);
190 
191  // actions drop down
192  //if ($this->glossary->getId() == $term["glo_id"])
193 
194  if ($this->term_perm->checkPermission("write", $term_id) ||
195  $this->term_perm->checkPermission("edit_content", $term_id)) {
196  if (ilGlossaryTerm::_lookGlossaryID($term_id) == $this->glossary->getId() ||
197  ilGlossaryTermReferences::isReferenced([$this->glossary->getId()], $term_id)) {
198  $actions = [];
199 
200  $actions[] = $ui_factory->link()->standard(
201  $this->lng->txt("cont_edit_term"),
202  $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "editTerm")
203  );
204  $this->ctrl->setParameterByClass("ilglossarydefpagegui", "term_id", $term_id);
205  $actions[] = $ui_factory->link()->standard(
206  $this->lng->txt("cont_edit_definition"),
207  $this->ctrl->getLinkTargetByClass(array("ilglossarytermgui",
208  "iltermdefinitioneditorgui",
209  "ilglossarydefpagegui"), "edit")
210  );
211  $this->ctrl->setParameterByClass("ilglossarydefpagegui", "term_id", "");
212 
213  $dd = $ui_factory->dropdown()->standard($actions);
214 
215  $this->tpl->setVariable("ACTIONS", $ui_renderer->render($dd));
216  }
217  }
218 
219  // text
220  $this->tpl->setCurrentBlock("definition");
221  $short_str = ilGlossaryTerm::_lookShortText($term_id);
222 
223  try {
224  if (ilGlossaryTerm::_lookShortTextDirty($term_id)) {
225  // #18022
226  $term_obj = new ilGlossaryTerm($term_id);
227  $term_obj->updateShortText();
228  $short_str = $term_obj->getShortText();
229  }
230 
231  $page = new ilGlossaryDefPage($term_id);
232 
233  // replace tex
234  // if a tex end tag is missing a tex end tag
235  $ltexs = strrpos($short_str, "[tex]");
236  $ltexe = strrpos($short_str, "[/tex]");
237  if ($ltexs > $ltexe) {
238  $page->buildDom();
239  $short_str = $page->getFirstParagraphText();
240  $short_str = strip_tags($short_str, "<br>");
241  $ltexe = strpos($short_str, "[/tex]", $ltexs);
242  $short_str = ilStr::shortenTextExtended($short_str, $ltexe + 6, true);
243  }
244 
245  $short_str = ilMathJax::getInstance()->insertLatexImages($short_str);
246 
247  $short_str = ilPCParagraph::xml2output(
248  $short_str,
249  false,
250  true,
251  !$page->getPageConfig()->getPreventHTMLUnmasking()
252  );
253 
254  $this->tpl->setVariable("DEF_SHORT", $short_str);
255  $this->tpl->parseCurrentBlock();
256  } catch (Exception $e) {
257  $this->tpl->setVariable("DEF_SHORT", "Error: Page is missing.");
258  $this->tpl->parseCurrentBlock();
259  }
260 
261  $this->tpl->setCurrentBlock("definition_row");
262  $this->tpl->parseCurrentBlock();
263 
264  $this->tpl->setCurrentBlock("check_col");
265  $this->tpl->setVariable("CHECKBOX_ID", $term_id);
266  $this->tpl->parseCurrentBlock();
267 
268  $this->ctrl->setParameter($this->parent_obj, "term_id", $term_id);
269 
270 
271  // usage
272  if (in_array("usage", $this->getSelectedColumns())) {
273  $nr_usage = ilGlossaryTerm::getNumberOfUsages($term_id);
274  if ($nr_usage > 0 && $this->glossary->getId() == $a_set["glo_id"]) {
275  $this->tpl->setCurrentBlock("link_usage");
276  $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term_id);
277  $this->tpl->setVariable("LUSAGE", ilGlossaryTerm::getNumberOfUsages($term_id));
278  $this->tpl->setVariable(
279  "LINK_USAGE",
280  $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "listUsages")
281  );
282  $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", "");
283  } else {
284  $this->tpl->setCurrentBlock("usage");
285  $this->tpl->setVariable("USAGE", ilGlossaryTerm::getNumberOfUsages($term_id));
286  }
287  $this->tpl->parseCurrentBlock();
288  $this->tpl->setCurrentBlock("td_usage");
289  $this->tpl->parseCurrentBlock();
290  }
291 
292  // glossary title
293  if ($this->showGlossaryColumn()) {
294  $this->tpl->setCurrentBlock("glossary");
295  $this->tpl->setVariable("GLO_TITLE", ilObject::_lookupTitle($a_set["glo_id"]));
296  $this->tpl->parseCurrentBlock();
297  }
298 
299  // output language
300  if (in_array("language", $this->getSelectedColumns())) {
301  $this->tpl->setCurrentBlock("td_lang");
302  $this->tpl->setVariable("TEXT_LANGUAGE", $this->lng->txt("meta_l_" . $a_set["language"]));
303  $this->tpl->parseCurrentBlock();
304  }
305 
306 
307  foreach ($this->adv_cols_order as $c) {
308  if ($c["id"] == 0) {
309  $this->tpl->setCurrentBlock("td");
310  $this->tpl->setVariable("TD_VAL", $a_set["term"]);
311  $this->tpl->parseCurrentBlock();
312  } elseif (in_array("md_" . $c["id"], $this->selected_cols)) {
313  $id = (int) $c["id"];
314 
315  $val = " ";
316  if (isset($a_set["md_" . $id . "_presentation"])) {
317  $pb = $a_set["md_" . $id . "_presentation"]->getHTML();
318  if ($pb) {
319  $val = $pb;
320  }
321  }
322 
323  $this->tpl->setCurrentBlock("td");
324  $this->tpl->setVariable("TD_VAL", $val);
325  $this->tpl->parseCurrentBlock();
326  }
327  }
328  }
329 }
setData(array $a_data)
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setEnableTitle(bool $a_enabletitle)
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...
static xml2output(string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
Converts xml from DB to output in edit textarea.
setId(string $a_val)
static _lookShortTextDirty(int $term_id)
get definition short text dirty
static hasReferences(int $a_glossary_id)
Check if a glossary uses references.
static isReferenced(array $a_glo_id, int $a_term_id)
Is a term referenced by a set of glossaries.
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
static _lookShortText(int $term_id)
get definition short text
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAllFields()
Get all advanced metadata fields.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_tax_node)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
ILIAS Glossary InternalGUIService $gui
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
static getNumberOfUsages(int $a_term_id)
addMultiCommand(string $a_cmd, string $a_text)
ilGlossaryTermPermission $term_perm
setEnableHeader(bool $a_enableheader)
numericOrdering(string $a_field)
static _lookGlossaryID(int $term_id)
get glossary id form term id