commit | author | age
|
175a52
|
1 |
<?php |
07517a
|
2 |
class ibd_BN implements ibd_module { |
JK |
3 |
public $url = 'http://data.bn.org.pl/api/bibs.json'; |
|
4 |
public $limit = 20; |
|
5 |
|
|
6 |
function szukaj_info($tytul=NULL, $autor=NULL, $wydawnictwo=NULL) { |
|
7 |
$params = []; |
|
8 |
if(!empty($tytul)) { |
|
9 |
$params['title'] = $tytul; |
|
10 |
} |
|
11 |
if(!empty($autor)) { |
|
12 |
$params['author'] = $author; |
|
13 |
} |
|
14 |
if(!empty($wydawnictwo)) { |
|
15 |
$params['publisher'] = $wydawnictwo; |
|
16 |
} |
|
17 |
return $this->query($params); |
|
18 |
} |
|
19 |
|
|
20 |
function szukaj_ISBN($ISBN) { |
|
21 |
$result = $this->query(array( |
|
22 |
'isbnIssn' => $ISBN, |
|
23 |
)); |
|
24 |
if(substr($ISBN, 0, 3) == '978') { |
|
25 |
$result = array_merge( |
|
26 |
$result, |
|
27 |
$this->query(array( |
|
28 |
'isbnIssn' => convert::ISBN13_to_ISBN10( $ISBN ), |
|
29 |
)) |
|
30 |
); |
|
31 |
} |
|
32 |
return $result; |
|
33 |
} |
|
34 |
|
|
35 |
function szukaj_ISSN($ISSN) { |
|
36 |
$result = $this->query(array( |
|
37 |
'isbnIssn' => $ISSN, |
|
38 |
)); |
|
39 |
if(substr($ISSN, 0, 3) == '977') { |
|
40 |
$result = array_merge( |
|
41 |
$result, |
|
42 |
$this->query(array( |
|
43 |
'isbnIssn' => convert::ISSN13_to_ISSN8( $ISSN ) |
|
44 |
)) |
|
45 |
); |
|
46 |
} |
|
47 |
return $result; |
|
48 |
} |
|
49 |
|
|
50 |
protected function query($params) { |
|
51 |
$params['limit'] = $limit; |
|
52 |
$result = file_get_contents($this->url . '?' . http_build_query($params)); |
|
53 |
$result = json_decode($result, TRUE); |
|
54 |
return $this->extractArrays($result); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
protected function convertSubfields($values) { |
|
59 |
$result = array(); |
|
60 |
if(!isset($values['subfields'])) { |
|
61 |
return array(); |
|
62 |
} |
|
63 |
if(isset($values['ind1'])) { |
|
64 |
$result['f0'] = $values['ind1']; |
|
65 |
} |
|
66 |
if(isset($values['ind2'])) { |
|
67 |
$result['f1'] = $values['ind2']; |
|
68 |
} |
|
69 |
foreach($values['subfields'] as $subfield) { |
|
70 |
foreach($subfield as $name => $value) { |
|
71 |
$result[$name] = $value; |
|
72 |
} |
|
73 |
} |
|
74 |
return $result; |
|
75 |
} |
|
76 |
|
|
77 |
protected function convert($entry) { |
|
78 |
$marc = array(); |
|
79 |
if(!isset($entry['marc'])) return NULL; |
|
80 |
if(!isset($entry['marc']['fields'])) return NULL; |
|
81 |
foreach($entry['marc']['fields'] as $fields) { |
|
82 |
foreach($fields as $field => $values) { |
|
83 |
if(!isset($marc[$field])) { |
|
84 |
$marc[$field] = array(); |
|
85 |
} |
|
86 |
$marc[$field][] = $this->convertSubfields($values); |
|
87 |
} |
|
88 |
} |
|
89 |
return $marc; |
|
90 |
} |
|
91 |
|
|
92 |
protected function extractArrays($result) { |
|
93 |
if(!$result) return array(); |
|
94 |
if(!$result['bibs']) return array(); |
|
95 |
|
|
96 |
$return = array(); |
|
97 |
foreach($result['bibs'] as $bib) { |
|
98 |
$marc = $this->convert($bib); |
|
99 |
$return[] = MARC21::to_array($marc); |
|
100 |
} |
|
101 |
return $return; |
175a52
|
102 |
} |
JK |
103 |
} |