[Mapbender-commits] r9045 - in trunk/mapbender/http: classes plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Aug 12 06:37:22 PDT 2014


Author: verenadiewald
Date: 2014-08-12 06:37:22 -0700 (Tue, 12 Aug 2014)
New Revision: 9045

Modified:
   trunk/mapbender/http/classes/class_wms_owsproxy_log.php
   trunk/mapbender/http/plugins/mb_owsproxy_log_csv.js
Log:
query type "getServiceLogs": Show only a summarized view of logs in table, list complete query result in csv file

Modified: trunk/mapbender/http/classes/class_wms_owsproxy_log.php
===================================================================
--- trunk/mapbender/http/classes/class_wms_owsproxy_log.php	2014-08-12 12:01:12 UTC (rev 9044)
+++ trunk/mapbender/http/classes/class_wms_owsproxy_log.php	2014-08-12 13:37:22 UTC (rev 9045)
@@ -18,7 +18,9 @@
     private $withContactData;
     
     private $resultHeader;
+    private $resultHeaderDisplay;
     private $resultData;
+    private $resultDataDisplay;
     private $resultMessage;
     
     
@@ -68,7 +70,9 @@
             $wmslogcsv->withContactData = $withContactData;
         }
         $wmslogcsv->resultHeader = array();
+        $wmslogcsv->resultHeaderDisplay = array();
         $wmslogcsv->resultData = array();
+        $wmslogcsv->resultDataDisplay = array();
         $wmslogcsv->resultMessage = "";
         return $wmslogcsv;
     }
@@ -113,6 +117,8 @@
 #function=getServiceLogs&listType=user&   serviceType=wms&userId=xyz&timeFrom=2012-05-31T12:01&timeTo=2012-05-31T12:12
         if($this->listType == "service"){
             $selectColumns = " m.*,u.mb_user_id,u.mb_user_name";
+            $selectColumnsDisplay = " m.fkey_wms_id as wms_id,u.mb_user_id,u.mb_user_name, sum(m.pixel) as pixel,sum(m.price) as price";
+            $groupByForDisplay = " GROUP BY m.fkey_wms_id, u.mb_user_id,u.mb_user_name  ORDER BY m.fkey_wms_id DESC";
             $join = " INNER JOIN mb_user AS u ON (u.mb_user_id = m.fkey_mb_user_id)";
 //            $innerjoinContactData = "";
             if($this->withContactData !== null && $this->withContactData == "1") {
@@ -121,6 +127,7 @@
                         .",u.mb_user_email,u.mb_user_phone,u.mb_user_street"
                         .",u.mb_user_housenumber,u.mb_user_postal_code"
                         .",u.mb_user_city";
+                $groupByForDisplay = " GROUP BY m.fkey_wms_id, u.mb_user_id,u.mb_user_name, u.mb_user_firstname,mb_user_lastname,u.mb_user_department,u.mb_user_description,u.mb_user_email,u.mb_user_phone,u.mb_user_street,u.mb_user_housenumber,u.mb_user_postal_code,u.mb_user_city ORDER BY m.fkey_wms_id DESC";
             }
             $v = array($this->mb_user_id, $this->timeFrom, $this->timeTo);
 //            $v = array($this->wmsId, $this->timeFrom, $this->timeTo, 9415);
@@ -136,13 +143,23 @@
                     ." FROM mb_proxy_log AS m INNER JOIN wms AS w ON"
                     ." (m.fkey_wms_id = w.wms_id AND w.wms_owner=$1"
                     .$wmsIdWhere." AND m.proxy_log_timestamp >= $2"
+                    ." AND m.proxy_log_timestamp <= $3)".$join;
+		                
+            $sqlDisplay  = "SELECT".$selectColumnsDisplay
+            ." FROM mb_proxy_log AS m INNER JOIN wms AS w ON"
+            		." (m.fkey_wms_id = w.wms_id AND w.wms_owner=$1"
+            		.$wmsIdWhere." AND m.proxy_log_timestamp >= $2"
                     ." AND m.proxy_log_timestamp <= $3)".$join
-		    . WmsOwsLogCsv::$LIMIT_SQL . WmsOwsLogCsv::$LIMIT_INT;
+            				." ". $groupByForDisplay;
             
             $result = db_prep_query($sql,$v,$t);
+            $resultDisplay = db_prep_query($sqlDisplay,$v,$t);
             $this->readResult($result);
+            $this->readResultDisplay($resultDisplay);
         } else if($this->listType == "user"){
             $selectColumns = " m.*,w.wms_title,w.wms_version,w.wms_abstract";
+            $selectColumnsDisplay = " m.fkey_wms_id as wms_id,w.wms_title,w.wms_version,w.wms_abstract, sum(m.pixel) as pixel,sum(m.price) as price";
+            $groupByForDisplay = " GROUP BY m.fkey_wms_id,w.wms_title,w.wms_version,w.wms_abstract ORDER BY m.fkey_wms_id DESC";
             $join = "";
 //            $innerjoinContactData = "";
             if($this->withContactData !== null && $this->withContactData == "1") {
@@ -152,9 +169,9 @@
                         .",u.mb_user_housenumber,u.mb_user_postal_code"
                         .",u.mb_user_city";
                 $join .= " INNER JOIN mb_user AS u  ON (u.mb_user_id = m.fkey_mb_user_id)";
+                $groupByForDisplay = " GROUP BY m.fkey_wms_id, w.wms_title,w.wms_version,w.wms_abstract,u.mb_user_firstname,mb_user_lastname,u.mb_user_department,u.mb_user_description,u.mb_user_email,u.mb_user_phone,u.mb_user_street,u.mb_user_housenumber,u.mb_user_postal_code,u.mb_user_city ORDER BY m.fkey_wms_id DESC";
             }
             
-            
             $v = array($this->timeFrom, $this->timeTo, $this->mb_user_id);
             $t = array("t", "t", "i");
             
@@ -177,10 +194,18 @@
                     ." FROM mb_proxy_log AS m INNER JOIN wms AS w ON"
                     ." (m.fkey_wms_id = w.wms_id AND w.wms_owner=$3"
                     .$userWhere." AND m.proxy_log_timestamp >= $1"
+                    ." AND m.proxy_log_timestamp <= $2".$wmsIdWhere.")".$join;
+		    
+            $sqlDisplay  = "SELECT".$selectColumnsDisplay
+                    ." FROM mb_proxy_log AS m INNER JOIN wms AS w ON"
+                    ." (m.fkey_wms_id = w.wms_id AND w.wms_owner=$3"
+                    .$userWhere." AND m.proxy_log_timestamp >= $1"
                     ." AND m.proxy_log_timestamp <= $2".$wmsIdWhere.")".$join
-		    . WmsOwsLogCsv::$LIMIT_SQL . WmsOwsLogCsv::$LIMIT_INT;
+            		." ". $groupByForDisplay;
             $result = db_prep_query($sql,$v,$t);
+            $resultDisplay = db_prep_query($sqlDisplay,$v,$t);
             $this->readResult($result);
+            $this->readResultDisplay($resultDisplay);
         }
     }
 
@@ -337,14 +362,60 @@
 
         if(!is_null($offsetPixel) || !is_null($offsetPrice)) {
             for($j=0;$j<$num_fields;$j++) {
-                if($j == $offsetPixel && !is_null($offsetPixel))
+    			if($j == $offsetPixel && !is_null($offsetPixel)) {
                     $this->resultData[$i][] = (string)$sumPixel;
-                else if($j == $offsetPrice && !is_null($offsetPrice))
+    			}
+    			else if($j == $offsetPrice && !is_null($offsetPrice)) {
                     $this->resultData[$i][] = (string)$sumPrice;
-                else
+    			}
+    			else {
                     $this->resultData[$i][] = '---';
+    			}
+    		}
+    	}
+    }
+    
+    private function readResultDisplay($result){
+        $offsetPixel = null;
+        $offsetPrice = null;
+        $sumPixel = 0;
+        $sumPrice = 0;
+        if ($result != false) {
+            $num_fields = pg_num_fields($result);
+            for ( $i = 0; $i < $num_fields; $i++ ){
+                $field_name = pg_field_name($result , $i);
+                $this->resultHeaderDisplay[] = $field_name;
+
+                // keep offsets of prixel and price row
+                if($field_name === "pixel")        $offsetPixel = $i;
+                else if($field_name === "price")   $offsetPrice = $i;
             }
         }
+        $i = 0;
+        while($row = db_fetch_row($result)){
+        foreach( $row as $key=>$value){
+    			$this->resultDataDisplay[$i][] = $value;
+    			    
+    			if($key == $offsetPixel)        $sumPixel += $value;
+    			else if($key == $offsetPrice)   $sumPrice += $value;
+    		}
+
+            $i++;
+        }
+        
+        if(!is_null($offsetPixel) || !is_null($offsetPrice)) {
+        	for($j=0;$j<$num_fields;$j++) {
+        		if($j == $offsetPixel && !is_null($offsetPixel)) {
+        			$this->resultDataDisplay[$i][] = (string)$sumPixel;
+        		}
+        		else if($j == $offsetPrice && !is_null($offsetPrice)) {
+        			$this->resultDataDisplay[$i][] = (string)$sumPrice;
+        		}
+        		else {
+        			$this->resultDataDisplay[$i][] = '---';
+        		}
+            }
+        }
     }
     
     public function getAsCsv(){
@@ -377,7 +448,9 @@
         return array(
             "function"=> $this->function,
             "header"=> $this->resultHeader,
+        	"headerDisplay"=> $this->resultHeaderDisplay,
             "data" => $this->resultData,
+        	"dataDisplay" => $this->resultDataDisplay,
             "message" => $this->resultMessage,
             "error" => "",
             "limit" => WmsOwsLogCsv::$LIMIT_INT);

Modified: trunk/mapbender/http/plugins/mb_owsproxy_log_csv.js
===================================================================
--- trunk/mapbender/http/plugins/mb_owsproxy_log_csv.js	2014-08-12 12:01:12 UTC (rev 9044)
+++ trunk/mapbender/http/plugins/mb_owsproxy_log_csv.js	2014-08-12 13:37:22 UTC (rev 9045)
@@ -162,6 +162,36 @@
                         alert(data.message);
                         self.location.reload();
                     } else {
+                    	if(data.function == "getServiceLogs") {
+                            var fs = $owsproxyCsv.find("#queryResult");
+                            fs.text(fs.attr('data-title')+" "+(data.dataDisplay.length >= data.limit ? fs.attr('data-limit').replace("XXX", data.limit) : fs.attr('data-count').replace("XXX", data.dataDisplay.length)));
+                            lastRequestData = parameter;
+                            var result = '<table class="result"><tr class="result-header">';
+                            var col_layer_num = -1;
+                            for(var i = 0; i < data.headerDisplay.length; i++){
+                                if(data.headerDisplay[i] == "layer_featuretype_list"){
+                                    col_layer_num = i;
+                                }
+                                result += '<td>' + data.headerDisplay[i] + '</td>'
+                            }
+                            result += '</tr>';
+
+                            // Summe hier berechnen!
+
+                            for(i = 0; i < data.dataDisplay.length; i++){
+                                result += '<tr>';
+                                for(var j = 0; j < data.dataDisplay[i].length; j++){
+                                    if(col_layer_num != -1 && col_layer_num == j && data.dataDisplay[i][j] != null){
+                                        result += '<td>' + (data.dataDisplay[i][j].replace(/,/g, ", ")) + '</td>';
+                                    } else {
+                                        result += '<td>' + data.dataDisplay[i][j] + '</td>';
+                                    }
+                                }
+                                result += '</tr>';
+                            }
+                            result += '</table>';
+                    	}
+                    	else {
                         var fs = $owsproxyCsv.find("#queryResult");
                         fs.text(fs.attr('data-title')+" "+(data.data.length >= data.limit ? fs.attr('data-limit').replace("XXX", data.limit) : fs.attr('data-count').replace("XXX", data.data.length)));
                         lastRequestData = parameter;
@@ -189,6 +219,7 @@
                             result += '</tr>';
                         }
                         result += '</table>';
+                    	} 
                         $('div#result').html(result);
                         $owsproxyCsv.find("fieldset#owsproxy-log-result").css("display", "block");
                     }



More information about the Mapbender_commits mailing list