From 7e5c02bd1013c1c4d04421c5d11e6b91a7b473a7 Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Mon, 14 Nov 2016 13:53:47 +0100 Subject: [PATCH 1/5] Small translation fix --- app/Tdt/Core/Repositories/DcatRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Tdt/Core/Repositories/DcatRepository.php b/app/Tdt/Core/Repositories/DcatRepository.php index 78fa2264..12e7ffe5 100644 --- a/app/Tdt/Core/Repositories/DcatRepository.php +++ b/app/Tdt/Core/Repositories/DcatRepository.php @@ -187,7 +187,7 @@ public function getDcatDocument(array $definitions, $oldest_definition) $vcard->setType('vcard:Kind'); $vcard->addLiteral('vcard:fn', $attribution['name']); - $vcard->addResource('vcard:hasEmail', 'mailto:' . $attribution['email']); + $vcard->addResource('vcard:hasEmail', $attribution['email']); $attribution_node->addResource('prov:Agent', $vcard); $attribution_node->addResource('dc:type', 'http://inspire.ec.europa.eu/metadata-codelist/ResponsiblePartyRole/' . $attribution['role']); From 1326919f9ff3d2fbba7d5523df882a3b49e4a1db Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Wed, 16 Nov 2016 14:51:32 +0100 Subject: [PATCH 2/5] TDT is PHP7 ready, found a replacement for the PHP7 abandoned function dbase_open() on which the previous SHP library relied --- .../Core/DataControllers/SHPController.php | 68 +++--- .../Core/Definitions/DefinitionController.php | 2 +- app/lang/en/parameters.php | 2 +- composer.json | 2 +- composer.lock | 196 +++++++++++------- 5 files changed, 164 insertions(+), 106 deletions(-) diff --git a/app/Tdt/Core/DataControllers/SHPController.php b/app/Tdt/Core/DataControllers/SHPController.php index a9ce04d9..8f34deb1 100644 --- a/app/Tdt/Core/DataControllers/SHPController.php +++ b/app/Tdt/Core/DataControllers/SHPController.php @@ -17,7 +17,7 @@ use Tdt\Core\Pager; use Tdt\Core\Repositories\Interfaces\TabularColumnsRepositoryInterface; use Tdt\Core\Repositories\Interfaces\GeoPropertyRepositoryInterface; -use muka\ShapeReader\ShapeReader; +use ShapeFile\ShapeFile; use Tdt\Core\Repositories\Interfaces\GeoprojectionRepositoryInterface; class SHPController extends ADataController @@ -98,8 +98,6 @@ public function readData($source_definition, $rest_parameters = array()) $arrayOfRowObjects = array(); // Prepare the options to read the SHP file - $options = array('noparts' => false); - $is_url = (substr($uri, 0, 4) == "http"); // If the shape files are located on an HTTP address, fetch them and store them locally @@ -112,34 +110,36 @@ public function readData($source_definition, $rest_parameters = array()) file_put_contents($tmp_file . ".shx", file_get_contents(substr($uri, 0, strlen($uri) - 4) . ".shx")); // Along this file the class will use file.shx and file.dbf - $shp = new ShapeReader($tmp_file . ".shp", $options); + $shape_file = new ShapeFile($tmp_file . ".shp"); } else { - $shp = new ShapeReader($uri, $options); // along this file the class will use file.shx and file.dbf + $shape_file = new ShapeFile($uri); // along this file the class will use file.shx and file.dbf } // Keep track of the total amount of rows $total_rows = 0; // Get the shape records in the binary file - while ($record = $shp->getNext()) { + while ($record = $shape_file->getRecord()) { if ($offset <= $total_rows && $offset + $limit > $total_rows) { // Every shape record is parsed as an anonymous object with the properties attached to it $rowobject = new \stdClass(); // Get the dBASE data - $dbf_data = $record->getDbfData(); + $dbf_data = $record['dbf']; foreach ($dbf_data as $property => $value) { - $property_alias = $columns[$property]; - $property = trim($property); - $property_alias = $columns[$property]; - $rowobject->$property_alias = trim($value); + if (array_key_exists($property, $columns)) { + $property_alias = $columns[$property]; + $property = trim($property); + $property_alias = $columns[$property]; + $rowobject->$property_alias = trim($value); + } } // Read the shape data - $shp_data = $record->getShpData(); + $shp_data = $record['shp']; - $shape_type = self::$RECORD_TYPES[$record->getTypeCode()]; + $shape_type = self::$RECORD_TYPES[$shape_file->getShapeType()]; // Get the projection code $projection = $this->projections->getByCode($this->epsg); @@ -154,8 +154,6 @@ public function readData($source_definition, $rest_parameters = array()) $this->projSrc = new Proj('EPSG:' . $this->epsg, $this->proj4); $this->projDest = new Proj('EPSG:4326', $this->proj4); - $geometry = []; - switch (strtolower($shape_type)) { case 'point': $point = $this->parsePoint($shp_data); @@ -326,11 +324,14 @@ private function parsePolygon($shp_data) foreach ($shp_data['parts'] as $part) { $points = array(); - foreach ($part['points'] as $point) { + // We don't support multi-ring polygon + $first_ring_points = array_shift($part['rings']); + + foreach ($first_ring_points['points'] as $point) { $x = $point['x']; $y = $point['y']; - // Translate the coordinates to WSG84 geo coordinates + // Translate the coordinates to WSG84 geo coordinates if (!empty($this->epsg)) { $pointSrc = new Point($x, $y); @@ -341,6 +342,7 @@ private function parsePolygon($shp_data) $points[] = $x . ',' . $y; } + array_push($parts, implode(" ", $points)); } @@ -354,7 +356,10 @@ private function parsePolygonZ($shp_data) foreach ($shp_data['parts'] as $part) { $points = array(); - foreach ($part['points'] as $point) { + // We don't support multi-ring polygon + $first_ring_points = array_shift($part['rings']); + + foreach ($first_ring_points['points'] as $point) { $x = $point['x']; $y = $point['y']; $z = $point['z']; @@ -446,16 +451,16 @@ public static function parseColumns($options) file_put_contents($tmp_dir . '/' . $tmp_file . ".shx", file_get_contents(substr($options['uri'], 0, strlen($options['uri']) - 4) . ".shx")); // Along this file the class will use file.shx and file.dbf - $shp = new ShapeReader($tmp_dir . '/' . $tmp_file . ".shp", array('noparts' => false)); + $shape_file = new Shapefile($tmp_dir . '/' . $tmp_file . ".shp", array('noparts' => false)); } else { // along this file the class will use file.shx and file.dbf - $shp = new ShapeReader($options['uri'], array('noparts' => false)); + $shape_file = new Shapefile($options['uri'], array('noparts' => false)); } } catch (Exception $e) { \App::abort(400, "The shape contents couldn't be retrieved, make sure the shape file is valid, zipped shape files are not yet supported."); } - $record = $shp->getNext(); + $record = $shape_file->getRecord(); // Read meta data if (!$record) { @@ -464,7 +469,7 @@ public static function parseColumns($options) } // Get the dBASE fields - $dbf_fields = $record->getDbfData(); + $dbf_fields = $record['dbf']; $column_index = 0; @@ -476,7 +481,7 @@ public static function parseColumns($options) $column_index++; } - $shape_type = self::$RECORD_TYPES[$record->getTypeCode()]; + $shape_type = self::$RECORD_TYPES[$shape_file->getShapeType()]; // Get the geographical column names switch (strtolower($shape_type)) { @@ -536,12 +541,12 @@ public static function parseGeoProperty($options, $columns) file_put_contents($tmp_dir . '/' . $tmp_file . ".dbf", file_get_contents(substr($options['uri'], 0, strlen($options['uri']) - 4) . ".dbf")); file_put_contents($tmp_dir . '/' . $tmp_file . ".shx", file_get_contents(substr($options['uri'], 0, strlen($options['uri']) - 4) . ".shx")); - $shp = new ShapeReader($tmp_dir . '/' . $tmp_file . ".shp", array('noparts' => false)); + $shape_file = new ShapeFile($tmp_dir . '/' . $tmp_file . ".shp", array('noparts' => false)); } else { - $shp = new ShapeReader($options['uri'], array('noparts' => false)); + $shape_file = new ShapeFile($options['uri'], array('noparts' => false)); } - $record = $shp->getNext(); + $record = $shape_file->getRecord(); // read meta data if (!$record) { @@ -549,17 +554,14 @@ public static function parseGeoProperty($options, $columns) \App::abort(400, "We failed to retrieve a record from the provided shape file on uri $uri, make sure the corresponding dbf and shx files are at the same location."); } - $shp_data = $record->getShpData(); - - $geo_properties = array(); - - // Get the geographical column names // Either multiple coordinates will be set (identified by the parts) // or a lat long pair will be set (identified by x and y) - $shp_data = $record->getShpData(); + $shp_data = $record['shp']; + + $geo_properties = array(); - $shape_type = self::$RECORD_TYPES[$record->getTypeCode()]; + $shape_type = self::$RECORD_TYPES[$shape_file->getShapeType()]; switch (strtolower($shape_type)) { case 'point': diff --git a/app/Tdt/Core/Definitions/DefinitionController.php b/app/Tdt/Core/Definitions/DefinitionController.php index 4a309d1c..39fd7a88 100644 --- a/app/Tdt/Core/Definitions/DefinitionController.php +++ b/app/Tdt/Core/Definitions/DefinitionController.php @@ -53,7 +53,7 @@ public function put($uri) if ($validator->fails()) { $message = $validator->messages()->first(); - \Log::info($message); + \App::abort(400, $message); } diff --git a/app/lang/en/parameters.php b/app/lang/en/parameters.php index fe74c013..5e7b39c9 100644 --- a/app/lang/en/parameters.php +++ b/app/lang/en/parameters.php @@ -25,7 +25,7 @@ 'definition_date_desc' => 'A date associated with the dataset.', 'definition_language' => 'Language', 'definition_language_desc' => 'A language of the resource.', - 'definition_rights' => 'Rights', + 'definition_rights' => 'License', 'definition_rights_description' => 'Information about rights held in and over the resource.', 'definition_theme' => 'Theme', 'definition_theme_description' => 'The theme or category that the dataset belongs to.', diff --git a/composer.json b/composer.json index d0ea44f0..88e52dd8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "willdurand/negotiation" : "1.3.2", "coreation/gisconverter" : "dev-master", "proj4php/proj4php" : "dev-inline-projections#89722067010a4c88b7c4c79a7ee187bb2ddb1b61", - "muka/shape-reader" : "dev-master", + "coreation/php-shapefile" : "dev-master", "elasticsearch/elasticsearch": "1.4.1", "nesbot/carbon": "~1.14", "phayes/geophp" : "dev-master", diff --git a/composer.lock b/composer.lock index b3b1284f..31f98630 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "1006b102fe40a9ced5fa640429123268", - "content-hash": "4fb6334d2fa9f8cbb9ddf5c979a396c6", + "hash": "26c62e3a8bb2b998e4510d3884cb2d39", + "content-hash": "3e724b5b7bac21fc8f27553c28aba7d9", "packages": [ { "name": "cartalyst/sentry", @@ -192,6 +192,52 @@ "description": "A php library to convert vector geometries between different formats", "time": "2015-05-18 17:01:06" }, + { + "name": "coreation/php-shapefile", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/coreation/php-shapefile.git", + "reference": "0a4e3af8609817dc02b702d1e7d8f9782182f1b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/coreation/php-shapefile/zipball/0a4e3af8609817dc02b702d1e7d8f9782182f1b3", + "reference": "0a4e3af8609817dc02b702d1e7d8f9782182f1b3", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ShapeFile\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gaspare Sganga", + "email": "contact@gasparesganga.com", + "homepage": "http://gasparesganga.com", + "role": "Developer" + } + ], + "description": "PHP library to read any ESRI Shapefile and its associated DBF into a PHP Array or WKT", + "homepage": "http://gasparesganga.com/labs/php-shapefile/", + "keywords": [ + "ESRI", + "Shapefile", + "dbf", + "shape", + "shp" + ], + "time": "2016-11-16 12:54:14" + }, { "name": "d11wtq/boris", "version": "v1.0.10", @@ -501,6 +547,7 @@ "rest", "web service" ], + "abandoned": "guzzlehttp/guzzle", "time": "2015-03-18 18:23:50" }, { @@ -807,17 +854,17 @@ }, { "name": "ml/json-ld", - "version": "1.0.5", + "version": "1.0.7", "target-dir": "ML/JsonLD", "source": { "type": "git", "url": "https://github.com/lanthaler/JsonLD.git", - "reference": "2f7f00a9daed844289135cc1cc99a75fc72a5438" + "reference": "f9dfe184f0da9ce0e0ffdddabf6d93d01787ac91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/lanthaler/JsonLD/zipball/2f7f00a9daed844289135cc1cc99a75fc72a5438", - "reference": "2f7f00a9daed844289135cc1cc99a75fc72a5438", + "url": "https://api.github.com/repos/lanthaler/JsonLD/zipball/f9dfe184f0da9ce0e0ffdddabf6d93d01787ac91", + "reference": "f9dfe184f0da9ce0e0ffdddabf6d93d01787ac91", "shasum": "" }, "require": { @@ -852,20 +899,20 @@ "JSON-LD", "jsonld" ], - "time": "2016-01-17 17:39:22" + "time": "2016-10-10 08:57:56" }, { "name": "monolog/monolog", - "version": "1.19.0", + "version": "1.21.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "5f56ed5212dc509c8dc8caeba2715732abb32dbf" + "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/5f56ed5212dc509c8dc8caeba2715732abb32dbf", - "reference": "5f56ed5212dc509c8dc8caeba2715732abb32dbf", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/f42fbdfd53e306bda545845e4dbfd3e72edb4952", + "reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952", "shasum": "" }, "require": { @@ -884,8 +931,8 @@ "php-console/php-console": "^3.1.3", "phpunit/phpunit": "~4.5", "phpunit/phpunit-mock-objects": "2.3.0", - "raven/raven": "^0.13", "ruflin/elastica": ">=0.90 <3.0", + "sentry/sentry": "^0.13", "swiftmailer/swiftmailer": "~5.3" }, "suggest": { @@ -897,9 +944,9 @@ "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", "php-console/php-console": "Allow sending log messages to Google Chrome", - "raven/raven": "Allow sending log messages to a Sentry server", "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server" + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "sentry/sentry": "Allow sending log messages to a Sentry server" }, "type": "library", "extra": { @@ -930,7 +977,7 @@ "logging", "psr-3" ], - "time": "2016-04-12 18:29:35" + "time": "2016-07-29 03:23:52" }, { "name": "muka/shape-reader", @@ -938,12 +985,12 @@ "source": { "type": "git", "url": "https://github.com/muka/ShapeReader.git", - "reference": "c71d16bd010498b1dca67100042e33854d2fd7e7" + "reference": "e1a1569d927f7d8e1f5cc0acfb7a7c4481180625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/muka/ShapeReader/zipball/c71d16bd010498b1dca67100042e33854d2fd7e7", - "reference": "c71d16bd010498b1dca67100042e33854d2fd7e7", + "url": "https://api.github.com/repos/muka/ShapeReader/zipball/e1a1569d927f7d8e1f5cc0acfb7a7c4481180625", + "reference": "e1a1569d927f7d8e1f5cc0acfb7a7c4481180625", "shasum": "" }, "require": { @@ -984,7 +1031,7 @@ "geospatial", "shp" ], - "time": "2015-11-17 12:48:18" + "time": "2016-07-20 08:44:36" }, { "name": "neitanod/forceutf8", @@ -1589,16 +1636,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.4.8", + "version": "1.4.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", "shasum": "" }, "require": { @@ -1634,7 +1681,7 @@ "keywords": [ "tokenizer" ], - "time": "2015-09-15 10:49:45" + "time": "2016-11-15 14:06:22" }, { "name": "phpunit/phpunit", @@ -1874,7 +1921,7 @@ }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/proj4php/proj4php/zipball/41c1e753e02c44d6b6e68844f62ae36f9149897d", + "url": "https://api.github.com/repos/proj4php/proj4php/zipball/89722067010a4c88b7c4c79a7ee187bb2ddb1b61", "reference": "89722067010a4c88b7c4c79a7ee187bb2ddb1b61", "shasum": "" }, @@ -1920,22 +1967,30 @@ }, { "name": "psr/log", - "version": "1.0.0", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", "shasum": "" }, + "require": { + "php": ">=5.3.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "psr-0": { - "Psr\\Log\\": "" + "psr-4": { + "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1949,12 +2004,13 @@ } ], "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", "keywords": [ "log", "psr", "psr-3" ], - "time": "2012-12-21 11:40:51" + "time": "2016-10-10 12:19:37" }, { "name": "ruflin/elastica", @@ -2067,23 +2123,23 @@ }, { "name": "sebastian/environment", - "version": "1.3.7", + "version": "1.3.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716" + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4e8f0da10ac5802913afc151413bc8c53b6c2716", - "reference": "4e8f0da10ac5802913afc151413bc8c53b6c2716", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^4.8 || ^5.0" }, "type": "library", "extra": { @@ -2113,7 +2169,7 @@ "environment", "hhvm" ], - "time": "2016-05-17 03:18:57" + "time": "2016-08-18 05:49:44" }, { "name": "sebastian/exporter", @@ -2266,23 +2322,23 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.2", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "d8db871a54619458a805229a057ea2af33c753e8" + "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8", - "reference": "d8db871a54619458a805229a057ea2af33c753e8", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", + "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "mockery/mockery": "~0.9.1,<0.9.4" + "mockery/mockery": "~0.9.1" }, "type": "library", "extra": { @@ -2315,7 +2371,7 @@ "mail", "mailer" ], - "time": "2016-05-01 08:45:47" + "time": "2016-07-08 11:51:25" }, { "name": "symfony/browser-kit", @@ -2592,16 +2648,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.7", + "version": "v2.8.13", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110" + "reference": "25c576abd4e0f212e678fe8b2bd9a9a98c7ea934" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2a6b8713f8bdb582058cfda463527f195b066110", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/25c576abd4e0f212e678fe8b2bd9a9a98c7ea934", + "reference": "25c576abd4e0f212e678fe8b2bd9a9a98c7ea934", "shasum": "" }, "require": { @@ -2648,20 +2704,20 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2016-10-13 01:43:15" }, { "name": "symfony/filesystem", - "version": "v2.8.7", + "version": "v2.8.13", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "dee379131dceed90a429e951546b33edfe7dccbb" + "reference": "a3784111af9f95f102b6411548376e1ae7c93898" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/dee379131dceed90a429e951546b33edfe7dccbb", - "reference": "dee379131dceed90a429e951546b33edfe7dccbb", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/a3784111af9f95f102b6411548376e1ae7c93898", + "reference": "a3784111af9f95f102b6411548376e1ae7c93898", "shasum": "" }, "require": { @@ -2697,7 +2753,7 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2016-04-12 18:01:21" + "time": "2016-10-18 04:28:30" }, { "name": "symfony/finder", @@ -3109,16 +3165,16 @@ }, { "name": "symfony/yaml", - "version": "v2.8.7", + "version": "v2.8.13", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34" + "reference": "396784cd06b91f3db576f248f2402d547a077787" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/815fabf3f48c7d1df345a69d1ad1a88f59757b34", - "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34", + "url": "https://api.github.com/repos/symfony/yaml/zipball/396784cd06b91f3db576f248f2402d547a077787", + "reference": "396784cd06b91f3db576f248f2402d547a077787", "shasum": "" }, "require": { @@ -3154,7 +3210,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2016-10-21 20:59:10" }, { "name": "tdt/input", @@ -3162,12 +3218,12 @@ "source": { "type": "git", "url": "https://github.com/tdt/input.git", - "reference": "38ca6ec055c9b9580357344e952b63d911195abd" + "reference": "fe2155d6972681f3e983f29f0e3f9af141d6bac6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tdt/input/zipball/38ca6ec055c9b9580357344e952b63d911195abd", - "reference": "38ca6ec055c9b9580357344e952b63d911195abd", + "url": "https://api.github.com/repos/tdt/input/zipball/fe2155d6972681f3e983f29f0e3f9af141d6bac6", + "reference": "fe2155d6972681f3e983f29f0e3f9af141d6bac6", "shasum": "" }, "require": { @@ -3206,7 +3262,7 @@ } }, "notification-url": "https://packagist.org/downloads/", - "time": "2016-06-18 13:25:32" + "time": "2016-10-01 09:34:38" }, { "name": "tdt/json", @@ -3348,16 +3404,16 @@ "source": { "type": "git", "url": "https://github.com/padraic/mockery.git", - "reference": "ec1ca8266d9f8220cb0f90bbb84735137d180c90" + "reference": "8569c87a009c2858884ed1e3ae5e5700035aff7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/padraic/mockery/zipball/ec1ca8266d9f8220cb0f90bbb84735137d180c90", - "reference": "ec1ca8266d9f8220cb0f90bbb84735137d180c90", + "url": "https://api.github.com/repos/padraic/mockery/zipball/8569c87a009c2858884ed1e3ae5e5700035aff7b", + "reference": "8569c87a009c2858884ed1e3ae5e5700035aff7b", "shasum": "" }, "require": { - "hamcrest/hamcrest-php": "^2.0@dev", + "hamcrest/hamcrest-php": "~2.0", "lib-pcre": ">=7.0", "php": ">=5.4.0" }, @@ -3405,7 +3461,7 @@ "test double", "testing" ], - "time": "2016-06-02 10:51:58" + "time": "2016-10-27 15:37:22" } ], "aliases": [], @@ -3414,7 +3470,7 @@ "easyrdf/easyrdf": 20, "coreation/gisconverter": 20, "proj4php/proj4php": 20, - "muka/shape-reader": 20, + "coreation/php-shapefile": 20, "phayes/geophp": 20, "tdt/input": 20, "mockery/mockery": 20 From d388cf44cc64f8c2e0d14c4dd7e141ee7a333152 Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Sat, 19 Nov 2016 17:13:25 +0100 Subject: [PATCH 3/5] Update on flemish open data licenses --- app/database/seeds/data/licenses.json | 52 +++++++++++++++++---------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/app/database/seeds/data/licenses.json b/app/database/seeds/data/licenses.json index 650e4d5a..7921badc 100644 --- a/app/database/seeds/data/licenses.json +++ b/app/database/seeds/data/licenses.json @@ -104,18 +104,20 @@ "title": "GNU Free Documentation License", "url": "http://www.opendefinition.org/licenses/gfdl" }, + { "domain_content": true, "domain_data": false, "domain_software": false, "family": "", - "license_id": "gfdl", + "license_id": "other-open", + "is_generic": true, "is_okd_compliant": true, "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 2 - Gratis Open Data Licentie - v1.0", - "url": "http://opendataforum.info/Docs/LICENTIES_2014/Modellicentie 2 - Gratis Open Data Licentie - v1.0.htm" + "title": "CC0 1.0 Universal", + "url": "http://creativecommons.org/publicdomain/zero/1.0/legalcode" }, { "domain_content": true, @@ -128,8 +130,8 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "CC0 1.0 Universal", - "url": "http://creativecommons.org/publicdomain/zero/1.0/legalcode" + "title": "Modellicentie 2 - Gratis Open Data Licentie - v1.2", + "url": "http://overheid.vlaanderen.be/opendata/licenties/v1-2/html/gratis-open-data-licentie" }, { "domain_content": true, @@ -142,8 +144,8 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 2 - Gratis Open Data Licentie - v1.2 Universal", - "url": "http://id.vlaanderen.be/licentie/gratis-open-data-licentie#id" + "title": "Modellicentie 4a - Gratis Open Data Licentie voor Niet-Commercieel Hergebruik - v1.2", + "url": "http://overheid.vlaanderen.be/opendata/licenties/v1-2/html/gratis-open-data-licentie-voor-niet-commercieel-hergebruik" }, { "domain_content": true, @@ -156,8 +158,8 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 4a+4b - Gratis Open Data Licentie voor Niet-Commercieel Hergebruik en Open Data Licentie voor Commercieel Hergebruik - v1.0", - "url": "http://opendataforum.info/Docs/LICENTIES_2014/Modellicentie 4a 4b - Gratis Open Data Licentie voor Niet-Commercieel Hergebruik en OpenData Licentie voor Commercieel Hergebruik - v1.0.htm" + "title": "Open Data Licentie tegen Billijke Vergoeding voor Commercieel Hergebruik", + "url": "http://overheid.vlaanderen.be/opendata/licenties/v1-2/html/open-data-licentie-tegen-billijke-vergoeding-voor-commercieel_hergebruik" }, { "domain_content": true, @@ -170,10 +172,10 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 4a+4b - Gratis Open Data Licentie voor Niet-Commercieel Hergebruik en Open Data Licentie voor Commercieel Hergebruik - v1.2", - "url": "http://opendataforum.info/Docs/licenties/BV.htm" + "title": "Open Data Licentie tegen Billijke Vergoeding", + "url": "http://overheid.vlaanderen.be/opendata/licenties/v1-2/html/open-data-licentie-tegen-billijke-vergoeding" }, - { + { "domain_content": true, "domain_data": false, "domain_software": false, @@ -184,10 +186,24 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 3 - Open Data Licentie tegen Billijke Vergoeding - v1.0", - "url": "http://opendataforum.info/Docs/LICENTIES_2014/Modellicentie%203%20-%20Open%20Data%20Licentie%20tegen%20Billijke%20Vergoeding%20-%20v1.0.htm" + "title": "Modellicentie Hergebruik Tegen Vergoeding", + "url": "http://overheid.vlaanderen.be/hergebruik/licenties/v1-0/html/modellicentie-hergebruik-tegen-vergoeding" }, - { + { + "domain_content": true, + "domain_data": false, + "domain_software": false, + "family": "", + "license_id": "other-open", + "is_generic": true, + "is_okd_compliant": true, + "is_osi_compliant": false, + "maintainer": "", + "status": "active", + "title": "Modellicentie Gratis Hergebruik - v1.0", + "url": "http://overheid.vlaanderen.be/hergebruik/licenties/v1-0/html/modellicentie-gratis-hergebruik" + }, + { "domain_content": true, "domain_data": false, "domain_software": false, @@ -198,8 +214,8 @@ "is_osi_compliant": false, "maintainer": "", "status": "active", - "title": "Modellicentie 3 - Open Data Licentie tegen Billijke Vergoeding - v1.2", - "url": "http://id.vlaanderen.be/licentie/open-data-licentie-tegen-billijke-vergoeding#id" + "title": "Modellicentie 1 - CC0-verklaring", + "url": "http://overheid.vlaanderen.be/hergebruik/licenties/v1-0/html/cc0" }, { "domain_content": true, @@ -297,4 +313,4 @@ "title": "Other (Not Open)", "url": "" } -] \ No newline at end of file +] From a13655bc48884c22cdacf20d407cb4596eb85f52 Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Sat, 19 Nov 2016 17:51:20 +0100 Subject: [PATCH 4/5] Small textual tweak --- app/Tdt/Core/Repositories/DefinitionRepository.php | 2 +- app/database/seeds/DcatSeeder.php | 10 +++++----- app/database/seeds/data/licenses.json | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Tdt/Core/Repositories/DefinitionRepository.php b/app/Tdt/Core/Repositories/DefinitionRepository.php index 46e9e314..dcb84646 100644 --- a/app/Tdt/Core/Repositories/DefinitionRepository.php +++ b/app/Tdt/Core/Repositories/DefinitionRepository.php @@ -763,7 +763,7 @@ public function getCreateParameters() 'rights' => array( 'required' => false, 'requiredgeodcat' => 'required', - 'name' => 'Rights', + 'name' => 'License', 'type' => 'list', 'list' => 'api/licenses', 'list_option' => 'title', diff --git a/app/database/seeds/DcatSeeder.php b/app/database/seeds/DcatSeeder.php index 86cfeb03..a8eb28a3 100644 --- a/app/database/seeds/DcatSeeder.php +++ b/app/database/seeds/DcatSeeder.php @@ -75,9 +75,9 @@ private function seedLanguages() foreach ($languages as $language) { \Language::create(array( 'lang_id' => $language->lang_id, - 'lang_code' =>$language->lang_code, + 'lang_code' => $language->lang_code, 'name' => $language->name, - )); + )); } $this->command->info('Added the languages from a local json file.'); @@ -132,7 +132,7 @@ private function seedThemes() \Theme::create(array( 'uri' => $theme_uri, 'label' => $label - )); + )); } } } @@ -159,7 +159,7 @@ private function seedThemes() \Theme::create(array( 'uri' => $theme->uri, 'label' => $theme->label, - )); + )); } if (!empty($themes)) { @@ -188,7 +188,7 @@ private function seedGeoProjections() foreach ($geoprojections as $language) { \Geoprojection::create(array( 'epsg' => $language->epsg, - 'projection' =>$language->projection, + 'projection' => $language->projection, )); } diff --git a/app/database/seeds/data/licenses.json b/app/database/seeds/data/licenses.json index 7921badc..7a4b0a59 100644 --- a/app/database/seeds/data/licenses.json +++ b/app/database/seeds/data/licenses.json @@ -104,7 +104,6 @@ "title": "GNU Free Documentation License", "url": "http://www.opendefinition.org/licenses/gfdl" }, - { "domain_content": true, "domain_data": false, @@ -161,7 +160,7 @@ "title": "Open Data Licentie tegen Billijke Vergoeding voor Commercieel Hergebruik", "url": "http://overheid.vlaanderen.be/opendata/licenties/v1-2/html/open-data-licentie-tegen-billijke-vergoeding-voor-commercieel_hergebruik" }, - { + { "domain_content": true, "domain_data": false, "domain_software": false, From 72aec5eed7a219f1c741cd89cfc8df156bff5ece Mon Sep 17 00:00:00 2001 From: Jan Vansteenlandt Date: Sat, 24 Dec 2016 13:44:22 +0100 Subject: [PATCH 5/5] Allow for xml or other semantic compatible formats to be request on the dcat --- app/Tdt/Core/ApiController.php | 25 ++++--- app/Tdt/Core/BaseController.php | 43 +++++++++++- app/Tdt/Core/Controller.php | 40 ++++++++++++ app/Tdt/Core/Datasets/DatasetController.php | 66 +++++-------------- app/Tdt/Core/Definitions/DcatController.php | 20 ++++-- app/Tdt/Core/HomeController.php | 2 +- app/Tdt/Core/Repositories/DcatRepository.php | 69 ++++++++++---------- 7 files changed, 156 insertions(+), 109 deletions(-) create mode 100644 app/Tdt/Core/Controller.php diff --git a/app/Tdt/Core/ApiController.php b/app/Tdt/Core/ApiController.php index d55ae26d..8d021d1b 100644 --- a/app/Tdt/Core/ApiController.php +++ b/app/Tdt/Core/ApiController.php @@ -11,7 +11,7 @@ * @license AGPLv3 * @author Jan Vansteenlandt */ -abstract class ApiController extends \Controller +abstract class ApiController extends Controller { protected $definition; @@ -23,27 +23,26 @@ public function __construct(DefinitionRepositoryInterface $definition) public function handle($uri) { - $uri = ltrim($uri, '/'); // Delegate the request based on the used http method $method = \Request::getMethod(); switch ($method) { - case "PUT": + case 'PUT': return $this->put($uri); break; - case "GET": + case 'GET': return $this->get($uri); break; - case "POST": - case "PATCH": + case 'POST': + case 'PATCH': return $this->patch($uri); break; - case "DELETE": + case 'DELETE': return $this->delete($uri); break; - case "HEAD": + case 'HEAD': return $this->head($uri); break; default: @@ -55,26 +54,26 @@ public function handle($uri) public function get($uri) { - \App::abort(405, "The HTTP method GET is not supported by this resource."); + \App::abort(405, 'The HTTP method GET is not supported by this resource.'); } public function put($uri) { - \App::abort(405, "The HTTP method PUT is not supported by this resource."); + \App::abort(405, 'The HTTP method PUT is not supported by this resource.'); } public function patch($uri) { - \App::abort(405, "The HTTP method PATCH is not supported by this resource."); + \App::abort(405, 'The HTTP method PATCH is not supported by this resource.'); } public function head($uri) { - \App::abort(405, "The HTTP method HEAD is not supported by this resource."); + \App::abort(405, 'The HTTP method HEAD is not supported by this resource.'); } public function delete($uri) { - \App::abort(405, "The HTTP method DELETE is not supported by this resource."); + \App::abort(405, 'The HTTP method DELETE is not supported by this resource.'); } } diff --git a/app/Tdt/Core/BaseController.php b/app/Tdt/Core/BaseController.php index 29e6545d..2e6694e3 100644 --- a/app/Tdt/Core/BaseController.php +++ b/app/Tdt/Core/BaseController.php @@ -9,7 +9,7 @@ * @license AGPLv3 * @author Michiel Vancoillie */ -class BaseController extends \Controller +class BaseController extends Controller { /* * Handles all core requests @@ -29,7 +29,10 @@ public function handleRequest($uri) $controller = 'Tdt\\Core\\Definitions\\DiscoveryController'; break; case 'api': - switch (\Request::segment(2)) { + // Allow for content negotiation for api endpoints + list($apiResource, $extension) = self::processURI(\Request::segment(2)); + + switch ($apiResource) { case 'definitions': // Definitions request $controller = 'Tdt\\Core\\Definitions\\DefinitionController'; @@ -74,7 +77,7 @@ public function handleRequest($uri) $uri = str_replace('api/keywords', '', $uri); break; default: - \App::abort(404, "Page not found."); + \App::abort(404, 'Page not found.'); break; } @@ -107,4 +110,38 @@ public function handleRequest($uri) return $response; } } + + /** + * Process the URI and return the extension (=format) and the resource identifier URI + * + * @param string $uri The URI that has been passed + * @return array + */ + public static function processURI($uri) + { + $dot_position = strrpos($uri, '.'); + + if (! $dot_position) { + return array($uri, null); + } + + // If a dot has been found, do a couple + // of checks to find out if it introduces a formatter + $uri_parts = explode('.', $uri); + + $possible_extension = strtoupper(array_pop($uri_parts)); + + $uri = implode('.', $uri_parts); + + $formatter_class = 'Tdt\\Core\\Formatters\\' . $possible_extension . 'Formatter'; + + if (! class_exists($formatter_class)) { + // Re-attach the dot with the latter part of the uri + $uri .= '.' . strtolower($possible_extension); + + return array($uri, null); + } + + return array($uri, strtolower($possible_extension)); + } } diff --git a/app/Tdt/Core/Controller.php b/app/Tdt/Core/Controller.php new file mode 100644 index 00000000..a5216b97 --- /dev/null +++ b/app/Tdt/Core/Controller.php @@ -0,0 +1,40 @@ +applyThrottle($definition); - if (!empty($throttle_response)) { + if (! empty($throttle_response)) { return $throttle_response; } @@ -106,12 +104,12 @@ public function get($uri) return $this->createXMLResponse($data->data); } elseif (strtolower($source_type) == 'xml' && $extension == 'kml' && $data->geo_formatted) { return $this->createXMLResponse($data->data); - } elseif (!$data->is_semantic && $extension == 'xml' && $source_type != 'xml') { - \App::abort(406, "The requested format for the datasource is not available."); - } elseif (strtolower($source_type) == 'xml' && !$data->geo_formatted &&!empty($extension) && $extension != 'xml') { - \App::abort(406, "The requested format for the datasource is not available."); - } elseif (strtolower($source_type) == 'xml' && $data->geo_formatted && !empty($extension) && !in_array($extension, $data->preferred_formats)) { - \App::abort(406, "The requested format for the datasource is not available."); + } elseif (! $data->is_semantic && $extension == 'xml' && $source_type != 'xml') { + \App::abort(406, 'The requested format for the datasource is not available.'); + } elseif (strtolower($source_type) == 'xml' && ! $data->geo_formatted && ! empty($extension) && $extension != 'xml') { + \App::abort(406, 'The requested format for the datasource is not available.'); + } elseif (strtolower($source_type) == 'xml' && $data->geo_formatted && ! empty($extension) && ! in_array($extension, $data->preferred_formats)) { + \App::abort(406, 'The requested format for the datasource is not available.'); } $data->rest_parameters = $rest_parameters; @@ -122,7 +120,7 @@ public function get($uri) } // Semantic paging with the hydra voc - if ($data->is_semantic && !empty($data->paging)) { + if ($data->is_semantic && ! empty($data->paging)) { RdfNamespace::set('hydra', 'http://www.w3.org/ns/hydra/core#'); $graph = $data->data; $url = \URL::to($definition['collection_uri'] . '/' . $definition['resource_name']); @@ -152,7 +150,7 @@ public function get($uri) $graph->addResource($url, 'a', 'dcat:Dataset'); $title = null; - if (!empty($definition['title'])) { + if (! empty($definition['title'])) { $title = $definition['title']; } else { $title = $definition['collection_uri'] . '/' . $definition['resource_name']; @@ -176,14 +174,14 @@ public function get($uri) $data->formats = $format_helper->getAvailableFormats($data); // Store in cache - if (!empty($definition['cache_minutes'])) { + if (! empty($definition['cache_minutes'])) { Cache::put($cache_string, $data, $definition['cache_minutes']); } // Return the formatted response with content negotiation return ContentNegotiator::getResponse($data, $extension); } else { - \App::abort(404, "Source for the definition could not be found."); + \App::abort(404, 'Source for the definition could not be found.'); } } else { @@ -203,7 +201,7 @@ public function get($uri) array_push($data->data->datasets, \URL::to($collection_uri . '/' . $res['resource_name'])); } else { // Push the subcollection if it's not already in the array - if (!in_array(\URL::to($collection_uri), $data->data->collections)) { + if (! in_array(\URL::to($collection_uri), $data->data->collections)) { array_push($data->data->collections, \URL::to($collection_uri)); } } @@ -257,40 +255,6 @@ public function head($uri) return $response; } - /** - * Process the URI and return the extension (=format) and the resource identifier URI - * - * @param string $uri The URI that has been passed - * @return array - */ - private static function processURI($uri) - { - $dot_position = strrpos($uri, '.'); - - if (!$dot_position) { - return array($uri, null); - } - - // If a dot has been found, do a couple - // of checks to find out if it introduces a formatter - $uri_parts = explode('.', $uri); - - $possible_extension = strtoupper(array_pop($uri_parts)); - - $uri = implode('.', $uri_parts); - - $formatter_class = 'Tdt\\Core\\Formatters\\' . $possible_extension . 'Formatter'; - - if (!class_exists($formatter_class)) { - // Re-attach the dot with the latter part of the uri - $uri .= '.' . strtolower($possible_extension); - - return array($uri, null); - } - - return array($uri, strtolower($possible_extension)); - } - /** * Apply RESTful filtering of the data (case insensitive) * @@ -302,7 +266,7 @@ private static function processURI($uri) private static function applyRestFilter($data, $rest_params) { foreach ($rest_params as $rest_param) { - if (!empty($rest_param)) { + if (! empty($rest_param)) { if (is_object($data) && $key = self::propertyExists($data, $rest_param)) { $data = $data->$key; } elseif (is_array($data)) { @@ -369,10 +333,10 @@ public static function fetchData($identifier) return $data; } else { - \App::abort(404, "Source for the definition could not be found."); + \App::abort(404, 'Source for the definition could not be found.'); } } else { - \App::abort(404, "The definition could not be found."); + \App::abort(404, 'The definition could not be found.'); } } diff --git a/app/Tdt/Core/Definitions/DcatController.php b/app/Tdt/Core/Definitions/DcatController.php index 06912d24..8996eb1d 100644 --- a/app/Tdt/Core/Definitions/DcatController.php +++ b/app/Tdt/Core/Definitions/DcatController.php @@ -2,8 +2,6 @@ namespace Tdt\Core\Definitions; -use Illuminate\Routing\Router; - use Tdt\Core\Auth\Auth; use Tdt\Core\Datasets\Data; use Tdt\Core\ContentNegotiator; @@ -40,18 +38,28 @@ public function __construct( $this->settings = $settings; } - public function get($uri) + /** + * Handle a request for a DCAT feed of the definitions + * + * @param string $slug The part after api/dcat + * @return Response + */ + public function get($slug) { // Ask permission Auth::requirePermissions('info.view'); + $dcat = $this->createDcat(); + + $extension = ltrim($slug, '.'); + + $extension = strtolower($extension); + // Default format is ttl for dcat if (empty($extension)) { $extension = 'ttl'; } - $dcat = $this->createDcat(); - // Allow content nego. for dcat return ContentNegotiator::getResponse($dcat, $extension); } @@ -73,7 +81,7 @@ private function createDcat() $limit = \Input::get('limit'); if (empty($limit)) { - \Input::merge(array('limit' => 100)); + \Input::merge(array('limit' => 50)); } // Apply paging when fetching the definitions diff --git a/app/Tdt/Core/HomeController.php b/app/Tdt/Core/HomeController.php index aead3a14..a544cd8f 100644 --- a/app/Tdt/Core/HomeController.php +++ b/app/Tdt/Core/HomeController.php @@ -17,7 +17,7 @@ public static function handle($uri) $definitions = \Definition::all(); // Polyfill - if (!function_exists('array_column')) { + if (! function_exists('array_column')) { function array_column($array, $column_name) { return array_map(function ($element) use ($column_name) { return $element[$column_name]; diff --git a/app/Tdt/Core/Repositories/DcatRepository.php b/app/Tdt/Core/Repositories/DcatRepository.php index 12e7ffe5..f9f45e74 100644 --- a/app/Tdt/Core/Repositories/DcatRepository.php +++ b/app/Tdt/Core/Repositories/DcatRepository.php @@ -29,7 +29,7 @@ public function __construct( } /** - * Return a DCAT document based on the definitions that are passed + * Return a DCAT document based on the definitions that are passed. * * @param array Array with definition configurations * @@ -45,45 +45,45 @@ public function getDcatDocument(array $definitions, $oldest_definition) $uri = \Request::root(); // Add the catalog and a title - $graph->addResource($uri . '/api/dcat', 'a', 'dcat:Catalog'); + $graph->addResource($uri.'/api/dcat', 'a', 'dcat:Catalog'); - $graph->addLiteral($uri . '/api/dcat', 'dct:title', $all_settings['catalog_title']); + $graph->addLiteral($uri.'/api/dcat', 'dct:title', $all_settings['catalog_title']); // Fetch the catalog description, issued date and language - $graph->addLiteral($uri . '/api/dcat', 'dct:description', $all_settings['catalog_description']); - $graph->addLiteral($uri . '/api/dcat', 'dct:issued', $this->getIssuedDate()); + $graph->addLiteral($uri.'/api/dcat', 'dct:description', $all_settings['catalog_description']); + $graph->addLiteral($uri.'/api/dcat', 'dct:issued', $this->getIssuedDate()); $lang = $this->languages->getByCode($all_settings['catalog_language']); if (!empty($lang)) { - $graph->addResource($uri . '/api/dcat', 'dct:language', 'http://lexvo.org/id/iso639-3/' . $lang['lang_id']); - $graph->addResource('http://lexvo.org/id/iso639-3/' . $lang['lang_id'], 'a', 'dct:LinguisticSystem'); + $graph->addResource($uri.'/api/dcat', 'dct:language', 'http://lexvo.org/id/iso639-3/'.$lang['lang_id']); + $graph->addResource('http://lexvo.org/id/iso639-3/'.$lang['lang_id'], 'a', 'dct:LinguisticSystem'); } // Fetch the homepage and rights - $graph->addResource($uri . '/api/dcat', 'foaf:homepage', $uri); - $graph->addResource($uri . '/api/dcat', 'dct:license', 'http://www.opendefinition.org/licenses/cc-zero'); + $graph->addResource($uri.'/api/dcat', 'foaf:homepage', $uri); + $graph->addResource($uri.'/api/dcat', 'dct:license', 'http://www.opendefinition.org/licenses/cc-zero'); $graph->addResource('http://www.opendefinition.org/licenses/cc-zero', 'a', 'dct:LicenseDocument'); // Add the publisher resource to the catalog - $graph->addResource($uri . '/api/dcat', 'dct:publisher', $all_settings['catalog_publisher_uri']); + $graph->addResource($uri.'/api/dcat', 'dct:publisher', $all_settings['catalog_publisher_uri']); $graph->addResource($all_settings['catalog_publisher_uri'], 'a', 'foaf:Agent'); $graph->addLiteral($all_settings['catalog_publisher_uri'], 'foaf:name', $all_settings['catalog_publisher_name']); if (count($definitions) > 0) { // Add the last modified timestamp in ISO8601 - $graph->addLiteral($uri . '/api/dcat', 'dct:modified', date(\DateTime::ISO8601, strtotime($oldest_definition['updated_at']))); + $graph->addLiteral($uri.'/api/dcat', 'dct:modified', date(\DateTime::ISO8601, strtotime($oldest_definition['updated_at']))); foreach ($definitions as $definition) { - if ($definition['source_type'] != "InspireDefinition" && $definition['source_type'] != "RemoteDefinition") { + if ($definition['source_type'] != 'InspireDefinition' && $definition['source_type'] != 'RemoteDefinition') { // Create the dataset uri - $dataset_uri = $uri . "/" . $definition['collection_uri'] . "/" . $definition['resource_name']; + $dataset_uri = $uri.'/'.$definition['collection_uri'].'/'.$definition['resource_name']; $dataset_uri = str_replace(' ', '%20', $dataset_uri); $source_type = $definition['type']; // Add the dataset link to the catalog - $graph->addResource($uri . '/api/dcat', 'dcat:dataset', $dataset_uri); + $graph->addResource($uri.'/api/dcat', 'dcat:dataset', $dataset_uri); // Add the dataset resource and its description $graph->addResource($dataset_uri, 'a', 'dcat:Dataset'); @@ -92,14 +92,14 @@ public function getDcatDocument(array $definitions, $oldest_definition) if (!empty($definition['title'])) { $title = $definition['title']; } else { - $title = $definition['collection_uri'] . '/' . $definition['resource_name']; + $title = $definition['collection_uri'].'/'.$definition['resource_name']; } $graph->addLiteral($dataset_uri, 'dct:title', $title); // Add the description, identifier, issued date, modified date, contact point and landing page of the dataset $graph->addLiteral($dataset_uri, 'dct:description', @$definition['description']); - $graph->addLiteral($dataset_uri, 'dct:identifier', str_replace(' ', '%20', $definition['collection_uri'] . '/' . $definition['resource_name'])); + $graph->addLiteral($dataset_uri, 'dct:identifier', str_replace(' ', '%20', $definition['collection_uri'].'/'.$definition['resource_name'])); $graph->addLiteral($dataset_uri, 'dct:issued', date(\DateTime::ISO8601, strtotime($definition['created_at']))); $graph->addLiteral($dataset_uri, 'dct:modified', date(\DateTime::ISO8601, strtotime($definition['updated_at']))); $graph->addResource($dataset_uri, 'dcat:landingPage', $dataset_uri); @@ -138,28 +138,27 @@ public function getDcatDocument(array $definitions, $oldest_definition) $lang = $this->languages->getByName($definition[$dc_term]); if (!empty($lang)) { - $graph->addResource($dataset_uri, 'dct:' . $dc_term, 'http://lexvo.org/id/iso639-3/' . $lang['lang_id']); - $graph->addResource('http://lexvo.org/id/iso639-3/' . $lang['lang_id'], 'a', 'dct:LinguisticSystem'); + $graph->addResource($dataset_uri, 'dct:'.$dc_term, 'http://lexvo.org/id/iso639-3/'.$lang['lang_id']); + $graph->addResource('http://lexvo.org/id/iso639-3/'.$lang['lang_id'], 'a', 'dct:LinguisticSystem'); } } elseif ($dc_term == 'theme') { $theme = $this->themes->getByLabel($definition[$dc_term]); if (!empty($theme)) { - $graph->addResource($dataset_uri, 'dcat:' . $dc_term, $theme['uri']); + $graph->addResource($dataset_uri, 'dcat:'.$dc_term, $theme['uri']); $graph->addLiteral($theme['uri'], 'rdfs:label', $theme['label']); } - } else { - $graph->addLiteral($dataset_uri, 'dct:' . $dc_term, $definition[$dc_term]); + $graph->addLiteral($dataset_uri, 'dct:'.$dc_term, $definition[$dc_term]); } } } // Add the distribution of the dataset if ($this->isDataGeoFormatted($definition)) { - $distribution_uri = $dataset_uri . '.geojson'; + $distribution_uri = $dataset_uri.'.geojson'; } else { - $distribution_uri = $dataset_uri . '.json'; + $distribution_uri = $dataset_uri.'.json'; } // Check for spatial properties: @@ -190,7 +189,7 @@ public function getDcatDocument(array $definitions, $oldest_definition) $vcard->addResource('vcard:hasEmail', $attribution['email']); $attribution_node->addResource('prov:Agent', $vcard); - $attribution_node->addResource('dc:type', 'http://inspire.ec.europa.eu/metadata-codelist/ResponsiblePartyRole/' . $attribution['role']); + $attribution_node->addResource('dc:type', 'http://inspire.ec.europa.eu/metadata-codelist/ResponsiblePartyRole/'.$attribution['role']); $graph->addResource($dataset_uri, 'prov:qualifiedAttribution', $attribution_node); } @@ -201,7 +200,7 @@ public function getDcatDocument(array $definitions, $oldest_definition) $graph->addResource($distribution_uri, 'dcat:accessURL', $dataset_uri); $graph->addResource($distribution_uri, 'dcat:downloadURL', $distribution_uri); $graph->addLiteral($distribution_uri, 'dct:title', $title); - $graph->addLiteral($distribution_uri, 'dct:description', 'A json feed of ' . $dataset_uri); + $graph->addLiteral($distribution_uri, 'dct:description', 'A json feed of '.$dataset_uri); $graph->addLiteral($distribution_uri, 'dcat:mediaType', 'application/json'); $graph->addLiteral($distribution_uri, 'dct:issued', date(\DateTime::ISO8601, strtotime($definition['created_at']))); @@ -210,13 +209,13 @@ public function getDcatDocument(array $definitions, $oldest_definition) $license = $this->licenses->getByTitle($definition['rights']); if (!empty($license) && !empty($license['url'])) { - $graph->addResource($dataset_uri . '.json', 'dct:license', $license['url']); + $graph->addResource($dataset_uri.'.json', 'dct:license', $license['url']); $graph->addResource($license['url'], 'a', 'dct:LicenseDocument'); } } } else { $turtle_parser = new Turtle(); - $tmp_graph = new Graph(); + $turtle_parser->parse($graph, $definition['dcat'], 'turtle', 'http://foo.bar'); } } @@ -227,15 +226,15 @@ public function getDcatDocument(array $definitions, $oldest_definition) private function isDataGeoFormatted($definition) { - return ( + return $definition['type'] == 'shp' || ($definition['type'] == 'json' && !empty($definition['geo_formatted']) && $definition['geo_formatted']) || ($definition['type'] == 'xml' && !empty($definition['geo_formatted']) && $definition['geo_formatted']) - ); + ; } /** - * Return the issued date (in ISO8601 standard) of the catalog + * Return the issued date (in ISO8601 standard) of the catalog. * * @return string */ @@ -249,7 +248,7 @@ private function getIssuedDate() } /** - * Return the used namespaces in the DCAT document + * Return the used namespaces in the DCAT document. * * @return array */ @@ -257,13 +256,13 @@ public function getNamespaces() { return array( 'dcat' => 'http://www.w3.org/ns/dcat#', - 'dct' => 'http://purl.org/dc/terms/', + 'dct' => 'http://purl.org/dc/terms/', 'foaf' => 'http://xmlns.com/foaf/0.1/', - 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', - 'owl' => 'http://www.w3.org/2002/07/owl#', + 'owl' => 'http://www.w3.org/2002/07/owl#', 'locn' => 'http://www.w3.org/ns/locn#', - 'prov' => 'http://www.w3.org/ns/prov#' + 'prov' => 'http://www.w3.org/ns/prov#', ); } }