添加可视化要素字段编辑功能,添加字段过滤值功能

This commit is contained in:
Li Jianxuan 2015-01-18 05:56:19 +00:00
parent 974be6693d
commit f3f2d33369
4 changed files with 70 additions and 10 deletions

View File

@ -3983,6 +3983,9 @@ class Admin_DataController extends Zend_Controller_Action
$data = $visual->getVisualVars($uuid);
if(isset($data['visual_datatable']))
$this->view->visualField = $visualTable->readFields($data['visual_datatable']);
if(!empty($data))
{
$this->view->info = $data;
@ -4003,6 +4006,7 @@ class Admin_DataController extends Zend_Controller_Action
'visual_timefield_year' => $this->_getParam('visual_timefield_year'),
'visual_timefield_month' => $this->_getParam('visual_timefield_month'),
'visual_timefield_day' => $this->_getParam('visual_timefield_day'),
'visual_timefield_custom' => $this->_getParam('visual_timefield_custom'),
'visual_type' => $this->_getParam('visual_type'),
);

View File

@ -8,12 +8,12 @@
$this->breadcrumb('同步GEONETWORK元数据</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row">
<div class="span3">
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span9">
<div class="span10">
<h3>添加可视化要素</h3>
<hr />
<?php if(!empty($this->error)) {?>
@ -147,8 +147,14 @@
<div class="control-group var-group">
<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>
<div class="controls">
字段<select name="var[<?=$k?>][field]">
<?php foreach($this->visualField as $f){ ?>
<option value="<?= $f ?>" <?= $v['field'] == $f ? 'selected="selected"':"" ?>><?= $f ?></option>
<?php } ?>
</select>
字段<input type="text" name="var[<?=$k?>][field]" value="<?= $v['field'] ?>" />
显示名<input type="text" name="var[<?= $k ?>][name]" value="<?= $v['name'] ?>">
过滤条件<input type="text" name="var[<?= $k ?>][filter]" value="<?= isset($v['filter']) && is_string($v['filter']) ? $v['filter']:"" ?><?= isset($v['filter']) && is_array($v['filter']) ? join(";",$v['filter']):"" ?>">
</div>
</div>
<?php } ?>

View File

@ -40,6 +40,12 @@ class VisualHandle extends \Westdc\Visual\VariableEncoder
{
$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']);
if(!isset($data['status']))

View File

@ -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;
}
}