[Mapbender-commits] r3555 - in branches/print_dev/http/print: . classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 17 08:52:44 EST 2009


Author: mschulz
Date: 2009-02-17 08:52:44 -0500 (Tue, 17 Feb 2009)
New Revision: 3555

Added:
   branches/print_dev/http/print/classes/mbTextDecorator.php
Modified:
   branches/print_dev/http/print/classes/mbMapDecorator.php
   branches/print_dev/http/print/classes/mbOverviewDecorator.php
   branches/print_dev/http/print/classes/mbTemplatePdf.php
   branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php
   branches/print_dev/http/print/mod_printPDF_div.php
   branches/print_dev/http/print/testConfigTemplate.json
Log:
added overriding values from request, new text decorator

Modified: branches/print_dev/http/print/classes/mbMapDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbMapDecorator.php	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/classes/mbMapDecorator.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -6,20 +6,51 @@
 
 class mbMapDecorator extends mbTemplatePdfDecorator {
 
+	protected $pageElementType = "map";
+	protected $elementId;
 	protected $filename;
+	/* a decorator should declare which parameters could be overwritten through the request object */
+	protected $overrideMembersFromRequest = array("res_dpi");
+	protected $res_dpi;
 	
-	public function __construct($pdfObj, $mapConf) {
-		parent::__construct($pdfObj, $mapConf);
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
 		$this->filename = TMPDIR."/".parent::generateOutputFileName("map","png");
+		$this->override();		
 		$this->decorate();	
 	}
 	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbMapDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbMapDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbMapDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbMapDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+				}	
+			}	
+		}
+	}
+	
 	public function decorate() {
 		$urls = $_REQUEST["map_url"];
 		$array_urls = explode("___", $urls);
 		$width = $this->conf->width;
 		$height = $this->conf->height;
-		$res = $this->pdf->objPdf->k*($this->conf->res_dpi/72);
+		$res = $this->pdf->objPdf->k * ($this->res_dpi/72);
 		$myURL = new stripRequest($array_urls[0]);
 		$e = new mb_notice("mbMapDecorator: original bbox: ".$myURL->get('BBOX'));
 		$this->pdf->setMapExtent($this->adjustBbox(explode(",",$myURL->get('BBOX')), $myURL->get('srs')));

Modified: branches/print_dev/http/print/classes/mbOverviewDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbOverviewDecorator.php	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/classes/mbOverviewDecorator.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -4,15 +4,21 @@
 require_once(dirname(__FILE__)."/../../classes/class_weldOverview2PNG.php");
 
 class mbOverviewDecorator extends mbTemplatePdfDecorator {
-
+
+	protected $pageElementType = "overview";
+	protected $elementId;
 	protected $filename;
 	
-	public function __construct($pdfObj, $mapConf) {
-		parent::__construct($pdfObj, $mapConf);
-		$this->filename = TMPDIR."/".parent::generateOutputFileName("map","png");
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->filename = TMPDIR."/".parent::generateOutputFileName("map","png");		
+		$this->override();		
 		$this->decorate();	
 	}
 	
+	public function override() {}
+	
 	public function decorate() {
 		$overview_url = $_REQUEST["overview_url"];
 		$o_url = new stripRequest($overview_url);
@@ -29,7 +35,7 @@
 		$myURL->set('bbox', $this->pdf->getMapExtent());
 
 		$i = new weldOverview2PNG($overview_url, $myURL->url, $this->filename);
-		$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height,'png');
+		$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height, 'png');
 	}
 }
 

Modified: branches/print_dev/http/print/classes/mbTemplatePdf.php
===================================================================
--- branches/print_dev/http/print/classes/mbTemplatePdf.php	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/classes/mbTemplatePdf.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -34,16 +34,20 @@
 			$this->objPdf->addPage();
             $pagecount = $this->objPdf->setSourceFile(dirname(__FILE__)."/../".$pageConf->tpl);
             $tplidx = $this->objPdf->importPage($pageConf->useTplPage);
+            $controls = $this->confPdf->controls;
             $this->objPdf->useTemplate($tplidx);
             
             foreach ($pageConf->elements as $pageElementId => $pageElementConf) {
 				switch ($pageElementConf->type) {
 					case "map":
-						$err = new mbMapDecorator($this, $pageElementConf);
+						$err = new mbMapDecorator($this, $pageElementId, $pageElementConf, $controls);
 						break;
 					case "overview":
-						$err = new mbOverviewDecorator($this, $pageElementConf);
-						break;						
+						$err = new mbOverviewDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;
+					case "text":
+						$err = new mbTextDecorator($this, $pageElementId, $pageElementConf, $controls);
+						break;							
 				}
             }
             

Modified: branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/classes/mbTemplatePdfDecorator.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -6,14 +6,33 @@
 	public $pdf;
 	/* the conf object for the desired decoration */
 	public $conf;
+	/* the controls object of the configuration */
+	public $controls;
 	/* possibly a zIndex will be needed */
 	public $zIndex;	
 	
-	public function __construct($pdfObj, $mapConf) {
+	public function __construct($pdfObj, $mapConf, $controls) {
 		$this->pdf = $pdfObj;
 		$this->conf = $mapConf;
+		$this->controls = $controls;
 	}
 	
+	public function getPageElementLink($pageElementId) {
+		$pageElementLinkArray = array();
+		$e = new mb_notice("mbTemplatePdfDecorator: pageElementId: ".$pageElementId);
+		foreach ($this->controls as $control) {
+			foreach ($control->pageElementsLink as $pageElementLinkId => $pageElementLinkValue) {
+				$e = new mb_notice("mbTemplatePdfDecorator: pageElementsLink: ".$control->id);
+				if ($pageElementLinkId == $pageElementId) 
+					#array_push($pageElementLinkArray, array($control->id => $pageElementLinkValue));
+					$pageElementLinkArray[$control->id]=$pageElementLinkValue;
+			}
+		}
+		return $pageElementLinkArray;
+	} 
+	
+	abstract public function override();
+	
 	abstract public function decorate();
 
 }

Added: branches/print_dev/http/print/classes/mbTextDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbTextDecorator.php	                        (rev 0)
+++ branches/print_dev/http/print/classes/mbTextDecorator.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -0,0 +1,52 @@
+<?php
+
+class mbTextDecorator extends mbTemplatePdfDecorator {
+
+	protected $pageElementType = "text";
+	protected $elementId;
+	/* a decorator should declare which parameters could be overwritten through the request object */
+	protected $overrideRequestIds = array("value");
+	/* the actual text that should be printed */
+	protected $value = "Lorem ipsum";
+	
+	public function __construct($pdfObj, $elementId, $mapConf, $controls) {
+		parent::__construct($pdfObj, $mapConf, $controls);
+		$this->elementId = $elementId;
+		$this->override();		
+		$this->decorate();	
+	}
+	
+	public function override() {
+		/* returns an array of (request key, member id) arrays */ 
+		$idsFromRequest = $this->getPageElementLink($this->elementId);
+		foreach ($idsFromRequest as $requestKey => $memberId) {
+			$e = new mb_notice("mbTextDecorator: checking overrides: ".$requestKey.$memberId);
+		}
+		foreach ($_REQUEST as $k => $v) {
+			$e = new mb_notice("mbTextDecorator: checking Request: ".$k."=".$v);
+		}
+		
+		foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+			foreach ($idsFromRequest as $requestKey => $memberId) {
+				$e = new mb_notice("mbTextDecorator: before override: set ".$memberId." to ".$requestKey);
+				if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") { 
+					$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+					$e = new mb_notice("mbTextDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+				}
+				else {
+					$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+				}	
+			}	
+		}
+	}
+	
+	public function decorate() {
+		$this->pdf->objPdf->setTextColor(0, 0, 0);
+		$this->pdf->objPdf->setFont($this->conf->font_family, "", $this->conf->font_size);
+		$this->pdf->objPdf->Text($this->conf->x_ul, $this->conf->y_ul, $this->value);
+	}
+	
+
+}
+
+?>
\ No newline at end of file

Modified: branches/print_dev/http/print/mod_printPDF_div.php
===================================================================
--- branches/print_dev/http/print/mod_printPDF_div.php	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/mod_printPDF_div.php	2009-02-17 13:52:44 UTC (rev 3555)
@@ -134,16 +134,16 @@
 		var element = json.controls[item];
 		var element_id = myId + "_" + element.id;
 		str += '<div class="print_option">\n';	
-		str += '<label class="print_label" for="'+element_id+'">'+element.label+'</label>\n';
+		str += '<label class="print_label" for="'+element.id+'">'+element.label+'</label>\n';
 		switch (element.type) {
 			case "text":
-				str += '<input type="'+element.type+'" name="'+element_id+'" id="'+element_id+'" size="'+element.size+'"><br>\n';
+				str += '<input type="'+element.type+'" name="'+element.id+'" id="'+element.id+'" size="'+element.size+'"><br>\n';
 				break;
 			case "textarea":
-				str += '<textarea id="'+element_id+'" name="'+element_id+'" size="'+element.size+'"></textarea><br>\n';
+				str += '<textarea id="'+element.id+'" name="'+element.id+'" size="'+element.size+'"></textarea><br>\n';
 				break;				
 			case "select":
-				str += '<select id="'+element_id+'" name="'+element_id+'" size="1">\n';
+				str += '<select id="'+element.id+'" name="'+element.id+'" size="1">\n';
 				for (var option_index in element.options) {
 					option = element.options[option_index];
 					str += '<option value="'+option.value+'">'+option.label+'</option>\n';

Modified: branches/print_dev/http/print/testConfigTemplate.json
===================================================================
--- branches/print_dev/http/print/testConfigTemplate.json	2009-02-17 10:33:20 UTC (rev 3554)
+++ branches/print_dev/http/print/testConfigTemplate.json	2009-02-17 13:52:44 UTC (rev 3555)
@@ -18,7 +18,9 @@
     		"label" : "DPI",
     		"type" : "select",
     		"size" : 20,
-    		"pageElementsLink" : "karte:res_dpi",
+    		"pageElementsLink" : {
+    			"karte" : "res_dpi"
+    		},
     		"options" : [
     			{
     			"value" : "56",
@@ -37,7 +39,9 @@
     		"label" : "Kommentar",
     		"type" : "textarea",
     		"size" : 5,
-    		"pageElementsLink" : "map:res_dpi"
+    		"pageElementsLink" : {
+    			"kommentar" : "value"
+    		}
     	}    	    		
     ],
     "pages" : [
@@ -60,7 +64,14 @@
 	    		"y_ul" : 15.2,
 	    		"width" : 50,
     			"height" : 50
-	   			}
+	   			},
+	   		"titel" : {
+    			"type" : "text", 
+    			"x_ul" : 10.1,
+	    		"y_ul" : 10,
+	    		"font_family" : "arial",
+	    		"font_size" : 14
+	   			}	   			
 	   		}
 	   	}
 	]



More information about the Mapbender_commits mailing list