ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBiblEntryTablePresentationGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected \ilBiblEntry $entry;
27  protected string $html = '';
28  protected \ilBiblFactoryFacadeInterface $facade;
29 
33  public function __construct(ilBiblEntry $entry, ilBiblFactoryFacadeInterface $facade)
34  {
35  $this->entry = $entry;
36  $this->facade = $facade;
37  $this->render();
38  }
39 
43  protected function render(): void
44  {
45  $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($this->getEntry()->getId());
46  //Get the model which declares which attributes to show in the overview table and how to show them
47  //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>"
48  $overviewModels = $this->facade->overviewModelFactory()->getAllOverviewModelsByType($this->facade->type());
49  //get design for specific entry type or get filetypes default design if type is not specified
50  $entryType = $this->getEntry()->getType();
51  //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, ...)
52  if (!($overviewModels[$this->facade->typeFactory()->getDataTypeIdentifierByInstance($this->facade->entryFactory()->getFileType())][$entryType] ?? false)) {
53  $entryType = 'default';
54  }
55  $single_entry = $overviewModels[$entryType];
56  //split the model into single attributes (which begin and end with a bracket, eg [|bib_default_title|. ] )
57  //such values are saved in $placeholders[0] while the same values but whithout brackets are saved in $placeholders[1] (eg |bib_default_title|. )
58  preg_match_all('/\[(.*?)\]/', $single_entry, $placeholders);
59  foreach ($placeholders[1] as $key => $placeholder) {
60  //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.
61  $cuts = explode('|', $placeholder);
62  //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)
63  if (!($attributes[$cuts[1]] ?? false)) {
64  $attribute_elements = explode('_', $cuts[1]);
65  $attribute_elements[1] = strtolower($this->getEntry()->getType());
66  $cuts[1] = implode('_', $attribute_elements);
67  }
68  if (($attributes[$cuts[1]] ?? false)) {
69  //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
70  $single_entry = str_replace($placeholders[0][$key], $cuts[0] . $attributes[$cuts[1]]
71  . $cuts[2], $single_entry);
72  // replace the <emph> tags with a span, in order to make text italic by css
73  do {
74  $first_sign_after_begin_emph_tag = strpos(strtolower($single_entry), '<emph>')
75  + 6;
76  $last_sign_after_end_emph_tag = strpos(strtolower($single_entry), '</emph>');
77  $italic_text_length = $last_sign_after_end_emph_tag
78  - $first_sign_after_begin_emph_tag;
79  //would not be true if there is no <emph> tag left
80  if ($last_sign_after_end_emph_tag) {
81  $italic_text = substr($single_entry, $first_sign_after_begin_emph_tag, $italic_text_length);
82  //parse
83  $it_tpl = new ilTemplate(
84  "tpl.bibliographic_italicizer.html",
85  true,
86  true,
87  "Modules/Bibliographic"
88  );
89  $it_tpl->setCurrentBlock("italic_section");
90  $it_tpl->setVariable('ITALIC_STRING', $italic_text);
91  $it_tpl->parseCurrentBlock();
92  //replace the emph tags and the text between with the parsed text from il_tpl
93  $text_before_emph_tag = substr($single_entry, 0, $first_sign_after_begin_emph_tag
94  - 6);
95  $text_after_emph_tag = substr($single_entry, $last_sign_after_end_emph_tag
96  + 7);
97  $single_entry = $text_before_emph_tag . $it_tpl->get()
98  . $text_after_emph_tag;
99  }
100  } while ($last_sign_after_end_emph_tag);
101  } else {
102  //if the attribute for the attribute key does not exist, just remove this attribute-key from the overview text line of a single entry
103  $single_entry = str_replace($placeholders[0][$key], '', $single_entry);
104  }
105  }
106  $this->setHtml($single_entry);
107  }
108 
109  public function getHtml(): string
110  {
111  return $this->html;
112  }
113 
114  public function setHtml(string $html): void
115  {
116  $this->html = $html;
117  }
118 
119  public function getEntry(): \ilBiblEntry
120  {
121  return $this->entry;
122  }
123 
124  public function setEntry(\ilBiblEntry $entry): void
125  {
126  $this->entry = $entry;
127  }
128 }
$attributes
Definition: metadata.php:248
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...
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilBiblEntry $entry, ilBiblFactoryFacadeInterface $facade)
ilBiblEntryTablePresentationGUI constructor.