ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBiblLibraryPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected $library;
15 
19  protected $facade;
20 
21 
28  {
29  $this->library = $library;
30  $this->facade = $facade;
31  }
32 
33 
43  public function generateLibraryLink(ilBiblEntry $entry, $type)
44  {
45  $attributes = $this->facade->entryFactory()->loadParsedAttributesByEntryId($entry->getId());
46  $type = $this->facade->typeFactory()->getInstanceForString($type);
47  switch ($type->getId()) {
49  $prefix = "bib_default_";
50  if (!empty($attributes[$prefix . "isbn"])) {
51  $attr = array( "isbn" );
52  } elseif (!empty($attributes[$prefix . "pmid"])) {
53  $attr = array( "pmid" );
54  } elseif (!empty($attributes[$prefix . "doi"])) {
55  $attr = array( "doi" );
56  } elseif (!empty($attributes[$prefix . "issn"])) {
57  $attr = array( "issn" );
58  } else {
59  $attr = array( "title", "author", "year", "number", "volume" );
60  }
61  break;
63  $prefix = "ris_" . strtolower($entry->getType()) . "_";
64  if (!empty($attributes[$prefix . "sn"])) {
65  $attr = array( "sn" );
66  } elseif (!empty($attributes[$prefix . "do"])) {
67  $attr = array( "do" );
68  } else {
69  $attr = array( "ti", "t1", "au", "py", "is", "vl" );
70  }
71  break;
72  }
73 
74  $url_params = "?";
75  if (sizeof($attr) == 1) {
76  if (($attr[0] == "doi") || ($attr[0] == "pmid")) {
77  $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
78  . "%3A" . $attributes[$prefix . $attr[0]];
79  } elseif ($attr[0] == "do") {
80  $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix)
81  . "i%3A" . $attributes[$prefix . $attr[0]];
82  } else {
83  $url_params .= $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "="
84  . urlencode($attributes[$prefix . $attr[0]]);
85  }
86  } else {
87  foreach ($attr as $a) {
88  if (array_key_exists($prefix . $a, $attributes)) {
89  if (strlen($url_params) > 1) {
90  $url_params .= "&";
91  }
92  $url_params .= $this->formatAttribute($a, $type, $attributes, $prefix) . "="
93  . urlencode($attributes[$prefix . $a]);
94  }
95  }
96  }
97 
98  // return full link
99  $full_link = $this->library->getUrl() . $url_params;
100 
101  return $full_link;
102  }
103 
104 
111  public function getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
112  {
113  if ($this->library->getImg()) {
114  $button = ilImageLinkButton::getInstance();
115  $button->setUrl($this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation()));
116  $button->setImage($this->library->getImg(), false);
117  $button->setTarget('_blank');
118 
119  return $button->render();
120  } else {
121  $button = ilLinkButton::getInstance();
122  $button->setUrl($this->generateLibraryLink($entry, $bibl_factory_facade->type()->getStringRepresentation()));
123  $button->setTarget('_blank');
124  $button->setCaption('bibl_link_online');
125 
126  return $button->render();
127  }
128  }
129 
130 
142  public function formatAttribute($a, $type, $attributes, $prefix)
143  {
144  if ($type == 'ris') {
145  switch ($a) {
146  case 'ti':
147  $a = "title";
148  break;
149  case 't1':
150  $a = "title";
151  break;
152  case 'au':
153  $a = "author";
154  break;
155  case 'sn':
156  if (strlen($attributes[$prefix . "sn"]) <= 9) {
157  $a = "issn";
158  } else {
159  $a = "isbn";
160  }
161  break;
162  case 'py':
163  $a = "date";
164  break;
165  case 'is':
166  $a = "issue";
167  break;
168  case 'vl':
169  $a = "volume";
170  break;
171  }
172  } elseif ($type = 'bib') {
173  switch ($a) {
174  case 'number':
175  $a = "issue";
176  break;
177  case 'year':
178  $a = "date";
179  break;
180  }
181  }
182 
183  return $a;
184  }
185 }
$type
getButton(ilBiblFactoryFacadeInterface $bibl_factory_facade, ilBiblEntry $entry)
Interface ilBiblFactoryFacadeInterface.
Interface ilBiblLibraryInterface.
formatAttribute($a, $type, $attributes, $prefix)
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
Class ilBiblEntry.
__construct(\ilBiblLibraryInterface $library, \ilBiblFactoryFacade $facade)
ilBiblLibraryPresentationGUI constructor.
Class ilBiblFactoryFacade.
Class ilBiblLibraryPresentationGUI.