ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBiblEntryTablePresentationGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected string $html = '';
27
31 public function __construct(protected \ilBiblEntry $entry, protected \ilBiblFactoryFacadeInterface $facade)
32 {
33 $this->render();
34 }
35
39 protected function render(): void
40 {
41 $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($this->getEntry()->getId());
42 //Get the model which declares which attributes to show in the overview table and how to show them
43 //example for overviewModels: $overviewModels['bib']['default'] => "[<strong>|bib_default_author|</strong>: ][|bib_default_title|. ]<Emph>[|bib_default_publisher|][, |bib_default_year|][, |bib_default_address|].</Emph>"
44 $overviewModels = $this->facade->overviewModelFactory()->getAllOverviewModelsByType($this->facade->type());
45 //get design for specific entry type or get filetypes default design if type is not specified
46 $entryType = $this->getEntry()->getType();
47 //if there is no model for the specific entrytype (book, article, ....) the entry overview will be structured by the default entrytype from the given filetype (ris, bib, ...)
48 if (!($overviewModels[$this->facade->typeFactory()->getDataTypeIdentifierByInstance($this->facade->entryFactory()->getFileType())][$entryType] ?? false)) {
49 $entryType = 'default';
50 }
51 $single_entry = $overviewModels[$entryType];
52 //split the model into single attributes (which begin and end with a bracket, eg [|bib_default_title|. ] )
53 //such values are saved in $placeholders[0] while the same values but whithout brackets are saved in $placeholders[1] (eg |bib_default_title|. )
54 preg_match_all('/\[(.*?)\]/', $single_entry, $placeholders);
55 foreach ($placeholders[1] as $key => $placeholder) {
56 //cut a moedel attribute like |bib_default_title|. in three pieces while $cuts[1] is the attribute key for the actual value and $cuts[0] is what comes before respectively $cuts[2] is what comes after the value if it is not empty.
57 $cuts = explode('|', $placeholder);
58 //if attribute key does not exist, because it comes from the default entry (e.g. ris_default_u2), we replace 'default' with the entrys type (e.g. ris_book_u2)
59 if (!($attributes[$cuts[1]] ?? false)) {
60 $attribute_elements = explode('_', $cuts[1]);
61 $attribute_elements[1] = strtolower($this->getEntry()->getType());
62 $cuts[1] = implode('_', $attribute_elements);
63 }
64 if (($attributes[$cuts[1]] ?? false)) {
65 //if the attribute for the attribute key exists, replace one attribute in the overview text line of a single entry with its actual value and the text before and after the value given by the model
66 $single_entry = str_replace($placeholders[0][$key], $cuts[0] . $attributes[$cuts[1]]
67 . $cuts[2], $single_entry);
68 // replace the <emph> tags with a span, in order to make text italic by css
69 do {
70 $first_sign_after_begin_emph_tag = stripos($single_entry, '<emph>')
71 + 6;
72 $last_sign_after_end_emph_tag = stripos($single_entry, '</emph>');
73 $italic_text_length = $last_sign_after_end_emph_tag
74 - $first_sign_after_begin_emph_tag;
75 //would not be true if there is no <emph> tag left
76 if ($last_sign_after_end_emph_tag) {
77 $italic_text = substr($single_entry, $first_sign_after_begin_emph_tag, $italic_text_length);
78 //parse
79 $it_tpl = new ilTemplate(
80 "tpl.bibliographic_italicizer.html",
81 true,
82 true,
83 "components/ILIAS/Bibliographic"
84 );
85 $it_tpl->setCurrentBlock("italic_section");
86 $it_tpl->setVariable('ITALIC_STRING', $italic_text);
87 $it_tpl->parseCurrentBlock();
88 //replace the emph tags and the text between with the parsed text from il_tpl
89 $text_before_emph_tag = substr($single_entry, 0, $first_sign_after_begin_emph_tag
90 - 6);
91 $text_after_emph_tag = substr($single_entry, $last_sign_after_end_emph_tag
92 + 7);
93 $single_entry = $text_before_emph_tag . $it_tpl->get()
94 . $text_after_emph_tag;
95 }
96 } while ($last_sign_after_end_emph_tag);
97 } else {
98 //if the attribute for the attribute key does not exist, just remove this attribute-key from the overview text line of a single entry
99 $single_entry = str_replace($placeholders[0][$key], '', $single_entry);
100 }
101 }
102 $this->setHtml($single_entry);
103 }
104
105 public function getHtml(): string
106 {
107 return $this->html;
108 }
109
110 public function setHtml(string $html): void
111 {
112 $this->html = $html;
113 }
114
115 public function getEntry(): \ilBiblEntry
116 {
117 return $this->entry;
118 }
119
120 public function setEntry(\ilBiblEntry $entry): void
121 {
122 $this->entry = $entry;
123 }
124}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected \ilBiblEntry $entry, protected \ilBiblFactoryFacadeInterface $facade)
ilBiblEntryTablePresentationGUI constructor.
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...