ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBibliographicSetting.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once('./Services/ActiveRecord/class.ActiveRecord.php');
4 
13 
14  const TABLE_NAME = 'il_bibl_settings';
15 
16 
21  static function returnDbTableName() {
22  return self::TABLE_NAME;
23  }
24 
25 
29  public function getConnectorContainerName() {
30  return self::TABLE_NAME;
31  }
32 
33 
45  protected $id;
54  protected $name;
63  protected $url;
71  protected $img;
79  protected $show_in_list;
80 
81 
85  public static function getAll() {
86  return self::get();
87  }
88 
89 
96  public function generateLibraryLink(ilBibliographicEntry $entry, $type) {
97  $attributes = $entry->getAttributes();
98  switch ($type) {
99  case 'bib':
100  $prefix = "bib_default_";
101  if (!empty($attributes[$prefix . "isbn"])) {
102  $attr = array( "isbn" );
103  } elseif (!empty($attributes[$prefix . "pmid"])) {
104  $attr = array( "pmid" );
105  } elseif (!empty($attributes[$prefix . "doi"])) {
106  $attr = array( "doi" );
107  } elseif (!empty($attributes[$prefix . "issn"])) {
108  $attr = array( "issn" );
109  } else {
110  $attr = array( "title", "author", "year", "number", "volume" );
111  }
112  break;
113  case 'ris':
114  $prefix = "ris_" . strtolower($entry->getType()) . "_";
115  if (!empty($attributes[$prefix . "sn"])) {
116  $attr = array( "sn" );
117  } elseif (!empty($attributes[$prefix . "do"])) {
118  $attr = array( "do" );
119  } else {
120  $attr = array( "ti", "t1", "au", "py", "is", "vl" );
121  }
122  break;
123  }
124 
125  $url_params = "?";
126  if (sizeof($attr) == 1) {
127  if (($attr[0] == "doi") || ($attr[0] == "pmid")) {
128  $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "%3A" . $attributes[$prefix . $attr[0]];
129  } elseif ($attr[0] == "do") {
130  $url_params .= "id=" . $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "i%3A" . $attributes[$prefix . $attr[0]];
131  } else {
132  $url_params .= $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "=" . urlencode($attributes[$prefix . $attr[0]]);
133  }} else {
134  foreach ($attr as $a) {
135  if (array_key_exists($prefix . $a, $attributes)) {
136  if (strlen($url_params) > 1) {
137  $url_params .= "&";
138  }
139  $url_params .= $this->formatAttribute($a, $type, $attributes, $prefix) . "=" . urlencode($attributes[$prefix . $a]);
140  }
141  }
142  }
143 
144  // return full link
145  $full_link = $this->getUrl() . $url_params;
146 
147  return $full_link;
148  }
149 
150 
157  public function getButton(ilObjBibliographic $bibl_obj, ilBibliographicEntry $entry) {
158  if ($this->getImg()) {
159  require_once('./Services/UIComponent/Button/classes/class.ilImageLinkButton.php');
160  $button = ilImageLinkButton::getInstance();
161  $button->setUrl($this->generateLibraryLink($entry, $bibl_obj->getFiletype()));
162  $button->setImage($this->getImg(), false);
163  } else {
164  require_once('./Services/UIComponent/Button/classes/class.ilLinkButton.php');
165  $button = ilLinkButton::getInstance();
166  $button->setUrl($this->generateLibraryLink($entry, $bibl_obj->getFiletype()));
167  $button->setCaption('bibl_link_online');
168  }
169 
170  $button->setTarget('_blank');
171 
172  return $button->render();
173  }
174 
175 
184  private function formatAttribute($a, $type, $attributes, $prefix) {
185  if ($type = 'ris') {
186  switch ($a) {
187  case 'ti':
188  $a = "title";
189  break;
190  case 't1':
191  $a = "title";
192  break;
193  case 'au':
194  $a = "author";
195  break;
196  case 'sn':
197  if (strlen($attributes[$prefix . "sn"]) <= 9) {
198  $a = "issn";
199  } else {
200  $a = "isbn";
201  }
202  break;
203  case 'py':
204  $a = "date";
205  break;
206  case 'is':
207  $a = "issue";
208  break;
209  case 'vl':
210  $a = "volume";
211  break;
212  }
213  } elseif ($type = 'bib') {
214  switch ($a) {
215  case 'number':
216  $a = "issue";
217  break;
218  case 'year':
219  $a = "date";
220  break;
221  }
222  }
223 
224  return $a;
225  }
226 
227 
231  public function getId() {
232  return $this->id;
233  }
234 
235 
239  public function setId($id) {
240  $this->id = $id;
241  }
242 
243 
247  public function getImg() {
248  return $this->img;
249  }
250 
251 
255  public function setImg($img) {
256  $this->img = $img;
257  }
258 
259 
263  public function getName() {
264  return $this->name;
265  }
266 
267 
271  public function setName($name) {
272  $this->name = $name;
273  }
274 
275 
279  public function getShowInList() {
280  return $this->show_in_list;
281  }
282 
283 
287  public function setShowInList($show_in_list) {
288  $this->show_in_list = $show_in_list;
289  }
290 
291 
295  public function getUrl() {
296  return $this->url;
297  }
298 
299 
303  public function setUrl($url) {
304  $this->url = $url;
305  }
306 }
Class ilBibliographicSetting.
getButton(ilObjBibliographic $bibl_obj, ilBibliographicEntry $entry)
Class ActiveRecord.
formatAttribute($a, $type, $attributes, $prefix)
generateLibraryLink(ilBibliographicEntry $entry, $type)
Create styles array
The data for the language used.
Class ilBibliographicEntry.
Class ilObjBibliographic.