You are here

public function BiblioEntrezClient::fetchRecords in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/pubmed/EntrezClient.php \BiblioEntrezClient::fetchRecords()
  2. 6 pubmed/EntrezClient.php \BiblioEntrezClient::fetchRecords()
  3. 7.2 modules/pubmed/EntrezClient.php \BiblioEntrezClient::fetchRecords()

Returns up to the maximum number of results starting at $retstart found by the previous search.

In order to return results this method must be called after search. The search method retrieves a web environment and query key from the NCBI server which is used to fetch the results. After setting a new search term the old web environment is deleted and search must be executed again before utilizing this method.

The root element of the returned SimpleXML object is PubmedArticleSet.

Parameters

$retStart: the sequential number of the first record retrieved - default=0 which will retrieve the first record

Return value

SimpleXMLElement

Throws

Exception

See also

Search interface

setReturnMax

2 calls to BiblioEntrezClient::fetchRecords()
BiblioEntrezClient::fetchResult in modules/pubmed/EntrezClient.php
BiblioEntrezClient::fetchSummaries in modules/pubmed/EntrezClient.php

File

modules/pubmed/EntrezClient.php, line 447
Provides Entrez client to retrieve items from the NCBI databases.

Class

BiblioEntrezClient

Code

public function fetchRecords($retStart = 0, $summaries = FALSE) {
  if (is_null($this->webEnvironment)) {
    throw new Exception(t('No web environment set.'));
  }
  $params['WebEnv'] = $this->webEnvironment;
  $params['query_key'] = $this->queryKey;
  $params['retstart'] = $retStart;
  $params['retmax'] = $this
    ->getReturnMax();
  $params['db'] = $this
    ->getDatabase();
  $params['retmode'] = 'xml';
  if (isset($this->dateRange)) {
    $params['mindate'] = $this
      ->getMinDate();
    $params['maxdate'] = $this
      ->getMaxDate();
  }
  if ($summaries) {
    $this->query = self::BASE_URL . 'esummary.fcgi?' . http_build_query($params);
  }
  else {
    $this->query = self::BASE_URL . 'efetch.fcgi?' . http_build_query($params);
  }
  $request_options = array(
    'method' => 'POST',
  );
  $result = drupal_http_request($this->query, $request_options);
  if ($result->code != 200) {
    throw new Exception('Query ' . $this->query . ' failed.');
  }
  $result = @simplexml_load_string($result->data);
  if (isset($result->body->pre->ERROR)) {
    return FALSE;
  }
  return $result;
}