You are here

public function BiblioEntrezClient::count in Bibliography Module 6

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

Returns the number of results for the previously set search terms.

Return value

int

Throws

Exception

File

pubmed/EntrezClient.php, line 359
EntrezClient.php Provides Entrez client to retrieve items from the NCBI databases Orginally writen by Stefan Freudenberg

Class

BiblioEntrezClient
@file EntrezClient.php Provides Entrez client to retrieve items from the NCBI databases Orginally writen by Stefan Freudenberg

Code

public function count() {
  if (is_null($this->count)) {
    $params['tool'] = $this
      ->getTool();
    $params['email'] = $this
      ->getEmail();
    $params['db'] = $this
      ->getDatabase();
    $params['term'] = $this
      ->getTerm();
    $params['rettype'] = 'count';
    if (isset($this->dateRange)) {
      $params['mindate'] = $this
        ->getMinDate();
      $params['maxdate'] = $this
        ->getMaxDate();
    }
    $this->query = self::BASE_URL . 'esearch.fcgi?' . http_build_query($params);
    $result = @simplexml_load_file($this->query);
    if (!$result) {
      throw new Exception('Query ' . $this->query . ' failed.');
    }
    if (isset($result->Count)) {
      $this->count = (int) $result->Count;
    }
  }
  return $this->count;
}