[Mapbender-commits] r9434 - trunk/mapbender/http/geoportal
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Apr 7 06:54:00 PDT 2016
Author: armin11
Date: 2016-04-07 06:54:00 -0700 (Thu, 07 Apr 2016)
New Revision: 9434
Added:
trunk/mapbender/http/geoportal/mod_showCatalogueStatistics.php
trunk/mapbender/http/geoportal/mod_showCatalogueStatistics_server.php
Log:
First draft for showing catalog content as diagrams
Added: trunk/mapbender/http/geoportal/mod_showCatalogueStatistics.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_showCatalogueStatistics.php (rev 0)
+++ trunk/mapbender/http/geoportal/mod_showCatalogueStatistics.php 2016-04-07 13:54:00 UTC (rev 9434)
@@ -0,0 +1,152 @@
+<?php
+//show catalogue statistics
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+$languageCode = "de";
+
+//e.g. tabs and their content
+$html = '<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$languageCode.'">';
+$html .= '<body onload="getStatisticsFromServer(\'NUTS_1\');">';
+$metadataStr .= '<head>' .
+ '<title>'._mb("").'</title>' .
+ '<meta name="description" content="'._mb("").'" xml:lang="'.$languageCode.'" />'.
+ '<meta name="keywords" content="'._mb('').'" xml:lang="'.$languageCode.'" />' .
+ '<meta http-equiv="cache-control" content="no-cache">'.
+ '<meta http-equiv="pragma" content="no-cache">'.
+ '<meta http-equiv="expires" content="0">'.
+ '<meta http-equiv="content-language" content="'.$languageCode.'" />'.
+ '<meta http-equiv="content-style-type" content="text/css" />'.
+ '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">' .
+ '</head>';
+$style = <<< HTML
+<style>
+.outer {
+ position: relative;
+ justify-content: center;
+}
+.inner {
+ margin-right:auto;
+ margin-left:auto;
+}
+</style>
+HTML;
+$html .= $style;
+//css
+$html .= '<link type="text/css" href="../extensions/jquery-ui-1.8.1.custom/css/custom-theme/jquery-ui-1.8.5.custom.css" rel="Stylesheet" />';
+$html .= $metadataStr;
+$html .= '<button class="pulldata" id="NUTS_1" value="NUTS_1">Land</button>';
+$html .= '<button class="pulldata" id="NUTS_2" value="NUTS_2">Regierungsbezirk</button>';
+$html .= '<button class="pulldata" id="NUTS_3" value="NUTS_3">Kreis</button>';
+$html .= '<button class="pulldata" id="LAU_1" value="LAU_1">Kommunalverband</button>';
+$html .= '<button class="pulldata" id="LAU_2" value="LAU_2">Kommune</button>';
+$html .= '<div id="pie" class="inner"></div>';
+$html .= '<div id="dialog" class="inner"><div id="pie2" class="inner"></div></div>';
+//internal lib javascript part
+$html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-1.4.2.min.js"></script>';
+$html .= '<script type="text/javascript" src="../extensions/jquery-ui-1.8.1.custom/js/jquery-ui-1.8.1.custom.min.js"></script>';
+//external javascript part
+$html .= '<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>';
+$html .= '<script type="text/javascript" src="https://raw.githubusercontent.com/benkeen/d3pie/0.1.8/d3pie/d3pie.min.j"></script>';
+$html .= '<script type="text/javascript" src="https://raw.githubusercontent.com/benkeen/d3pie/0.1.8/d3pie/d3pie.js"></script>';
+
+//internal javascript part
+$javascript = <<< JAVASCRIPT
+ <script type="text/javascript">
+ var pie = new d3pie("pie");
+ var pie2 = new d3pie("pie2");
+ d3.selectAll(".pulldata")
+ .on("click", function(){
+ if (pie2 !== undefined) {
+ pie.destroy();
+ }
+ getStatisticsFromServer(this.value);
+ });
+ function getStatisticsFromServer(adminLevel) {
+ $.getJSON('mod_showCatalogueStatistics_server.php?adminLevel='+adminLevel, null, function(data) {
+ if (data !== false) {
+ var pie = new d3pie("pie", {
+ size: {
+ pieOuterRadius: "50%",
+ canvasHeight: 600,
+ canvasWidth: 600
+ },
+ data: {
+ sortOrder: "value-asc",
+ smallSegmentGrouping: {
+ enabled: false,
+ value: 2,
+ valueType: "value",
+ label: "Andere Organisationen",
+ color: "#999999"
+ },
+ content: data
+ },
+ tooltips: {
+ enabled: true,
+ type: "caption"
+ },
+ callbacks: {
+ onClickSegment: function(data) {
+ $("#dialog").dialog({
+ title: data.data.label,
+ height:500,
+ width:500,
+ modal: true,
+ buttons: {
+ }
+ });
+ getCategoriesFromServer(data.data.id);
+ }
+ }
+ });
+ } else {
+ alert("Keine Daten für EU-Gebietsklassifikation "+adminLevel+" gefunden!");
+ }
+ });
+ }
+
+ function getCategoriesFromServer(registratingDepartments) {
+ if (pie2 !== undefined) {
+ pie2.destroy();
+ }
+ $.getJSON('mod_showCatalogueStatistics_server.php?registratingDepartments='+registratingDepartments, null, function(data) {
+ if (data !== false) {
+ var pie2 = new d3pie("pie2", {
+ size: {
+ pieOuterRadius: "50%",
+ canvasHeight: 300,
+ canvasWidth: 300
+ },
+ data: {
+ sortOrder: "value-asc",
+ smallSegmentGrouping: {
+ enabled: false,
+ value: 2,
+ valueType: "value",
+ label: "Andere Kategorien",
+ color: "#999999"
+ },
+ content: data
+ },
+ tooltips: {
+ enabled: true,
+ type: "caption"
+ },
+ callbacks: {
+ }
+ });
+ } else {
+ alert("Keine weitere Kategorisierung vorhanden!");
+ $("#dialog").dialog("close");
+ if (pie2 !== undefined) {
+ pie2.destroy();
+ }
+
+ }
+ });
+ }
+ </script>
+JAVASCRIPT;
+$html .= $javascript;
+$html .= "</body></html>";
+echo $html;
+?>
Added: trunk/mapbender/http/geoportal/mod_showCatalogueStatistics_server.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_showCatalogueStatistics_server.php (rev 0)
+++ trunk/mapbender/http/geoportal/mod_showCatalogueStatistics_server.php 2016-04-07 13:54:00 UTC (rev 9434)
@@ -0,0 +1,119 @@
+<?php
+//server component to pull statistics from geoportal catalogue
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../classes/class_connector.php");
+require_once(dirname(__FILE__)."/../classes/class_Uuid.php");
+$adminLevel = "NUTS_1";
+$registratingDepartments = false;
+
+if (isset($_REQUEST["adminLevel"]) & $_REQUEST["adminLevel"] != "") {
+ $testMatch = $_REQUEST["adminLevel"];
+ if (!($testMatch == 'LAU_1' or $testMatch == 'LAU_2' or $testMatch == 'NUTS_3' or $testMatch == 'NUTS_1' or $testMatch == 'NUTS_2')){
+ //echo 'outputFormat: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>adminLevel</b> is not valid (NUTS_1, NUTS_2, NUTS_3, LAU_1, LAU_2).<br/>';
+ die();
+ }
+ $adminLevel = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
+ //validate to csv integer list
+ $testMatch = $_REQUEST["registratingDepartments"];
+ $pattern = '/^[\d,]*$/';
+ if (!preg_match($pattern,$testMatch)){
+ //echo 'registratingDepartments: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>registratingDepartments</b> is not valid (integer or cs integer list).<br/>';
+ die();
+ }
+ $registratingDepartments = $testMatch;
+ $testMatch = NULL;
+}
+
+
+$jsonString2 = <<<JSON
+ [{ "label": "Bushtit", "value": 5 },
+ { "label":"Chickadee", "value": 2 },
+ { "label": "Elephants", "value": 1 },
+ { "label": "Killdeer", "value": 3 },
+ { "label": "Caspian Tern", "value": 2 },
+ { "label": "Blackbird", "value": 1 },
+ { "label": "Song Sparrow", "value": 6 },
+ { "label": "Blue Jay", "value": 5 },
+ { "label": "Black-throated Gray warbler" , "value": 1 },
+ { "label": "Pelican", "value": 6 },
+ { "label": "Bewick's Wren", "value": 5 },
+ { "label": "Cowbird", "value": 1 },
+ { "label": "Fox Sparrow", "value": 6 },
+ { "label": "Common Yellowthroat", "value": 5 },
+ { "label": "Virginia Rail", "value": 6 },
+ { "label": "Sora", "value": 1 },
+ { "label": "Osprey", "value": 1 },
+ { "label": "Merlin", "value": 1 },
+ { "label": "Kestrel", "value": 1 }]
+JSON;
+
+if ($registratingDepartments == false) {
+
+ //pull statistics from database
+$sql = <<<SQL
+ select count, mb_group_name, mb_group_title, mb_group_logo_path, mb_group_id, mb_group_admin_code from ( select count(layer_id), fkey_mb_group_id from (select wms_id, fkey_mb_group_id from wms where fkey_mb_group_id <> 0 AND fkey_mb_group_id is not null group by fkey_mb_group_id, wms_id union select wms_id, fkey_mb_group_id from (select wms_owner, wms_id from wms where fkey_mb_group_id = 0 OR fkey_mb_group_id is null group by wms_owner, wms_id) as owner_wms inner join mb_user_mb_group on owner_wms.wms_owner = mb_user_mb_group.fkey_mb_user_id where mb_user_mb_group_type = 2) as test inner join layer on test.wms_id = layer.fkey_wms_id group by fkey_mb_group_id ) as layer_count inner join mb_group on mb_group.mb_group_id = layer_count.fkey_mb_group_id WHERE mb_group_admin_code = $1
+SQL;
+/*$sql = <<<SQL
+ select count, mb_group_name, mb_group_logo_path, mb_group_admin_code from ( select count(layer_id), fkey_mb_group_id from (select wms_id, fkey_mb_group_id from wms where fkey_mb_group_id <> 0 AND fkey_mb_group_id is not null group by fkey_mb_group_id, wms_id union select wms_id, fkey_mb_group_id from (select wms_owner, wms_id from wms where fkey_mb_group_id = 0 OR fkey_mb_group_id is null group by wms_owner, wms_id) as owner_wms inner join mb_user_mb_group on owner_wms.wms_owner = mb_user_mb_group.fkey_mb_user_id where mb_user_mb_group_type = 2) as test inner join layer on test.wms_id = layer.fkey_wms_id group by fkey_mb_group_id ) as layer_count inner join mb_group on mb_group.mb_group_id = layer_count.fkey_mb_group_id
+SQL;*/
+
+ $v = array(str_replace('_',' ',$adminLevel));
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $row = array();
+ $resultObj = array();
+ if ($res) {
+ $i = 0;
+ $dataCount = 0;
+ while ($row = db_fetch_assoc($res)) {
+ $resultObj[$i]["label"] = $row["mb_group_name"] . " (".(integer)$row["count"].")";
+ $resultObj[$i]["value"] = (integer)$row["count"];
+ $resultObj[$i]["caption"] = $row["mb_group_title"];
+ $resultObj[$i]["id"] = $row["mb_group_id"];
+ $dataCount = $dataCount + $resultObj[$i]["value"];
+ $i++;
+ }
+ if ($i == 0) {
+ $resultObj = false;
+ $e = new mb_exception("no results!");
+ } else {
+ for ($j=0;$j<count($resultObj);$j++) {
+ $resultObj[$j]["value"] = ceil(($resultObj[$j]["value"] / $dataCount) * 100);
+ }
+ }
+ } else {
+ $e = new mb_exception("Error while request to database!");
+ }
+} else {
+ //call searchInterface for categories
+ $connector = new connector("http://localhost/mb_trunk/php/mod_callMetadata.php?searchText=e&outputFormat=json&resultTarget=categories&searchResources=wms&searchId=test®istratingDepartments=".$registratingDepartments);
+ $jsonString = $connector->file;
+ $jsonObject = json_decode($jsonString);
+ $i = 0;
+ $dataCount = 0;
+ foreach ($jsonObject->searchMD->category[0]->subcat as $cat) {
+ $resultObj[$i]["label"] = $cat->title . " (".$cat->count.")";
+ $resultObj[$i]["value"] = $cat->count;
+ $resultObj[$i]["caption"] = $cat->title;
+ $dataCount = $dataCount + $resultObj[$i]["value"];
+ $i++;
+ }
+ if ($i == 0) {
+ $resultObj = false;
+ $e = new mb_exception("no results!");
+ } else {
+ for ($j=0;$j<count($resultObj);$j++) {
+ $resultObj[$j]["value"] = ceil(($resultObj[$j]["value"] / $dataCount) * 100);
+ }
+ }
+}
+$jsonString = json_encode($resultObj);
+header('Content-Type: application/json; charset='.CHARSET);
+echo $jsonString;
+?>
More information about the Mapbender_commits
mailing list