添加可视化要素
error)) {?>
@@ -147,8 +147,14 @@
diff --git a/application/module/Westdc/Visual/Handle/VisualHandle.php b/application/module/Westdc/Visual/Handle/VisualHandle.php
index 24850071..c9b829d4 100644
--- a/application/module/Westdc/Visual/Handle/VisualHandle.php
+++ b/application/module/Westdc/Visual/Handle/VisualHandle.php
@@ -39,6 +39,12 @@ class VisualHandle extends \Westdc\Visual\VariableEncoder
public function processData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
+
+ foreach($data['vars'] as $k=>$v)
+ {
+ if(preg_match("/;/",$v['filter']))
+ $data['vars'][$k]['filter'] = explode(";",$v['filter']);
+ }
$data['vars'] = $this->encode($data['vars']);
diff --git a/application/module/Westdc/Visual/Record.php b/application/module/Westdc/Visual/Record.php
index b18d9294..9bf665d5 100644
--- a/application/module/Westdc/Visual/Record.php
+++ b/application/module/Westdc/Visual/Record.php
@@ -4,7 +4,7 @@ namespace Westdc\Visual;
class Record extends Database
{
- public $subdataset,$valueFilter;
+ public $subdataset,$valueFilter,$vars;
public $timeFiled = "utctime";
@@ -35,6 +35,7 @@ class Record extends Database
$visual = new Visual;
$var_data = $visual->getVisualVars($uuid);
+ $this->vars = $var_data['vars'];
if(!empty($var_data['visual_valuefilter']))
$this->valueFilter = (float)$var_data['visual_valuefilter'];
@@ -74,7 +75,7 @@ class Record extends Database
$this->timeFiled = $timefield_temp;
}//multiple
elseif($var_data['visual_timefield_model'] == 'custom'){
- $this->timeFiled = $var_data['visual_timefield_model'];
+ $this->timeFiled = $var_data['visual_timefield_custom'];
}//custom
//时间字段为空的bug
@@ -91,9 +92,9 @@ class Record extends Database
}
if(isset($var_data['data']) && !empty($var_data['data']))
- $this->sql = $this->makeSql($var_data['data'],$this->subdataset);
+ $this->sql = $this->makeSql($var_data['data']);
else
- $this->sql = $this->makeSql($var_data['visual_datatable'],$this->subdataset);
+ $this->sql = $this->makeSql($var_data['visual_datatable']);
//echo $this->sql;exit();
}
@@ -122,16 +123,37 @@ class Record extends Database
return $data;
}
- public function makeSql($table,$fieldValue)
+ public function makeSql($table)
{
$wheresql = "";
+
if(!empty($this->valueFilter))
{
- $wheresql = " WHERE \"$fieldValue\"<>".$this->valueFilter .' ';
+ $wheresql = " WHERE \"$this->subdataset\"<>".$this->valueFilter .' ';
+ }
+
+ $filter = $this->getFilter($this->subdataset);
+ if(!empty($filter))
+ {
+ if(is_string($filter))
+ $wheresql = ' WHERE "'.$this->subdataset.'"'. $filter .' ';
+
+ elseif(is_array($filter))
+ {
+ $wheresql = [];
+ foreach($filter as $v)
+ {
+ if(preg_match("/^[<|>|=|!](.*)/",$v))
+ $wheresql[] = '"'.$this->subdataset.'"'.$v;
+ else
+ $wheresql[] = $v;
+ }
+ $wheresql = ' WHERE '.join(" AND ",$wheresql);
+ }
}
$sql = "SELECT
- {$this->timeFiled} as utctime , \"$fieldValue\" as value
+ {$this->timeFiled} as utctime , \"{$this->subdataset}\" as value
FROM $table as tbl
$wheresql
ORDER BY
@@ -152,4 +174,26 @@ class Record extends Database
else
return ($time)*1000;
}
+
+ public function getFilter($subdataset)
+ {
+ $vars = json_decode($this->vars,TRUE);
+
+ if(!is_array($vars) || count($vars)<1)
+ return null;
+
+ foreach($vars as $v)
+ {
+ if($v['field'] == $subdataset)
+ {
+ if(isset($v['filter']) && !empty($v['filter']))
+ {
+ return $v['filter'];
+ }else{
+ return null;
+ }
+ }
+ }
+ return null;
+ }
}
\ No newline at end of file