1
|
|
|
<?php namespace Scriptotek\Sru; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* SearchRetrieve response, containing a list of records or some error |
5
|
|
|
*/ |
6
|
|
|
class SearchRetrieveResponse extends Response implements ResponseInterface |
7
|
|
|
{ |
8
|
|
|
/** @var Record[] Array of records */ |
9
|
|
|
public $records = array(); |
10
|
|
|
|
11
|
|
|
/** @var int Total number of records in the result set */ |
12
|
|
|
public $numberOfRecords = 0; |
13
|
|
|
|
14
|
|
|
/** @var int Position of next record in the result set, or null if no such record exist */ |
15
|
|
|
public $nextRecordPosition = null; |
16
|
|
|
|
17
|
|
|
/** @var string The CQL query used to generate the response */ |
18
|
|
|
public $query = ''; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a new searchRetrieve response |
22
|
|
|
* |
23
|
|
|
* @param string $text Raw XML response |
24
|
|
|
* @param Client $client SRU client reference (optional) |
25
|
|
|
* @param string $url Request URL |
26
|
|
|
*/ |
27
|
|
|
public function __construct($text = null, &$client = null, $url = null) |
28
|
|
|
{ |
29
|
|
|
parent::__construct($text, $client, $url); |
30
|
|
|
|
31
|
|
|
if (is_null($this->response)) { |
32
|
|
|
return; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$this->numberOfRecords = (int) $this->response->text('/srw:searchRetrieveResponse/srw:numberOfRecords'); |
36
|
|
|
$this->nextRecordPosition = (int) $this->response->text('/srw:searchRetrieveResponse/srw:nextRecordPosition') ?: null; |
37
|
|
|
|
38
|
|
|
// The server may echo the request back to the client along with the response |
39
|
|
|
$this->query = $this->response->text('/srw:searchRetrieveResponse/srw:echoedSearchRetrieveRequest/srw:query') ?: null; |
40
|
|
|
|
41
|
|
|
$this->records = array(); |
42
|
|
|
foreach ($this->response->xpath('/srw:searchRetrieveResponse/srw:records/srw:record') as $record) { |
43
|
|
|
$this->records[] = new Record($record); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Request next batch of records in the result set, or return null if we're at the end of the set |
49
|
|
|
* |
50
|
|
|
* @return Response |
51
|
|
|
*/ |
52
|
|
|
public function next() |
53
|
|
|
{ |
54
|
|
|
if (is_null($this->client)) { |
55
|
|
|
throw new \Exception('No client reference passed to response'); |
56
|
|
|
} |
57
|
|
|
if (is_null($this->query)) { |
58
|
|
|
throw new \Exception('No query available'); |
59
|
|
|
} |
60
|
|
|
if (is_null($this->nextRecordPosition)) { |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
return $this->client->search($this->query, $this->nextRecordPosition, count($this->records)); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This method has been deprecated.