ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
class.ilPresentationTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI;
27use Psr\Http\Message\ServerRequestInterface;
28
33{
34 protected \ILIAS\Style\Content\Service $content_style;
35 protected ilObjUser $user;
36 protected ilCtrl $ctrl;
37 protected ilLanguage $lng;
41 protected UI\Factory $ui_fac;
42 protected UI\Renderer $ui_ren;
43 protected ServerRequestInterface $request;
44 protected object $parent_obj;
46 protected bool $offline = false;
47 protected int $tax_node = 0;
50 protected \ilUIFilterService $filter_service;
51 protected \ILIAS\AdvancedMetaData\Services\Services $adv_md_service;
52 protected ?array $filter_data = null;
53 protected array $terms = [];
54
55 public function __construct(
56 $parent_object,
58 bool $offline,
59 int $tax_node = 0
60 ) {
61 global $DIC;
62
63 $this->ctrl = $DIC->ctrl();
64 $this->user = $DIC->user();
65 $this->lng = $DIC->language();
66 $this->tpl = $DIC->ui()->mainTemplate();
67 $this->tabs_gui = $DIC->tabs();
68 $this->nav_history = $DIC["ilNavigationHistory"];
69 $this->ui_fac = $DIC->ui()->factory();
70 $this->ui_ren = $DIC->ui()->renderer();
71 $this->request = $DIC->http()->request();
72 $this->parent_obj = $parent_object;
73 $this->glossary = $glossary;
74 $this->offline = $offline;
75 $this->tax_node = $tax_node;
76 $this->pres_gui_request = $DIC->glossary()
77 ->internal()
78 ->gui()
79 ->presentation()
80 ->request();
81 $this->manager = $DIC->glossary()
82 ->internal()
83 ->domain()
84 ->presentation($this->glossary);
85 $this->filter_service = $DIC->uiService()->filter();
86 $this->adv_md_service = new \ILIAS\AdvancedMetaData\Services\Services();
87 $this->content_style = $DIC->contentStyle();
88 }
89
90 public function executeCommand(): void
91 {
92 $next_class = $this->ctrl->getNextClass($this);
93 $cmd = $this->ctrl->getCmd();
94
95 switch ($next_class) {
96 default:
97 $cmd = $this->ctrl->getCmd("show");
98 $ret = $this->$cmd();
99 break;
100 }
101 }
102
103 public function show(): void
104 {
105 $this->ctrl->setParameter($this, "term_id", "");
106 $this->tabs_gui->activateTab("terms");
107
108 $this->nav_history->addItem(
109 $this->glossary->getRefId(),
110 $this->ctrl->getLinkTargetByClass("ilGlossaryPresentationGUI", "listTerms"),
111 "glo"
112 );
113
114 $this->content_style->gui()->addCss(
115 $this->tpl,
116 $this->glossary->getRefId()
117 );
118
119 $filter = $this->initFilter();
120 $this->filter_data = $this->filter_service->getData($filter);
121 $this->manager->setSessionLetter($this->filter_data["letter"] ?? "");
122
123 $adt_search_bridges = $this->getADTSearchBridges();
124 $this->initTerms($adt_search_bridges);
125
126 $view_control = $this->initViewControl();
127 if ($vc_data = $view_control->getData()) {
128 $this->setStartAndLengthForViewControl($vc_data);
129 }
130
131 $pres_table = $this->initPresentationTable();
132
133 $this->tpl->setContent($this->ui_ren->render([$filter, $view_control, $pres_table]));
134 $this->tpl->setPermanentLink("glo", $this->glossary->getRefId());
135 }
136
137 protected function applyFilter(): void
138 {
139 $this->manager->setSessionViewControlStart(0);
140 $this->show();
141 }
142
143 protected function initTerms(array $adt_search_bridges): void
144 {
145 $this->terms = $this->glossary->getTermList(
146 $this->filter_data["term"] ?? "",
147 $this->filter_data["letter"] ?? "",
148 $this->filter_data["definition"] ?? "",
149 $this->tax_node,
150 false,
151 true,
152 $adt_search_bridges,
153 false,
154 true
155 );
156 }
157
158 protected function getADTSearchBridges(): array
159 {
160 $bridges = [];
161 if (is_array($this->filter_data)) {
162 foreach ($this->filter_data as $input_key => $value) {
163 if (substr($input_key, 0, 7) != "adv_md_") {
164 continue;
165 }
166 if (!$value) {
167 continue;
168 }
169
170 $field_id = substr($input_key, 7);
171 $field = \ilAdvancedMDFieldDefinition::getInstance((int) $field_id);
172 $field_form = \ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance(
173 $field->getADTDefinition(),
174 true,
175 false
176 );
177
178 if (is_array($value)) {
179 switch (true) {
180 case $field_form instanceof ilADTDateSearchBridgeRange:
181 $start = $value[0];
182 $end = $value[1];
183 if ($start) {
184 $field_form->getLowerADT()->setDate(new ilDate($start, IL_CAL_DATE));
185 }
186 if ($end) {
187 $field_form->getUpperADT()->setDate(new ilDate($end, IL_CAL_DATE));
188 }
189 if ($start || $end) {
190 $bridges[$field_id] = $field_form;
191 }
192 break;
193 case $field_form instanceof ilADTDateTimeSearchBridgeRange:
194 if ($value[0]) {
195 $start = strtotime($value[0]);
196 $field_form->getLowerADT()->setDate(new ilDateTime($start, IL_CAL_UNIX));
197 }
198 if ($value[1]) {
199 $end = strtotime($value[1]);
200 $field_form->getUpperADT()->setDate(new ilDateTime($end, IL_CAL_UNIX));
201 }
202 if ($value[0] || $value[1]) {
203 $bridges[$field_id] = $field_form;
204 }
205 break;
206 case $field_form instanceof ilADTEnumSearchBridgeMulti:
207 $field_form->getADT()->setSelections($value);
208 $bridges[$field_id] = $field_form;
209 break;
210 }
211 } else {
212 switch (true) {
213 case $field_form instanceof ilADTTextSearchBridgeSingle:
214 $field_form->getADT()->setText($value);
215 $bridges[$field_id] = $field_form;
216 break;
217 case $field_form instanceof ilADTFloatSearchBridgeSingle:
218 case $field_form instanceof ilADTIntegerSearchBridgeSingle:
219 // numeric metadata currently not supported as filter inputs
220 $field_form->getADT()->setNumber($value);
221 $bridges[$field_id] = $field_form;
222 break;
223 case $field_form instanceof ilADTEnumSearchBridgeSingle:
224 $field_form->getADT()->setSelection($value);
225 $bridges[$field_id] = $field_form;
226 break;
227 case $field_form instanceof ilADTExternalLinkSearchBridgeSingle:
228 $field_form->getADT()->setUrl($value);
229 $bridges[$field_id] = $field_form;
230 break;
231 case $field_form instanceof ilADTInternalLinkSearchBridgeSingle:
232 $field_form->getADT()->setTargetRefId(1);
233 $field_form->setTitleQuery($value);
234 $bridges[$field_id] = $field_form;
235 break;
236 }
237 }
238 }
239 }
240
241 return $bridges;
242 }
243
244 protected function initFilter(): Filter\Standard
245 {
246 $first_letters = $this->glossary->getFirstLetters($this->tax_node);
247 $session_letter = ilUtil::stripSlashes($this->manager->getSessionLetter());
248 if (!empty($session_letter) && !in_array($session_letter, $first_letters)) {
249 $first_letters[$session_letter] = $session_letter;
250 }
251
252 $default_inputs = [
253 "letter" => $this->ui_fac->input()->field()->select(
254 $this->lng->txt("glo_term_letter"),
255 $first_letters
256 ),
257 "term" => $this->ui_fac->input()->field()->text($this->lng->txt("cont_term")),
258 "definition" => $this->ui_fac->input()->field()->text($this->lng->txt("cont_definition"))
259 ];
260 $adv_md_inputs = $this->adv_md_service->forSubObjects(
261 "glo",
262 $this->glossary->getRefId(),
263 "term"
264 )->inFilter()->getFilterInputs();
265 $inputs = $default_inputs + $adv_md_inputs;
266
267 $default_inputs_active = [true, true, true];
268 $adv_md_inputs_active = [];
269 for ($i = 0; $i < count($adv_md_inputs); $i++) {
270 $adv_md_inputs_active[] = false;
271 }
272 $inputs_active = array_merge($default_inputs_active, $adv_md_inputs_active);
273
274 $filter = $this->filter_service->standard(
275 self::class . "_filter_" . $this->glossary->getRefId(),
276 $this->ctrl->getLinkTarget($this, "applyFilter"),
277 $inputs,
278 $inputs_active,
279 false,
280 true
281 );
282
283 return $filter;
284 }
285
286 protected function initPresentationTable(bool $offline = false): Table\Presentation
287 {
288 $vc_start = 0;
289 $vc_length = 9999;
290 if (!$offline) {
291 $vc_start = $this->manager->getSessionViewControlStart();
292 $vc_length = $this->manager->getSessionViewControlLength();
293 }
294
295 $terms_sliced = array_slice(
296 $this->terms,
297 $vc_start,
298 $vc_length
299 );
300 $data = [];
301 foreach ($terms_sliced as $term) {
302 $data[] = [
303 "term_id" => (int) $term["id"],
304 "term" => $term["term"],
305 "short_txt" => $this->getShortTextForTerm((int) $term["id"]),
306 "definition" => $this->parent_obj->listDefinitions(
307 $this->pres_gui_request->getRefId(),
308 (int) $term["id"],
309 true,
310 false,
312 false
313 )
314 ];
315 }
316
317 $table = $this->ui_fac->table()->presentation(
318 $this->lng->txt("cont_terms"),
319 [],
320 function ($row, array $record, $ui_factory) {
321 $mdgui = new ilObjectMetaDataGUI($this->glossary, "term", $record["term_id"]);
322 $adv_term_sets = $this->adv_md_service->forObject(
323 "glo",
324 $this->glossary->getRefId(),
325 "term",
326 $record["term_id"]
327 )->custom()->sets();
328 $adv_data = [];
329 foreach ($adv_term_sets as $set) {
330 if (!empty($fields = $set->fields())) {
331 $adv_data[] = "<b>" . $set->presentableTitle() . "</b>";
332 }
333 foreach ($fields as $field) {
334 $adv_data[] = $field->presentableTitle() . ": " . $field->valueAsHTML();
335 }
336 }
337
338 return $row
339 ->withHeadline($record["term"])
340 ->withImportantFields([$record["short_txt"]])
341 ->withContent(
342 $ui_factory->legacy()->content($record["definition"])
343 )
344 ->withFurtherFieldsHeadline($this->lng->txt("glo_md_advanced"))
345 ->withFurtherFields($adv_data)
346 ;
347 }
348 )->withData($data);
349
350 return $table;
351 }
352
353 protected function initViewControl(): ViewControl
354 {
355 $offset = $this->manager->getSessionViewControlStart() ?: 0;
356 $limit = $this->manager->getSessionViewControlLength() ?: 25;
357 $pagination = $this->ui_fac->input()->viewControl()->pagination()
358 ->withTotalCount(count($this->terms))
359 ->withValue([Pagination::FNAME_OFFSET => $offset, Pagination::FNAME_LIMIT => $limit]);
360 ;
361 $vc_container = $this->ui_fac->input()->container()->viewControl()->standard([$pagination])
362 ->withRequest($this->request);
363
364 return $vc_container;
365 }
366
367 protected function setStartAndLengthForViewControl(array $vc_data): void
368 {
370 $range = $vc_data[0];
371 if (($start = $range->getStart()) >= 0) {
372 $this->manager->setSessionViewControlStart($start);
373 }
374 if (($length = $range->getLength()) > 0) {
375 $this->manager->setSessionViewControlLength($length);
376 }
377 }
378
379 protected function getShortTextForTerm(int $term_id): string
380 {
381 $short_str = \ilGlossaryTerm::_lookShortText($term_id);
382
384 // #18022
385 $term_obj = new \ilGlossaryTerm($term_id);
386 $term_obj->updateShortText();
387 $short_str = $term_obj->getShortText();
388 }
389
390 $page = new \ilGlossaryDefPage($term_id);
391
392 // replace tex
393 // if a tex end tag is missing a tex end tag
394 $ltexs = strrpos($short_str, "[tex]");
395 $ltexe = strrpos($short_str, "[/tex]");
396 if ($ltexs > $ltexe) {
397 $page->buildDom();
398 $short_str = $page->getFirstParagraphText();
399 $short_str = strip_tags($short_str, "<br>");
400 $ltexe = strpos($short_str, "[/tex]", $ltexs);
401 $short_str = \ilStr::shortenTextExtended($short_str, $ltexe + 6, true);
402 }
403
404 $short_str = \ilPCParagraph::xml2output(
405 $short_str,
406 false,
407 true,
408 !$page->getPageConfig()->getPreventHTMLUnmasking()
409 );
410
411 $short_str = $this->ui_ren->render($this->ui_fac->legacy()->latexContent($short_str));
412
413 return $short_str;
414 }
415
416 public function renderPresentationTableForOffline(): string
417 {
418 $this->initTerms([]);
419 $pres_table = $this->initPresentationTable(true);
420
421 return $this->ui_ren->render($pres_table);
422
423 //$this->tpl->setVariable("ADM_CONTENT", $this->ui_ren->render($pres_table));
424 //return $this->tpl->printToString();
425 }
426}
Manages presentation of glossary content.
const IL_CAL_DATE
const IL_CAL_UNIX
Class ilADTDateSearchBridgeRange.
Class ilADTDateTimeSearchBridgeRange.
Class ilADTEnumSearchBridgeMulti.
static getInstance(?int $a_field_id, ?int $a_type=null, string $language='')
Class ilCtrl provides processing control methods.
@classDescription Date and time handling
Class for single dates.
static _lookShortTextDirty(int $term_id)
get definition short text dirty
static _lookShortText(int $term_id)
get definition short text
language handling
Last visited history for repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
Class ilObjectMetaDataGUI.
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.
initPresentationTable(bool $offline=false)
__construct( $parent_object, ilObjGlossary $glossary, bool $offline, int $tax_node=0)
Presentation PresentationGUIRequest $pres_gui_request
Presentation PresentationManager $manager
ILIAS AdvancedMetaData Services Services $adv_md_service
ILIAS Style Content Service $content_style
initTerms(array $adt_search_bridges)
ilGlobalTemplateInterface $tpl
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
This describes a standard button.
Definition: Standard.php:27
withRequest(ServerRequestInterface $request)
Get a form like this where data from the request is attached.
This describes commonalities between all filters.
Definition: Filter.php:34
This describes a View Control Container.
Definition: ViewControl.php:30
This describes a Presentation Table.
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...
global $DIC
Definition: shib_login.php:26