commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
if(!extension_loaded('yaz')) { |
|
3 |
error::add('Brak rozszerzenia YAZ. Wyszukiwanie w bazach Biblioteki Narodowej niemożliwe.'); |
|
4 |
} |
|
5 |
|
|
6 |
class YAZ { |
|
7 |
private static $connection; |
|
8 |
static $timeout = 10; |
|
9 |
|
|
10 |
static function connect($host) { |
|
11 |
self::$connection = yaz_connect($host, array('charset' => 'UTF-8')); |
|
12 |
yaz_syntax(self::$connection, 'marc21'); |
|
13 |
} |
|
14 |
|
|
15 |
static function search($query, $start=1, $num=10) { |
|
16 |
yaz_search(self::$connection, 'rpn', $query); |
|
17 |
yaz_range(self::$connection, $start, $num); |
|
18 |
yaz_wait(); |
|
19 |
self::is_error(); |
|
20 |
} |
|
21 |
|
|
22 |
static function scan($query) { |
|
23 |
yaz_scan(self::$connection, 'rpn', $query); |
|
24 |
yaz_wait(); |
|
25 |
self::is_error(); |
|
26 |
} |
|
27 |
|
|
28 |
static function scan_result() { |
|
29 |
return yaz_scan_result(self::$connection); |
|
30 |
} |
|
31 |
|
|
32 |
static function scan_get($start=1, $num=10) { |
|
33 |
yaz_range(self::$connection, $start, $num); |
|
34 |
yaz_present(self::$connection); |
|
35 |
yaz_wait(); |
|
36 |
self::is_error(); |
|
37 |
} |
|
38 |
|
|
39 |
static function hits() { |
|
40 |
return yaz_hits(self::$connection); |
|
41 |
} |
|
42 |
|
|
43 |
static function return_MARCs() { |
|
44 |
$hits = self::hits(); |
|
45 |
|
|
46 |
$records = array(); |
|
47 |
|
|
48 |
$time = time(); |
|
49 |
|
|
50 |
for($i=1; $i<=$hits; $i++) { |
|
51 |
if($time+self::$timeout <= time()) { |
|
52 |
break; |
|
53 |
} |
|
54 |
$record = yaz_record(self::$connection, $i, 'raw'); |
|
55 |
$records[] = MARC21::from_string($record); |
|
56 |
} |
|
57 |
|
|
58 |
return $records; |
|
59 |
} |
|
60 |
|
|
61 |
static function return_arrays() { |
|
62 |
$return = array(); |
|
63 |
|
|
64 |
$MARCs = self::return_MARCs(); |
|
65 |
|
|
66 |
foreach($MARCs as $MARC) { |
|
67 |
$return[] = MARC21::to_array( $MARC ); |
|
68 |
} |
|
69 |
|
|
70 |
return $return; |
|
71 |
} |
|
72 |
|
|
73 |
static function is_error() { |
|
74 |
if($e = yaz_error(self::$connection)) { |
|
75 |
error::add('Błąd YAZ: '.$e); |
|
76 |
} |
|
77 |
else |
|
78 |
{ |
|
79 |
return FALSE; |
|
80 |
} |
|
81 |
} |
|
82 |
} |
532779
|
83 |
?> |