ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBiblLibraryPresentationGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
30 public function __construct(
31 protected \ilBiblLibraryInterface $library,
32 protected \ilBiblFactoryFacade $facade,
33 protected \ilCtrlInterface $ctrl,
34 protected \ilLanguage $lng,
35 protected UIServices $ui
36 ) {
37 }
38
42 public function generateLibraryLink(ilBiblEntry $entry, string $type): string
43 {
44 $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($entry->getId());
45 $type = $this->facade->typeFactory()->getInstanceForString($type);
46 $attr = [];
47 $prefix = '';
48 switch ($type->getId()) {
50 $prefix = "bib_default_";
51 if (!empty($attributes[$prefix . "isbn"])) {
52 $attr = ["isbn"];
53 } elseif (!empty($attributes[$prefix . "pmid"])) {
54 $attr = ["pmid"];
55 } elseif (!empty($attributes[$prefix . "doi"])) {
56 $attr = ["doi"];
57 } elseif (!empty($attributes[$prefix . "issn"])) {
58 $attr = ["issn"];
59 } else {
60 $attr = ["title", "author", "year", "number", "volume"];
61 }
62 break;
64 $prefix = "ris_" . strtolower($entry->getType()) . "_";
65 if (!empty($attributes[$prefix . "sn"])) {
66 $attr = ["sn"];
67 } elseif (!empty($attributes[$prefix . "do"])) {
68 $attr = ["do"];
69 } else {
70 $attr = ["ti", "t1", "au", "py", "is", "vl"];
71 }
72 break;
73 }
74
75 $url_params = "?";
76 if (count($attr) === 1) {
77 if (($attr[0] === "doi") || ($attr[0] === "pmid")) {
78 $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
79 . "%3A" . $attributes[$prefix . $attr[0]];
80 } elseif ($attr[0] === "do") {
81 $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
82 . "i%3A" . $attributes[$prefix . $attr[0]];
83 } else {
84 $url_params .= $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "="
85 . urlencode((string) $attributes[$prefix . $attr[0]]);
86 }
87 } else {
88 foreach ($attr as $a) {
89 if (array_key_exists($prefix . $a, $attributes)) {
90 if (strlen($url_params) > 1) {
91 $url_params .= "&";
92 }
93 $url_params .= $this->formatAttribute($a, $type, $attributes, $prefix) . "="
94 . urlencode((string) $attributes[$prefix . $a]);
95 }
96 }
97 }
98
99 return $this->library->getUrl() . $url_params;
100 }
101
105 public function getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
106 {
107 $action = $this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation());
108 if (null !== ($img_path = $this->library->getImg())) {
109 $icon = $this->ui->factory()->symbol()->icon()->custom($img_path, "");
110 $btn_online_link = $this->ui->factory()->button()->bulky(
111 $icon,
112 $this->lng->txt('bibl_link_online'),
113 $action
114 );
115 } else {
116 $btn_online_link = $this->ui->factory()->button()->standard(
117 $this->lng->txt('bibl_link_online'),
118 $action
119 );
120 }
121
122 return $this->ui->renderer()->render($btn_online_link);
123 }
124
128 public function formatAttribute(string $a, ilBiblTypeInterface $type, array $attributes, string $prefix): string
129 {
130 if ($type->getStringRepresentation() === 'ris') {
131 switch ($a) {
132 case 't1':
133 case 'ti':
134 $a = "title";
135 break;
136 case 'au':
137 $a = "author";
138 break;
139 case 'sn':
140 $a = strlen((string) $attributes[$prefix . "sn"]) <= 9 ? "issn" : "isbn";
141 break;
142 case 'py':
143 $a = "date";
144 break;
145 case 'is':
146 $a = "issue";
147 break;
148 case 'vl':
149 $a = "volume";
150 break;
151 }
152 } elseif ($type->getStringRepresentation() === 'bib') {
153 switch ($a) {
154 case 'number':
155 $a = "issue";
156 break;
157 case 'year':
158 $a = "date";
159 break;
160 }
161 }
162
163 return $a;
164 }
165}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
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...
Class ilBiblLibraryPresentationGUI.
__construct(protected \ilBiblLibraryInterface $library, protected \ilBiblFactoryFacade $facade, protected \ilCtrlInterface $ctrl, protected \ilLanguage $lng, protected UIServices $ui)
ilBiblLibraryPresentationGUI constructor.
generateLibraryLink(ilBiblEntry $entry, string $type)
formatAttribute(string $a, ilBiblTypeInterface $type, array $attributes, string $prefix)
getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
language handling
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31