ILIAS  release_8 Revision v8.24
class.ilBiblLibraryPresentationGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ilBiblLibraryInterface $library;
26 protected \ilBiblFactoryFacade $facade;
27
32 {
33 $this->library = $library;
34 $this->facade = $facade;
35 }
36
40 public function generateLibraryLink(ilBiblEntry $entry, string $type): string
41 {
42 $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($entry->getId());
43 $type = $this->facade->typeFactory()->getInstanceForString($type);
44 $attr = [];
45 $prefix = '';
46 switch ($type->getId()) {
48 $prefix = "bib_default_";
49 if (!empty($attributes[$prefix . "isbn"])) {
50 $attr = array("isbn");
51 } elseif (!empty($attributes[$prefix . "pmid"])) {
52 $attr = array("pmid");
53 } elseif (!empty($attributes[$prefix . "doi"])) {
54 $attr = array("doi");
55 } elseif (!empty($attributes[$prefix . "issn"])) {
56 $attr = array("issn");
57 } else {
58 $attr = array("title", "author", "year", "number", "volume");
59 }
60 break;
62 $prefix = "ris_" . strtolower($entry->getType()) . "_";
63 if (!empty($attributes[$prefix . "sn"])) {
64 $attr = array("sn");
65 } elseif (!empty($attributes[$prefix . "do"])) {
66 $attr = array("do");
67 } else {
68 $attr = array("ti", "t1", "au", "py", "is", "vl");
69 }
70 break;
71 }
72
73 $url_params = "?";
74 if (count($attr) === 1) {
75 if (($attr[0] === "doi") || ($attr[0] === "pmid")) {
76 $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
77 . "%3A" . $attributes[$prefix . $attr[0]];
78 } elseif ($attr[0] === "do") {
79 $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
80 . "i%3A" . $attributes[$prefix . $attr[0]];
81 } else {
82 $url_params .= $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "="
83 . urlencode($attributes[$prefix . $attr[0]]);
84 }
85 } else {
86 foreach ($attr as $a) {
87 if (array_key_exists($prefix . $a, $attributes)) {
88 if (strlen($url_params) > 1) {
89 $url_params .= "&";
90 }
91 $url_params .= $this->formatAttribute($a, $type, $attributes, $prefix) . "="
92 . urlencode($attributes[$prefix . $a]);
93 }
94 }
95 }
96
97 return $this->library->getUrl() . $url_params;
98 }
99
103 public function getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
104 {
105 if ($this->library->getImg()) {
107 $button->setImage($this->library->getImg(), false);
108 $button->addCSSClass("btn");
109 $button->addCSSClass("btn-default");
110 } else {
111 $button = ilLinkButton::getInstance();
112 }
113 $button->setUrl($this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation()));
114 $button->setTarget('_blank');
115 $button->setCaption('bibl_link_online');
116
117 return $button->render();
118 }
119
123 public function formatAttribute(string $a, ilBiblTypeInterface $type, array $attributes, string $prefix): string
124 {
125 if ($type->getStringRepresentation() === 'ris') {
126 switch ($a) {
127 case 't1':
128 case 'ti':
129 $a = "title";
130 break;
131 case 'au':
132 $a = "author";
133 break;
134 case 'sn':
135 if (strlen($attributes[$prefix . "sn"]) <= 9) {
136 $a = "issn";
137 } else {
138 $a = "isbn";
139 }
140 break;
141 case 'py':
142 $a = "date";
143 break;
144 case 'is':
145 $a = "issue";
146 break;
147 case 'vl':
148 $a = "volume";
149 break;
150 }
151 } elseif ($type->getStringRepresentation() === 'bib') {
152 switch ($a) {
153 case 'number':
154 $a = "issue";
155 break;
156 case 'year':
157 $a = "date";
158 break;
159 }
160 }
161
162 return $a;
163 }
164}
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
generateLibraryLink(ilBiblEntry $entry, string $type)
formatAttribute(string $a, ilBiblTypeInterface $type, array $attributes, string $prefix)
__construct(\ilBiblLibraryInterface $library, \ilBiblFactoryFacade $facade)
ilBiblLibraryPresentationGUI constructor.
getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$attributes
Definition: metadata.php:248
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$type