ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBibItem.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once ("Services/MetaData/classes/class.ilMDLanguageItem.php");
25 
36 class ilBibItem
37 {
40  var $xml;
41 
43  var $abstract;
44 
45  var $id = 0;
46  var $type = "bib";
47 
48  var $meta;
49 
50  var $language;
51 
56  function ilBibItem($content_obj = 0)
57  {
58  global $ilias;
59 
60  $this->ilias =& $ilias;
61 
62  $this->import_id = array();
63  $this->title = "";
64  $this->language = array();
65  $this->description = array();
66  $this->keyword = array();
67  $this->technicals = array(); // technical sections
68  $this->coverage = "";
69  $this->structure = "";
70 
71  $this->content_obj =& $content_obj;
72  if(is_object($content_obj))
73  {
74  $this->setID($this->content_obj->getId());
75  $this->readXML();
76 # $this->read();
77  }
78  }
79 
80  // SET METHODS
86  function setBibliographyAttributes($a_data)
87  {
88  $this->bibliography_attr = $a_data;
89  }
90 
98  function setAbstract($a_data)
99  {
100  $this->abstract = $a_data;
101  }
102 
110  function setBibItemData($a_key,$a_value,$a_bib_item_nr)
111  {
112  $this->bib_item_data[$a_bib_item_nr]["$a_key"] = $a_value;
113 
114  return true;
115  }
116 
124  function appendBibItemData($a_key,$a_value,$a_bib_item_nr)
125  {
126  $this->bib_item_data[$a_bib_item_nr]["$a_key"] = array_merge($this->bib_item_data[$a_bib_item_nr]["$a_key"],array($a_value));
127  }
128 
129  // GET MEHODS
130  function getBibItemData()
131  {
132  return $this->bib_item_data;
133  }
134 
141  {
142  return $this->bibliography_attr ? $this->bibliography_attr : array();
143  }
149  function getAbstract()
150  {
151  return $this->abstract;
152  }
153 
161  function getTitle()
162  {
163  return $this->title;
164  }
165 
173  function getXML()
174  {
175  return $this->xml;
176  }
177 
185  function readXML()
186  {
187  if(!$this->__initNestedSet())
188  {
189  return false;
190  }
191  $this->xml = $this->nested_obj->export($this->content_obj->getId(),"bib");
192  }
193 
194 
203  function setXMLContent($a_xml, $a_encoding = "UTF-8")
204  {
205  $this->encoding = $a_encoding;
206  $this->xml = $a_xml;
207  }
208 
209 
216  function appendXMLContent($a_xml)
217  {
218  $this->xml.= $a_xml;
219  }
220 
221 
225  function getXMLContent()/*$a_incl_head = false*/
226  {
227 
228  return $this->xml;
229  }
230 
231  // PRIVATE METHODS
232  function __initNestedSet()
233  {
234  include_once("./Services/Xml/classes/class.ilNestedSetXML.php");
235 
236  $this->nested_obj =& new ilNestedSetXML();
237  $this->nested_obj->init($this->getID(), "bib");
238 
239  return $this->nested_obj->initDom();
240  }
241 
242  function setBooktitle($a_booktitle)
243  {
244  if ($a_booktitle == "")
245  {
246  $a_booktitle = "NO TITLE";
247  }
248 
249  $this->booktitle = $a_booktitle;
250  }
251 
252  function getBooktitle()
253  {
254  return $this->booktitle;
255  }
256 
257  function setEdition($a_edition)
258  {
259  $this->edition = $a_edition;
260  }
261 
262  function getEdition()
263  {
264  return $this->edition;
265  }
266 
267  function setPublisher($a_publisher)
268  {
269  $this->publisher = $a_publisher;
270  }
271 
272  function getPublisher()
273  {
274  return $this->publisher;
275  }
276 
277  function setYear($a_year)
278  {
279  $this->year = $a_year;
280  }
281 
282  function getYear()
283  {
284  return $this->year;
285  }
286 
290  function setMeta($a_data)
291  {
292  $this->meta = $a_data;
293  }
294 
298  function getMeta()
299  {
300  return $this->meta;
301  }
305  function setID($a_id)
306  {
307  $this->id = $a_id;
308  }
309 
310  function getID()
311  {
312  return $this->id;
313  }
314 
315  function setType($a_type)
316  {
317  $this->type = $a_type;
318  }
319 
320  function getType()
321  {
322  return $this->type;
323  }
324 
329  function setElement($a_name, $a_data)
330  {
331  $this->$a_name = $a_data;
332  }
333 
338  function getElement($a_name, $a_path = "", $a_index = 0)
339  {
340  if(!$this->__initNestedSet())
341  {
342  return false;
343  }
344 
345  $p = "//Bibliography";
346  if ($a_path != "")
347  {
348  $p .= "/" . $a_path;
349  }
350  $nodes = $this->nested_obj->getDomContent($p, $a_name, $a_index);
351  $this->setElement($a_name, $nodes);
352 /* if ($a_name == "Author" ||
353  $a_name == "FirstName" ||
354  $a_name == "MiddleName" ||
355  $a_name == "LastName")
356  {
357  echo "Index: " . $a_index . " | Path: " . $p . " | Name: " . $a_name . "<br>\n";
358  vd($this->$a_name);
359  }
360 */
361  return $this->$a_name;
362  }
363 
364  function read()
365  {
366  if(!$this->__initNestedSet())
367  {
368  $bibData = $this->create();
369  }
370  else
371  {
372  $bibData["booktitle"] = $this->nested_obj->getFirstDomContent("//Bibliography/BibItem/Booktitle");
373  $bibData["edition"] = $this->nested_obj->getFirstDomContent("//Bibliography/BibItem/Edition");
374  $bibData["publisher"] = $this->nested_obj->getFirstDomContent("//Bibliography/BibItem/Publisher");
375  $bibData["year"] = $this->nested_obj->getFirstDomContent("//Bibliography/BibItem/Year");
376  }
377 
378  $this->setBooktitle($bibData["booktitle"]);
379  $this->setEdition($bibData["edition"]);
380  $this->setPublisher($bibData["publisher"]);
381  $this->setYear($bibData["year"]);
382  }
383 
387  function create()
388  {
389  $this->__initNestedSet();
390 
391 /* if (is_object($this->obj))
392  {
393  $bibData["booktitle"] = $this->obj->getTitle();
394  }
395  else
396  {*/
397  $bibData["booktitle"] = "NO TITLE";
398 /* }*/
399  $bibData["edition"] = "N/A";
400  $bibData["publisher"] = "";
401  $bibData["year"] = "N/A";
402 
403  $xml = '
404  <Bibliography>
405  <BibItem Type="" Label="">
406  <Identifier Catalog="ILIAS" Entry="il__' . $this->getType() . '_' . $this->getID() . '"></Identifier>
407  <Language Language="' . $this->ilias->account->getLanguage() . '"></Language>
408  <Booktitle Language="' . $this->ilias->account->getLanguage() . '">'. $bibData["booktitle"] . '</Booktitle>
409  <Edition>'. $bibData["edition"] . '</Edition>
410  <HowPublished Type=""></HowPublished>
411  <Publisher>'. $bibData["publisher"] . '</Publisher>
412  <Year>'. $bibData["year"] . '</Year>
413  <URL></URL>
414  </BibItem>
415  </Bibliography>
416  ';
417  $this->nested_obj->import($xml, $this->getID(), "bib");
418 
419  return $bibData;
420  }
421 
425  function delete($a_name, $a_path, $a_index)
426  {
427  if(!$this->__initNestedSet())
428  {
429  return false;
430  }
431 
432  if ($a_name != "")
433  {
434  $p = "//Bibliography";
435  if ($a_path != "")
436  {
437  $p .= "/" . $a_path;
438  }
439  $this->nested_obj->deleteDomNode($p, $a_name, $a_index);
440  $this->nested_obj->updateFromDom();
441  }
442  }
443 
447  function add($a_name, $a_path, $a_index = 0)
448  {
449  if(!$this->__initNestedSet())
450  {
451  return false;
452  }
453 
454  $p = "//Bibliography";
455  if ($a_path != "")
456  {
457  $p .= "/" . $a_path;
458  }
459  $attributes = array();
460 # echo "Index: " . $a_index . " | Path: " . $p . " | Name: " . $a_name . "<br>\n";
461  switch ($a_name)
462  {
463  case "BibItem" : $xml = '
464  <BibItem Type="" Label="">
465  <Identifier Catalog="ILIAS" Entry="il__' . $this->getType() . '_' . $this->getID() . '"></Identifier>
466  <Language Language="' . $this->ilias->account->getLanguage() . '"></Language>
467  <Booktitle Language="' . $this->ilias->account->getLanguage() . '">NO TITLE</Booktitle>
468  <Edition>N/A</Edition>
469  <HowPublished Type=""></HowPublished>
470  <Publisher></Publisher>
471  <Year>N/A</Year>
472  <URL></URL>
473  </BibItem>
474  ';
475  $this->nested_obj->addXMLNode($p, $xml, $a_index);
476  break;
477  case "Identifier" : $value = "";
478  $attributes[0] = array("name" => "Catalog", "value" => "");
479  $attributes[1] = array("name" => "Entry", "value" => "");
480  $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
481  break;
482  case "Keyword" : ;
483  case "Booktitle" : ;
484  case "Language" : $value = "";
485  $attributes[0] = array("name" => "Language", value => $this->ilias->account->getLanguage());
486  $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
487  break;
488  case "Author" : $xml = '
489  <Author>
490  <Lastname></Lastname>
491  </Author>
492  ';
493  $this->nested_obj->addXMLNode($p, $xml, $a_index);
494  break;
495  case "HowPublished" : $value = "";
496  $attributes[0] = array("name" => "Type", value => "");
497  $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
498  break;
499  case "Series" : $xml = '
500  <Series>
501  <SeriesTitle></SeriesTitle>
502  </Series>
503  ';
504  $this->nested_obj->addXMLNode($p, $xml, $a_index);
505  break;
506  default : $value = "";
507  $attributes = "";
508  $this->nested_obj->addDomNode($p, $a_name, $value, $attributes, $a_index);
509  break;
510  }
511  $this->nested_obj->updateFromDom();
512  }
513 
514  function getCountries()
515  {
516  global $lng;
517 
518  $lng->loadLanguageModule("meta");
519 
520  $cntcodes = array ("DE","ES","FR","GB","AT","CH","AF","AL","DZ","AS","AD","AO",
521  "AI","AQ","AG","AR","AM","AW","AU","AT","AZ","BS","BH","BD","BB","BY",
522  "BE","BZ","BJ","BM","BT","BO","BA","BW","BV","BR","IO","BN","BG","BF",
523  "BI","KH","CM","CA","CV","KY","CF","TD","CL","CN","CX","CC","CO","KM",
524  "CG","CK","CR","CI","HR","CU","CY","CZ","DK","DJ","DM","DO","TP","EC",
525  "EG","SV","GQ","ER","EE","ET","FK","FO","FJ","FI","FR","FX","GF","PF",
526  "TF","GA","GM","GE","DE","GH","GI","GR","GL","GD","GP","GU","GT","GN",
527  "GW","GY","HT","HM","HN","HU","IS","IN","ID","IR","IQ","IE","IL","IT",
528  "JM","JP","JO","KZ","KE","KI","KP","KR","KW","KG","LA","LV","LB","LS",
529  "LR","LY","LI","LT","LU","MO","MK","MG","MW","MY","MV","ML","MT","MH",
530  "MQ","MR","MU","YT","MX","FM","MD","MC","MN","MS","MA","MZ","MM","NA",
531  "NR","NP","NL","AN","NC","NZ","NI","NE","NG","NU","NF","MP","NO","OM",
532  "PK","PW","PA","PG","PY","PE","PH","PN","PL","PT","PR","QA","RE","RO",
533  "RU","RW","KN","LC","VC","WS","SM","ST","SA","CH","SN","SC","SL","SG",
534  "SK","SI","SB","SO","ZA","GS","ES","LK","SH","PM","SD","SR","SJ","SZ",
535  "SE","SY","TW","TJ","TZ","TH","TG","TK","TO","TT","TN","TR","TM","TC",
536  "TV","UG","UA","AE","GB","UY","US","UM","UZ","VU","VA","VE","VN","VG",
537  "VI","WF","EH","YE","ZR","ZM","ZW");
538  $cntrs = array();
539  foreach($cntcodes as $cntcode)
540  {
541  $cntrs[$cntcode] = $lng->txt("meta_c_".$cntcode);
542  }
543  asort($cntrs);
544  return $cntrs;
545 
546  }
547 
548  // GENERAL: Language
549  function setLanguage($a_lang)
550  {
551  $this->language = $a_lang;
552  }
553 
554  function getLanguage()
555  {
556  return $this->language;
557  }
558 
563  function getLanguages()
564  {
565  global $lng;
566 
567  $lng->loadLanguageModule("meta");
568 
569  $lngcodes = array("aa","ab","af","am","ar","as","ay","az","ba","be","bg","bh",
570  "bi","bn","bo","br","ca","co","cs","cy","da","de","dz","el","en","eo",
571  "es","et","eu","fa","fi","fj","fo","fr","fy","ga","gd","gl","gn","gu",
572  "ha","he","hi","hr","hu","hy","ia","ie","ik","id","is","it","iu","ja",
573  "jv","ka","kk","kl","km","kn","ko","ks","ku","ky","la","ln","ru","rw",
574  "sa","sd","sg","sh","si","sk","sl","sm","sn","so","sq","sr","ss","st",
575  "su","sv","sw","ta","te","tg","th","ti","tk","tl","tn","to","tr","ts",
576  "tt","tw","ug","uk","ur","uz","vi","vo","wo","xh","yi","yo","za","zh",
577  "zu");
578  $langs = array();
579  foreach($lngcodes as $lngcode)
580  {
581  $langs[$lngcode] = $lng->txt("meta_l_".$lngcode);
582  }
583  asort($langs);
584  return $langs;
585  }
586 
587 }
588 ?>