Browse Source

Started organising the bibliographic details response from OPS API

main
Simon Bowie 3 years ago
parent
commit
6ed5d292da
2 changed files with 54 additions and 8 deletions
  1. +27
    -6
      site/ops_api.php
  2. +27
    -2
      site/public/index.php

+ 27
- 6
site/ops_api.php View File

$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ops_url); curl_setopt($ch, CURLOPT_URL, $ops_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token", "Accept: application/json"));


// Give back curl result // Give back curl result
$response = curl_exec($ch); $response = curl_exec($ch);
curl_close($ch); curl_close($ch);


if (strpos($response,"No results found") === false ) { if (strpos($response,"No results found") === false ) {
$xml = new SimpleXMLElement($response);


print_r($response);
//var_dump($xml->{'exchange-documents'}->{'exchange-document'}->{'bibliographic-data'}->{'invention-title'}['lang']);
//print_r($xml->xpath('//*'));
//print_r($xml);
// Turn the API response into useful Json
$json = json_decode($response);

// For each invention title, check if it's in the original language
foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'bibliographic-data'}->{'invention-title'} as $invention_title){

if ($invention_title->{'@lang'} === 'ol'){

$output['original_title'] = $invention_title->{'$'};

}

}

// For each abstract, check if it's in the original language
foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'abstract'} as $abstract){

if ($abstract->{'@lang'} === 'ol'){

$output['original_abstract'] = $abstract->p->{'$'};

}

}

return $output;


} }



+ 27
- 2
site/public/index.php View File

?> ?>


<?php <?php
if (get_publication_details($random_record['doc_ref'])):
$publication_details = get_publication_details($random_record['doc_ref']);

if ($publication_details['original_title']):
?> ?>


<br><br>
Original language title:

<?php
echo $publication_details['original_title'];
?>

<br><br>


<?php <?php
endif; endif;
?> ?>


<?php
if ($publication_details['original_abstract']):
?>

Original language abstract:

<?php
echo $publication_details['original_abstract'];
?>

<br><br>

<?php
endif;
?>


<?php <?php
if (check_for_images($random_record['doc_ref'])): if (check_for_images($random_record['doc_ref'])):
?> ?>

Loading…
Cancel
Save