11 changed files with 224 additions and 296 deletions
@ -1,14 +1,18 @@
|
||||
islandora_herbarium_object.graph: |
||||
path: '/islandora_herbarium_object/fdg' |
||||
path: '/islandora_herbarium_object/fdg/{scientificName}/{municipality}' |
||||
defaults: |
||||
_controller: '\Drupal\islandora_herbarium_object\Controller\GraphController::printFdgGraph' |
||||
_title: 'Graph' |
||||
scientificName: '' |
||||
municipality: '' |
||||
requirements: |
||||
_permission: 'access content' |
||||
islandora_herbarium_object.graph-json: |
||||
path: '/islandora_herbarium_object/fdg_json' |
||||
path: '/islandora_herbarium_object/fdg_json/{scientificName}/{municipality}' |
||||
defaults: |
||||
_controller: '\Drupal\islandora_herbarium_object\Controller\GraphController::printFdgData' |
||||
_title: 'Graph Json' |
||||
scientificName: '' |
||||
municipality: '' |
||||
requirements: |
||||
_permission: 'access content' |
||||
|
||||
@ -1,73 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Drupal\islandora_herbarium_object\DataParser; |
||||
|
||||
/** |
||||
* Provides storage and functions for GeoName data. |
||||
*/ |
||||
class GeonamesParser extends XmlDataParser { |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function parseData() { |
||||
$xml_doc = new \DOMDocument(); |
||||
if (empty($xml_doc->loadXML($this->data))) { |
||||
throw new \Exception('Failed loading data as xml'); |
||||
} |
||||
$this->getXmlNodeValue($xml_doc, 'toponymName'); |
||||
$this->getXmlNodeValue($xml_doc, 'name'); |
||||
$this->getXmlNodeValue($xml_doc, 'lat'); |
||||
$this->getXmlNodeValue($xml_doc, 'lng'); |
||||
$this->getXmlNodeValue($xml_doc, 'geonameId'); |
||||
$this->getXmlNodeValue($xml_doc, 'countryCode'); |
||||
$this->getXmlNodeValue($xml_doc, 'countryName'); |
||||
$this->getXmlNodeValue($xml_doc, 'fcodeName'); |
||||
$this->getXmlNodeValue($xml_doc, 'toponymName'); |
||||
$this->getXmlNodeValue($xml_doc, 'population'); |
||||
$this->getXmlNodeValue($xml_doc, 'asciiName'); |
||||
$this->getXmlNodeValue($xml_doc, 'elevation'); |
||||
$this->getXmlNodeValue($xml_doc, 'continentCode'); |
||||
$this->getXmlNodeValue($xml_doc, 'adminName1'); |
||||
$this->getXmlNodeValue($xml_doc, 'timezone'); |
||||
$this->getXmlNodeValue($xml_doc, 'west'); |
||||
$this->getXmlNodeValue($xml_doc, 'north'); |
||||
$this->getXmlNodeValue($xml_doc, 'east'); |
||||
$this->getXmlNodeValue($xml_doc, 'south'); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function updateEntity($entity) { |
||||
try { |
||||
$dwciri = $entity->get("field_dwciri_municipality")->getValue(); |
||||
if (empty($dwciri[0]['value'])) { |
||||
throw new Exception("No URI provided, cannot look up location data."); |
||||
} |
||||
$this->getRemoteData($dwciri[0]['value']); |
||||
$this->parseData(); |
||||
} |
||||
catch (Exception $e) { |
||||
watchdog_exception('islandora_herbarium_object', $e, 'Error getting dwciri'); |
||||
drupal_set_message(t('There was an error retrieving Municipality data. %msg. Verify the url is correct %url', |
||||
['%msg' => $e->getMessage(), '%url' => $dwciri[0]['value']]), 'error'); |
||||
return; |
||||
} |
||||
$entity->set('field_dwc_municipality', $this->getValue('name')); |
||||
$entity->set('field_dwc_countrycode', $this->getValue('countryCode')); |
||||
$entity->set('field_dwc_country', $this->getValue('countryName')); |
||||
$entity->set('field_dwc_continent', $this->getValue('countinentCode')); |
||||
$entity->set('field_dwc_decimallatitude', $this->getValue('lat')); |
||||
$entity->set('field_dwc_decimallongitude', $this->getValue('lng')); |
||||
$entity->set('field_dwc_stateprovince', $this->getValue('adminName1')); |
||||
$point = [ |
||||
'lon' => $this->getValue('lng'), |
||||
'lat' => $this->getValue('lat'), |
||||
]; |
||||
$geo_field_value = \Drupal::service('geofield.wkt_generator') |
||||
->WktBuildPoint($point); |
||||
$entity->set('field_herb_geo_field', $geo_field_value); |
||||
} |
||||
|
||||
} |
||||
@ -1,21 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Drupal\islandora_herbarium_object\DataParser; |
||||
|
||||
/** |
||||
* Provides storage and functions for IPNI data. |
||||
*/ |
||||
abstract class IpniParser extends XmlDataParser { |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function parseData() { |
||||
$xml_doc = new \DOMDocument(); |
||||
$xml_doc->loadXML($this->data); |
||||
$this->getXmlNodeValue($xml_doc, 'nameComplete'); |
||||
$this->getXmlNodeValue($xml_doc, 'genusPart'); |
||||
$this->getXmlNodeValue($xml_doc, 'specificEpithet'); |
||||
} |
||||
|
||||
} |
||||
@ -1,22 +0,0 @@
|
||||
<?php |
||||
|
||||
namespace Drupal\islandora_herbarium_object\DataParser; |
||||
|
||||
/** |
||||
* Provides functions for simple XML data. |
||||
*/ |
||||
abstract class XmlDataParser extends DataParser { |
||||
|
||||
/** |
||||
* Retrieves the value of the first xml node matching element_name. |
||||
* |
||||
* @param \DOMDocument $xml_doc |
||||
* An xml document. |
||||
* @param string $element_name |
||||
* The xml node to lookup. |
||||
*/ |
||||
public function getXmlNodeValue(\DOMDocument $xml_doc, $element_name) { |
||||
$this->dataArray[$element_name] = $xml_doc->getElementsByTagName($element_name)[0]->nodeValue; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,16 @@
|
||||
<?php |
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* User: ppound |
||||
* Date: 2018-06-29 |
||||
* Time: 10:54 AM |
||||
*/ |
||||
|
||||
namespace Drupal\islandora_herbarium_object\Graph; |
||||
|
||||
|
||||
interface GraphInterface { |
||||
|
||||
public function parseData(); |
||||
|
||||
} |
||||
@ -0,0 +1,53 @@
|
||||
<?php |
||||
/** |
||||
* Created by IntelliJ IDEA. |
||||
* User: ppound |
||||
* Date: 2018-06-29 |
||||
* Time: 11:00 AM |
||||
*/ |
||||
|
||||
namespace Drupal\islandora_herbarium_object\Graph; |
||||
|
||||
|
||||
class GraphParser implements GraphInterface { |
||||
|
||||
/** |
||||
* Parse the data retrieved from the triple store for use in a d3 graph. |
||||
* |
||||
* @return string |
||||
* A json encode string. |
||||
*/ |
||||
public function parseData() { |
||||
$jsonArr = json_decode($this->data, TRUE); |
||||
$outputArr = []; |
||||
// $nodes = $links = new \Ds\Set(); |
||||
$outputArr['nodes'] = []; |
||||
$outputArr['links'] = []; |
||||
$idArr = []; |
||||
|
||||
foreach ($jsonArr['results']['bindings'] as $result) { |
||||
if (!array_key_exists($result['municipality']['value'], $idArr)) { |
||||
$outputArr['nodes'][] = [ |
||||
'id' => $result['municipality']['value'], |
||||
'name' => $result['municipality']['value'], |
||||
'uri' => $result['municipalityIRI']['value'], |
||||
'group' => 1, |
||||
]; |
||||
$idArr[$result['municipality']['value']] = ''; |
||||
} |
||||
$outputArr['nodes'][] = [ |
||||
'id' => $result['name']['value'], |
||||
'name' => $result['name']['value'], |
||||
'uri' => $result['scientificNameIRI']['value'], |
||||
'group' => 2, |
||||
]; |
||||
$outputArr['links'][] = [ |
||||
'target' => $result['municipality']['value'], |
||||
'source' => $result['name']['value'], |
||||
'type' => 'found', |
||||
]; |
||||
} |
||||
return json_encode($outputArr); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue