[Mapbender-commits] r9572 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Sep 2 05:36:00 PDT 2016


Author: armin11
Date: 2016-09-02 05:36:00 -0700 (Fri, 02 Sep 2016)
New Revision: 9572

Modified:
   trunk/mapbender/http/php/mod_transformTimeDimension.php
Log:
New functions for support of wms dimension parameters

Modified: trunk/mapbender/http/php/mod_transformTimeDimension.php
===================================================================
--- trunk/mapbender/http/php/mod_transformTimeDimension.php	2016-09-02 12:35:38 UTC (rev 9571)
+++ trunk/mapbender/http/php/mod_transformTimeDimension.php	2016-09-02 12:36:00 UTC (rev 9572)
@@ -22,12 +22,36 @@
 
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 $objDateTime = new DateTime('NOW');
-$maxEntries = 40;
+$maxEntries = 10;
+$default = false;
+$userValue = false;
 $kindOfExtent = "singleValue"; //interval, discreteValues, intervalWithDuration
 $extent = $objDateTime->format($objDateTime::ATOM);
 //http://stackoverflow.com/questions/21686539/regular-expression-for-full-iso-8601-date-syntax
 //http://stackoverflow.com/questions/12756159/regex-and-iso8601-formated-datetime
-$iso8601Pattern = '/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i';	
+function abort($message) {
+	$result->result->error = false;
+	$result->result->message = $message;
+	header('Content-Type: application/json');
+	echo json_encode($result);
+	die();
+}
+$iso8601Pattern = '/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i';
+//test default value
+if (isset($_REQUEST["default"]) & $_REQUEST["default"] != "") {
+	$testMatch = $_REQUEST["default"];
+	if (!preg_match($iso8601Pattern,$testMatch)){
+		abort("The value for the default parameter is not a valid iso8601 dateTime string."); 	
+ 	}
+	$default = $testMatch;
+}
+if (isset($_REQUEST["userValue"]) & $_REQUEST["userValue"] != "") {
+	$testMatch = $_REQUEST["userValue"];
+	if (!preg_match($iso8601Pattern,$testMatch)){
+		abort("The value for the userValue parameter is not a valid iso8601 dateTime string."); 	
+ 	}
+	$userValue = $testMatch;
+}	
 if (isset($_REQUEST["extent"]) & $_REQUEST["extent"] != "") {
 	$testMatch = $_REQUEST["extent"];
 	//search for comma
@@ -37,8 +61,7 @@
 		//test format of each value 
 		foreach ($singleValues as $dateTime) {
 			if (!preg_match($iso8601Pattern,$dateTime)){
-				echo 'The value for the <b>extent</b> parameter is not csv list of a valid iso8601 dateTime strings.<br/>'; 
-				die(); 		
+				abort("The value for the extent parameter is not csv list of a valid iso8601 dateTime strings."); 	
  			}
 		}
 		$kindOfExtent = "discreteValues";
@@ -46,34 +69,35 @@
 		//found interval with duration
 		//extract values
 		if (count(explode('/',$testMatch)) !== 3 ) {
-			echo 'The value for the <b>extent</b> parameter is not a valid iso8601 time duration string.<br/>'; 
-			die(); 	
+			abort("The value for the extent parameter is not a valid iso8601 time duration string."); 
+	
 		} else {
 			$singleValues = explode('/',$testMatch);
 			//check the first 2 entries for iso8601 strings	
 			for ($i=0; $i < 2; $i++) {
 				if (!preg_match($iso8601Pattern,$singleValues[$i])){
-					echo 'The first two parts of the value for the <b>extent</b> parameter are not valid iso8601 dateTime strings.<br/>'; 
-					die(); 		
+					abort("The first two parts of the value for the extent parameter are not valid iso8601 dateTime strings."); 	
  				}
 			}
 			//check duration string
 			$iso8601DurationPattern = '/^P(?=\w*\d)(?:\d+Y|Y)?(?:\d+M|M)?(?:\d+W|W)?(?:\d+D|D)?(?:T(?:\d+H|H)?(?:\d+M|M)?(?:\d+(?:\­.\d{1,2})?S|S)?)?$/';	
 			if (!preg_match($iso8601DurationPattern,$singleValues[2])) {
-				echo 'The third part of the value for the <b>extent</b> parameter is not a valid iso8601 duration string.<br/>'; 
-				die(); 	
+				abort("The third part of the value for the extent parameter is not a valid iso8601 duration string."); 
 			}
 		}
 		$kindOfExtent = "intervalWithDuration";
 	} elseif (!preg_match($iso8601Pattern,$testMatch)) {
-		echo 'The value for the <b>extent</b> parameter is not a valid iso8601 dateTime string.<br/>'; 
-		die(); 	
+
+			abort("The value for the extent parameter is not a valid iso8601 dateTime string."); 
 	}
 	//everything is allright
 	$extent = $testMatch;
 	$testMatch = NULL;
-	
 }
+//Variable for result object
+$result->data = array();
+//what do we need further for timeline:
+//min, max, if point is slideable, if some point is already selected -> userValue
 switch ($kindOfExtent) {
 	case "intervalWithDuration":
 		//calculate discrete points
@@ -81,30 +105,74 @@
 		$startTime = new DateTime($interval[0]);
 		$endTime = new DateTime($interval[1]);
 		$duration = new DateInterval($interval[2]);
-		$diffTime = $startTime->diff($endTime);
-		$diffTimeSeconds = $diffTime->format('%R%a')*(3600*24);
+		$diffTime = $startTime->diff($endTime); //creates php datetime interval object
+		$diffTimeSeconds = $diffTime->s + $diffTime->i * 60 + $diffTime->h * 3600 + $diffTime->days * (3600*24);
 		//Problem: DateInterval cannot be directly converted into seconds - only days are possible
+		//echo $startTime->add($duration)->format('c');
+		//die();
 		$seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->days * (3600*24); 
 		$numberOfDiscreteValues = $diffTimeSeconds / $seconds;
 		if ($numberOfDiscreteValues > $maxEntries) {
-			echo "Number of possible discrete values: ".$numberOfDiscreteValues." exeeds max allowed number for visualization of timeline: ".$maxEntries."!";
-			die();
+			//abort("Number of possible discrete values: ".$numberOfDiscreteValues." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
+			//use the default value or the userValue if given
+			if ($userValue !== false || $default !== false) {
+				if ($userValue !== false) {
+					$result->data[0]->id = 0;
+					$result->data[0]->content = $userValue;
+					$result->data[0]->start = $userValue;
+				} else {
+					$result->data[0]->id = 0;
+					$result->data[0]->content = $default;
+					$result->data[0]->start = $default;
+				}
+				//set options to make a moving of value possible
+				$result->options->editable->updateTime = true;
+				//$result->options->configure = true;
+				//$result->options->timeAxis->scale = 'minute';
+				//$result->options->timeAxis->step = 5;
+				//better do snapping in callback function!
+				//$result->options->onMove = "function (item,callback) {alert('test')}";
+			} else {
+
+			}
 		} else {
-			//push json values 
-		}	
+			$result->data[0]->id = 0;
+			$result->data[0]->content = $startTime->format('c');
+			$result->data[0]->start = $startTime->format('c');
+			for ($i=1; $i < $numberOfDiscreteValues+1; $i++) {
+				$time = $startTime->add($duration)->format('c');
+				$result->data[$i]->id = $i;
+				$result->data[$i]->content = $time;
+				$result->data[$i]->start = $time;
+			}
+		}		
+		$result->options->min = $interval[0];
+		$result->options->max = $interval[1];	
+		$result->result->error = false;
+		$result->result->message = "All done";
 		break;
 	case "discreteValues":
 		if (count(explode(',',$extent)) > $maxEntries) {
-			echo "Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!";
-			die();
+			abort("Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
 		} else {
-			//push json values
-			echo $extent;
+			$extentArray = explode(',',$extent);
+			for ($i=0; $i < count($extentArray); $i++) {
+				$result->data[$i]->id = $i;
+				$result->data[$i]->content = $extentArray[$i];
+				$result->data[$i]->start = $extentArray[$i];
+			}
 		}
+		//use first and last entry as borders
+		$result->options->min = $extentArray[0];
+		$result->options->max = $extentArray[count($extentArray) - 1];
+		$result->result->error = false;
+		$result->result->message = "All done";
 		break;
 	case "singleValue":
 			//push json values
 			echo $extent;
 		break;
-}
+} 
+header('Content-Type: application/json');
+echo json_encode($result);
 ?>



More information about the Mapbender_commits mailing list