ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilBiblLibraryPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 
24 {
28  public function __construct(
29  protected \ilBiblLibraryInterface $library,
30  protected \ilBiblFactoryFacade $facade,
31  protected \ilCtrlInterface $ctrl,
32  protected \ilLanguage $lng,
33  protected \ILIAS\DI\UIServices $ui
34  ) {
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  $action = $this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation());
106  if (null !== ($img_path = $this->library->getImg())) {
107  $icon = $this->ui->factory()->symbol()->icon()->custom($img_path, "");
108  $btn_online_link = $this->ui->factory()->button()->bulky(
109  $icon,
110  $this->lng->txt('bibl_link_online'),
111  $action
112  );
113  } else {
114  $btn_online_link = $this->ui->factory()->button()->standard(
115  $this->lng->txt('bibl_link_online'),
116  $action
117  );
118  }
119 
120  return $this->ui->renderer()->render($btn_online_link);
121  }
122 
126  public function formatAttribute(string $a, ilBiblTypeInterface $type, array $attributes, string $prefix): string
127  {
128  if ($type->getStringRepresentation() === 'ris') {
129  switch ($a) {
130  case 't1':
131  case 'ti':
132  $a = "title";
133  break;
134  case 'au':
135  $a = "author";
136  break;
137  case 'sn':
138  if (strlen($attributes[$prefix . "sn"]) <= 9) {
139  $a = "issn";
140  } else {
141  $a = "isbn";
142  }
143  break;
144  case 'py':
145  $a = "date";
146  break;
147  case 'is':
148  $a = "issue";
149  break;
150  case 'vl':
151  $a = "volume";
152  break;
153  }
154  } elseif ($type->getStringRepresentation() === 'bib') {
155  switch ($a) {
156  case 'number':
157  $a = "issue";
158  break;
159  case 'year':
160  $a = "date";
161  break;
162  }
163  }
164 
165  return $a;
166  }
167 }
__construct(protected \ilBiblLibraryInterface $library, protected \ilBiblFactoryFacade $facade, protected \ilCtrlInterface $ctrl, protected \ilLanguage $lng, protected \ILIAS\DI\UIServices $ui)
ilBiblLibraryPresentationGUI constructor.
getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
Interface Observer Contains several chained tasks and infos about them.
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 HTTPServicesTest.
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:32
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
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...