ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBiblLibraryPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected $library;
18  protected $facade;
19 
20 
27  {
28  $this->library = $library;
29  $this->facade = $facade;
30  }
31 
32 
42  public function generateLibraryLink(ilBiblEntry $entry, $type)
43  {
44  $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($entry->getId());
45  $type = $this->facade->typeFactory()->getInstanceForString($type);
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 (sizeof($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 full link
98  $full_link = $this->library->getUrl() . $url_params;
99 
100  return $full_link;
101  }
102 
103 
110  public function getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
111  {
112  if ($this->library->getImg()) {
113  $button = ilImageLinkButton::getInstance();
114  $button->setUrl($this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation()));
115  $button->setImage($this->library->getImg(), false);
116  $button->setTarget('_blank');
117 
118  return $button->render();
119  } else {
120  $button = ilLinkButton::getInstance();
121  $button->setUrl($this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation()));
122  $button->setTarget('_blank');
123  $button->setCaption('bibl_link_online');
124 
125  return $button->render();
126  }
127  }
128 
129 
141  public function formatAttribute($a, $type, $attributes, $prefix)
142  {
143  if ($type->getStringRepresentation() === 'ris') {
144  switch ($a) {
145  case 'ti':
146  $a = "title";
147  break;
148  case 't1':
149  $a = "title";
150  break;
151  case 'au':
152  $a = "author";
153  break;
154  case 'sn':
155  if (strlen($attributes[$prefix . "sn"]) <= 9) {
156  $a = "issn";
157  } else {
158  $a = "isbn";
159  }
160  break;
161  case 'py':
162  $a = "date";
163  break;
164  case 'is':
165  $a = "issue";
166  break;
167  case 'vl':
168  $a = "volume";
169  break;
170  }
171  } elseif ($type->getStringRepresentation() === 'bib') {
172  switch ($a) {
173  case 'number':
174  $a = "issue";
175  break;
176  case 'year':
177  $a = "date";
178  break;
179  }
180  }
181 
182  return $a;
183  }
184 }
$attributes
Definition: metadata.php:231
$type
getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
Interface ilBiblFactoryFacadeInterface.
Interface ilBiblLibraryInterface.
formatAttribute($a, $type, $attributes, $prefix)
Class ilBiblEntry.
__construct(\ilBiblLibraryInterface $library, \ilBiblFactoryFacade $facade)
ilBiblLibraryPresentationGUI constructor.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
Class ilBiblFactoryFacade.
Class ilBiblLibraryPresentationGUI.