ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 if (class_exists('ActiveRecord') != true) {
4  require_once('./Services/ActiveRecord/class.ActiveRecord.php');
5 }
6 
15 
16  const TABLE_NAME = 'il_bibl_settings';
17 
18 
23  static function returnDbTableName() {
24  return self::TABLE_NAME;
25  }
26 
27 
31  public function getConnectorContainerName() {
32  return self::TABLE_NAME;
33  }
34 
35 
47  protected $id;
56  protected $name;
65  protected $url;
73  protected $img;
81  protected $show_in_list;
82 
83 
87  public static function getAll() {
88  return self::get();
89  }
90 
91 
98  public function generateLibraryLink(ilBibliographicEntry $entry, $type) {
99  $attributes = $entry->getAttributes();
100  switch ($type) {
101  case 'bib':
102  $prefix = "bib_default_";
103  if (!empty($attributes[$prefix . "isbn"])) {
104  $attr = Array( "isbn" );
105  } elseif (!empty($attributes[$prefix . "issn"])) {
106  $attr = Array( "issn" );
107  } else {
108  $attr = Array( "title", "author", "year", "number", "volume" );
109  }
110  break;
111  case 'ris':
112  $prefix = "ris_" . strtolower($entry->getType()) . "_";
113  if (!empty($attributes[$prefix . "sn"])) {
114  $attr = Array( "sn" );
115  } else {
116  $attr = Array( "ti", "t1", "au", "py", "is", "vl" );
117  }
118  break;
119  }
120 
121  $url_params = "?";
122  if (sizeof($attr) == 1) {
123  $url_params .= $this->formatAttribute($attr[0], $type, $attributes, $prefix) . "=" . urlencode($attributes[$prefix . $attr[0]]);
124  } else {
125  foreach ($attr as $a) {
126  if (array_key_exists($prefix . $a, $attributes)) {
127  if (strlen($url_params) > 1) {
128  $url_params .= "&";
129  }
130  $url_params .= $this->formatAttribute($a, $type, $attributes, $prefix) . "=" . urlencode($attributes[$prefix . $a]);
131  }
132  }
133  }
134 
135  // return full link
136  $full_link = $this->getUrl() . $url_params;
137 
138  return $full_link;
139  }
140 
141 
148  public function getButton(ilObjBibliographic $bibl_obj, ilBibliographicEntry $entry) {
149  if ($this->getImg()) {
150  require_once('./Services/UIComponent/Button/classes/class.ilImageLinkButton.php');
151  $button = ilImageLinkButton::getInstance();
152  $button->setUrl($this->generateLibraryLink($entry, $bibl_obj->getFiletype()));
153  $button->setImage($this->getImg(), false);
154  $button->setTarget('_blank');
155  return $button->render();
156  } else {
157  require_once('./Services/UIComponent/Button/classes/class.ilLinkButton.php');
158  $button = ilLinkButton::getInstance();
159  $button->setUrl($this->generateLibraryLink($entry, $bibl_obj->getFiletype()));
160  $button->setTarget('_blank');
161  $button->setCaption('bibl_link_online');
162 
163  return $button->render();
164  }
165  }
166 
167 
176  private function formatAttribute($a, $type, $attributes, $prefix) {
177  if ($type = 'ris') {
178  switch ($a) {
179  case 'ti':
180  $a = "title";
181  break;
182  case 't1':
183  $a = "title";
184  break;
185  case 'au':
186  $a = "author";
187  break;
188  case 'sn':
189  if (strlen($attributes[$prefix . "sn"]) <= 9) {
190  $a = "issn";
191  } else {
192  $a = "isbn";
193  }
194  break;
195  case 'py':
196  $a = "date";
197  break;
198  case 'is':
199  $a = "issue";
200  break;
201  case 'vl':
202  $a = "volume";
203  break;
204  }
205  } elseif ($type = 'bib') {
206  switch ($a) {
207  case "number":
208  $a = "issue";
209  break;
210  case "year":
211  $a = "date";
212  break;
213  }
214  }
215 
216  return $a;
217  }
218 
219 
223  public function getId() {
224  return $this->id;
225  }
226 
227 
231  public function setId($id) {
232  $this->id = $id;
233  }
234 
235 
239  public function getImg() {
240  return $this->img;
241  }
242 
243 
247  public function setImg($img) {
248  $this->img = $img;
249  }
250 
251 
255  public function getName() {
256  return $this->name;
257  }
258 
259 
263  public function setName($name) {
264  $this->name = $name;
265  }
266 
267 
271  public function getShowInList() {
272  return $this->show_in_list;
273  }
274 
275 
279  public function setShowInList($show_in_list) {
280  $this->show_in_list = $show_in_list;
281  }
282 
283 
287  public function getUrl() {
288  return $this->url;
289  }
290 
291 
295  public function setUrl($url) {
296  $this->url = $url;
297  }
298 }
299 
300 ?>