ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTermListTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $glossary;
16
20 protected $term_perm;
21
25 protected $lng;
26
30 protected $ctrl;
31
35 public function __construct($a_parent_obj, $a_parent_cmd, $a_tax_node)
36 {
37 global $DIC;
38
39 $this->glossary = $a_parent_obj->object;
40 $this->setId("glotl" . $this->glossary->getId());
41 $this->tax_node = $a_tax_node;
42
43 $this->lng = $DIC->language();
44 $this->ctrl = $DIC->ctrl();
45
46 $this->selectable_cols = array();
47
48 $this->term_perm = ilGlossaryTermPermission::getInstance();
49
50 $adv_ad = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId());
51 $this->adv_fields = $adv_ad->getAllFields();
52 foreach ($this->adv_fields as $f) {
53 $this->selectable_cols["md_" . $f["id"]] = array(
54 "txt" => $f["title"],
55 "default" => false
56 );
57 }
58
59 // selectable columns
60 $this->selectable_cols["language"] = array(
61 "txt" => $this->lng->txt("language"),
62 "default" => true);
63 $this->selectable_cols["usage"] = array(
64 "txt" => $this->lng->txt("cont_usage"),
65 "default" => true);
66
67 // selectable columns of advanced metadata
68
69 parent::__construct($a_parent_obj, $a_parent_cmd);
70 $this->setTitle($this->lng->txt("cont_terms"));
71
72 $this->addColumn("", "", "1", true);
73 //$this->addColumn($this->lng->txt("cont_term"));
74
75 $adv_ap = new ilGlossaryAdvMetaDataAdapter($this->glossary->getRefId());
76 $this->adv_cols_order = $adv_ap->getColumnOrder();
77 $this->selected_cols = $this->getSelectedColumns();
78 foreach ($this->adv_cols_order as $c) {
79 if ($c["id"] == 0) {
80 $this->addColumn($this->lng->txt("cont_term"), "term");
81 } else {
82 if (in_array("md_" . $c["id"], $this->selected_cols)) {
83 $this->addColumn($c["text"], "md_" . $c["id"]);
84 }
85 }
86 }
87
88 foreach (array("language", "usage") as $c) {
89 if (in_array($c, $this->selected_cols)) {
90 $this->addColumn($this->selectable_cols[$c]["txt"]);
91 }
92 }
93
94 $this->setDefaultOrderDirection("asc");
95 $this->setDefaultOrderField("term");
96 $this->addColumn($this->lng->txt("cont_definitions"));
97
98 if ($this->showGlossaryColumn()) {
99 $this->addColumn($this->lng->txt("obj_glo"));
100 }
101
102 $this->addColumn("", "", "1");
103
104 $this->setEnableHeader(true);
105 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
106 $this->setRowTemplate("tpl.term_tbl_row.html", "Modules/Glossary");
107 $this->setEnableTitle(true);
108
109 $this->addMultiCommand("copyTerms", $this->lng->txt("copy"));
110 $this->addMultiCommand("referenceTerms", $this->lng->txt("glo_reference"));
111 $this->addMultiCommand("confirmTermDeletion", $this->lng->txt("delete"));
112 //$this->addMultiCommand("addDefinition", $this->lng->txt("cont_add_definition"));
113
114 $this->setShowRowsSelector(true);
115
116 $this->initFilter();
117 $this->setData($this->glossary->getTermList(
118 $this->filter["term"],
119 "",
120 $this->filter["definition"],
121 $this->tax_node,
122 true,
123 true,
124 null,
125 false,
126 true
127 ));
128 }
129
136 public function showGlossaryColumn()
137 {
138 return (in_array(
139 $this->glossary->getVirtualMode(),
140 array("level", "subtree")
141 ) || ilGlossaryTermReferences::hasReferences($this->glossary->getId()));
142 }
143
144
151 public function getSelectableColumns()
152 {
153 return $this->selectable_cols;
154 }
155
161 public function numericOrdering($a_field)
162 {
163 if (substr($a_field, 0, 3) == "md_") {
164 $md_id = (int) substr($a_field, 3);
165 if ($this->adv_fields[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
166 return true;
167 }
168 }
169 return false;
170 }
171
175 public function initFilter()
176 {
177 // term
178 $ti = new ilTextInputGUI($this->lng->txt("cont_term"), "term");
179 $ti->setMaxLength(64);
180 $ti->setSize(20);
181 $ti->setSubmitFormOnEnter(true);
182 $this->addFilterItem($ti);
183 $ti->readFromSession();
184 $this->filter["term"] = $ti->getValue();
185
186 // definition
187 if ($this->glossary->supportsLongTextQuery()) {
188 $ti = new ilTextInputGUI($this->lng->txt("cont_definition"), "defintion");
189 $ti->setMaxLength(64);
190 $ti->setSize(20);
191 $ti->setSubmitFormOnEnter(true);
192 $this->addFilterItem($ti);
193 $ti->readFromSession();
194 $this->filter["definition"] = $ti->getValue();
195 }
196 }
197
201 protected function fillRow($term)
202 {
203 $defs = ilGlossaryDefinition::getDefinitionList($term["id"]);
204 $this->ctrl->setParameterByClass("ilobjglossarygui", "term_id", $term["id"]);
205 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term["id"]);
206 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "term_id", $term["id"]);
207
208 // actions drop down
209 //if ($this->glossary->getId() == $term["glo_id"])
210
211 if ($this->term_perm->checkPermission("write", $term["id"]) ||
212 $this->term_perm->checkPermission("edit_content", $term["id"])) {
213 if (ilGlossaryTerm::_lookGlossaryID($term["id"]) == $this->glossary->getId() ||
214 ilGlossaryTermReferences::isReferenced($this->glossary->getId(), $term["id"])) {
215 $list = new ilAdvancedSelectionListGUI();
216 $list->addItem($this->lng->txt("cont_edit_term"), "", $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "editTerm"));
217 if (count($defs) > 1) {
218 $list->addItem($this->lng->txt("cont_edit_definitions"), "", $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "listDefinitions"));
219 } elseif (count($defs) == 1) {
220 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "def", $defs[0]["id"]);
221 $list->addItem($this->lng->txt("cont_edit_definition"), "", $this->ctrl->getLinkTargetByClass(array("ilglossarytermgui",
222 "iltermdefinitioneditorgui",
223 "ilglossarydefpagegui"), "edit"));
224 }
225 $list->addItem($this->lng->txt("cont_add_definition"), "", $this->ctrl->getLinkTargetByClass("ilobjglossarygui", "addDefinition"));
226 $this->ctrl->setParameterByClass("ilglossarydefpagegui", "def", "");
227
228 $list->setId("act_term_" . $term["id"]);
229 $list->setListTitle($this->lng->txt("actions"));
230 $this->tpl->setVariable("ACTIONS", $list->getHTML());
231 }
232 }
233
234
235 for ($j = 0; $j < count($defs); $j++) {
236 $def = $defs[$j];
237
238
239 // text
240 $this->tpl->setCurrentBlock("definition");
241 $short_str = $def["short_text"];
242
243 if ($def["short_text_dirty"]) {
244 // #18022
245 $def_obj = new ilGlossaryDefinition($def["id"]);
246 $def_obj->updateShortText();
247 $short_str = $def_obj->getShortText();
248 }
249
250 // replace tex
251 // if a tex end tag is missing a tex end tag
252 $ltexs = strrpos($short_str, "[tex]");
253 $ltexe = strrpos($short_str, "[/tex]");
254 if ($ltexs > $ltexe) {
255 $page = new ilGlossaryDefPage($def["id"]);
256 $page->buildDom();
257 $short_str = $page->getFirstParagraphText();
258 $short_str = strip_tags($short_str, "<br>");
259 $ltexe = strpos($short_str, "[/tex]", $ltexs);
260 $short_str = ilUtil::shortenText($short_str, $ltexe + 6, true);
261 }
262
263 $short_str = ilMathJax::getInstance()->insertLatexImages($short_str);
264
265 $short_str = ilPCParagraph::xml2output($short_str);
266 $this->tpl->setVariable("DEF_SHORT", $short_str);
267 $this->tpl->parseCurrentBlock();
268
269 $this->tpl->setCurrentBlock("definition_row");
270 $this->tpl->parseCurrentBlock();
271 }
272
273 $this->tpl->setCurrentBlock("check_col");
274 $this->tpl->setVariable("CHECKBOX_ID", $term["id"]);
275 $this->tpl->parseCurrentBlock();
276
277 $this->ctrl->setParameter($this->parent_obj, "term_id", $term["id"]);
278
279
280 // usage
281 if (in_array("usage", $this->getSelectedColumns())) {
282 $nr_usage = ilGlossaryTerm::getNumberOfUsages($term["id"]);
283 if ($nr_usage > 0 && $this->glossary->getId() == $term["glo_id"]) {
284 $this->tpl->setCurrentBlock("link_usage");
285 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", $term["id"]);
286 $this->tpl->setVariable("LUSAGE", ilGlossaryTerm::getNumberOfUsages($term["id"]));
287 $this->tpl->setVariable(
288 "LINK_USAGE",
289 $this->ctrl->getLinkTargetByClass("ilglossarytermgui", "listUsages")
290 );
291 $this->ctrl->setParameterByClass("ilglossarytermgui", "term_id", "");
292 $this->tpl->parseCurrentBlock();
293 } else {
294 $this->tpl->setCurrentBlock("usage");
295 $this->tpl->setVariable("USAGE", ilGlossaryTerm::getNumberOfUsages($term["id"]));
296 $this->tpl->parseCurrentBlock();
297 }
298 $this->tpl->setCurrentBlock("td_usage");
299 $this->tpl->parseCurrentBlock();
300 }
301
302 // glossary title
303 if ($this->showGlossaryColumn()) {
304 $this->tpl->setCurrentBlock("glossary");
305 $this->tpl->setVariable("GLO_TITLE", ilObject::_lookupTitle($term["glo_id"]));
306 $this->tpl->parseCurrentBlock();
307 }
308
309 // output language
310 if (in_array("language", $this->getSelectedColumns())) {
311 $this->tpl->setCurrentBlock("td_lang");
312 $this->tpl->setVariable("TEXT_LANGUAGE", $this->lng->txt("meta_l_" . $term["language"]));
313 $this->tpl->parseCurrentBlock();
314 }
315
316
317 foreach ($this->adv_cols_order as $c) {
318 if ($c["id"] == 0) {
319 $this->tpl->setCurrentBlock("td");
320 $this->tpl->setVariable("TD_VAL", $term["term"]);
321 $this->tpl->parseCurrentBlock();
322 } else {
323 if (in_array("md_" . $c["id"], $this->selected_cols)) {
324 $id = (int) $c["id"];
325
326 $val = " ";
327 if (isset($term["md_" . $id . "_presentation"])) {
328 $pb = $term["md_" . $id . "_presentation"]->getHTML();
329 if ($pb) {
330 $val = $pb;
331 }
332 }
333
334 $this->tpl->setCurrentBlock("td");
335 $this->tpl->setVariable("TD_VAL", $val);
336 $this->tpl->parseCurrentBlock();
337 }
338 }
339 }
340 }
341}
An exception for terminatinating execution or to throw for unit testing.
User interface class for advanced drop-down selection lists.
Glossary definition page object.
Class ilGlossaryDefinition.
static getDefinitionList($a_term_id)
static
static hasReferences($a_glossary_id)
Check if a glossary uses references.
static isReferenced($a_glo_id, $a_term_id)
Is a term referenced by one or multiple glossaries.
static getNumberOfUsages($a_term_id)
Get number of usages.
static _lookGlossaryID($term_id)
get glossary id form term id
static getInstance()
Singleton: get instance.
static _lookupTitle($a_id)
lookup object title
static xml2output($a_text, $a_wysiwyg=false, $a_replace_lists=true, $unmask=true)
Converts xml from DB to output in edit textarea.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
setEnableHeader($a_enableheader)
Set Enable Header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
showGlossaryColumn()
Show glossary column.
fillRow($term)
Fill table row.
__construct($a_parent_obj, $a_parent_cmd, $a_tax_node)
Constructor.
getSelectableColumns()
Get selectable columns.
numericOrdering($a_field)
Should this field be sorted numeric?
This class represents a text property in a property form.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46