完善数据可视化的详细展示功能,修改dbh类中得bug,增加Uuid类

This commit is contained in:
Li Jianxuan 2014-05-28 06:44:19 +00:00
parent c261d567be
commit d746b7b313
12 changed files with 1687 additions and 1418 deletions

View File

@ -36,7 +36,9 @@
</div>
</div>
<?php }else{ ?>
<?php $vars = explode(",",$this->info['vars']) ?>
<?php $vars = array() ?>
<?php $encoder = new \Westdc\Visual\VariableEncoder; ?>
<?php $vars = $encoder->decode($this->info['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素 <small><a href="javascript:void(0);" onclick="delVar(this)">删除</a></small></label>

View File

@ -680,6 +680,9 @@ class DataController extends Zend_Controller_Action
$fund = new Fund($this->db);
$this->view->fund = $fund->fetch($uuid);
$visual = new \Westdc\Visual\Visual;
$this->view->visual = $visual->getVisualVars($uuid);
//判断特殊数据服务
$this->view->dataService= $this->checkDataService($uuid);

View File

@ -1,80 +1,110 @@
<?php
use Westdc\Visual\Factory;
class VisualController extends Zend_Controller_Action
{
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$this->uid = $user->id;
}else{
$this->_redirect('/account/login?href=/visual');
}
}
function indexAction()
{
$record_type = $this->_getParam("dataset");
if(empty($record_type))
return true;
$sc = Factory::Bootstrap($record_type);
}
//********************************************************
/*
* dataAction() ajax获取数据
*
* param string $ac //请求的数据类型
* param string $dt //请求的数据来源(气象,水文)
*
* return view
*/
function dataAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$record_type = $this->_getParam("dataset");
$record_subset = $this->_getParam("subdataset");
if(empty($record_type))
return true;
$record = Factory::Bootstrap($record_type);
if(!empty($record_subset))
{
$record->subset = $record_subset;
}
$data = $record->outPut();
$this->jsonexit($data);
return true;
}//dataAction() Ajax获取数据
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return application/JSON
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}//jsonexit() 退出并返回json数据
<?php
use Westdc\Visual;
use Westdc\Metadata;
use Helpers\View as view;
class VisualController extends Zend_Controller_Action
{
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db');
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$this->uid = $user->id;
}else{
$this->_redirect('/account/login?href=/visual');
}
}
function indexAction()
{
$record_type = $this->_getParam("dataset");
if(empty($record_type))
return true;
$sc = Factory::Bootstrap($record_type);
}
//********************************************************
/*
* dataAction() ajax获取数据
*
* param string $ac //请求的数据类型
* param string $dt //请求的数据来源(气象,水文)
*
* return view
*/
function dataAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
$record_type = $this->_getParam("dataset");
$record_subset = $this->_getParam("subdataset");
if(empty($record_type))
return true;
$record = Visual\Factory::Bootstrap($record_type);
if(!empty($record_subset))
{
$record->subset = $record_subset;
}
$data = $record->outPut();
$this->jsonexit($data);
return true;
}//dataAction() Ajax获取数据
//viewAction
public function viewAction()
{
$uuid = $this->_getParam('uuid');
if(empty($uuid) || \Helpers\Uuid::test($uuid) == false)
{
view::Post($this,"参数错误",-1);
return;
}
$visual = new Visual\Visual;
$this->view->data = $visual->getVisualVars($uuid);
if(empty($this->view->data))
{
view::Post($this,"此数据不支持可视化",-1);
return;
}
$metadata = new Metadata\Metadata;
$this->view->info = $metadata->view($uuid);
}
/*
* jsonexit() 退出并返回json数据
*
* param array $data 要返回的JSON数据可以是任意数组
*
* return application/JSON
*/
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}//jsonexit() 退出并返回json数据
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->data);
$this->headTitle()->setSeparator(' - ');
$theme = new Theme;
$theme->appendPlus($this,'highstock');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/data">数据与服务</a>');
$this->breadcrumb('数据可视化');
$this->breadcrumb()->setSeparator(' > ');
?>
<div class="row">
<div class="span12">
<h3><?= $this->info['title'] ?> <small>数据可视化查看</small></h3>
<hr />
<?php $vars = (new \Westdc\Visual\VariableEncoder)->normaldecode($this->data['vars']);?>
<?php foreach($vars as $k=>$v) { ?>
<a class="btn btn-default control-btn" href="javascript:void(0);" data-dataset="<?= $v['dataset'] ?>" data-subdataset="<?= $v['subdataset'] ?>" data-seriename="<?= $v['seriename'] ?>">
<?= $v['seriename'] ?>
</a>
<?php } ?>
</div>
<!-- 页面内容 -->
<div class="span12">
<div id="datachart" style="width:100%;height:500px;"></div>
<a class="btn btn-primary control-btn-cls" href="javascript:void(0);">
清除图像
</a>
</div>
<!-- //页面内容 -->
</div>
<script>
_this = {};
$(function() {
$('#datachart').highcharts('StockChart', {
rangeSelector : {
selected : 1,
inputEnabled: $('#container').width() > 480
},
credits : {
enabled : false
}
});
var chart = $('#datachart').highcharts();
$(".control-btn").click(function(){
dataset = $(this).data('dataset');
subdataset = $(this).data('subdataset');
seriename = $(this).data('seriename');
for(i in chart.series)
{
if(chart.series[i].name == seriename)
{
chart.series[i].remove();
return;
}
}
$.ajax({
'url': '/visual/data',
'data': 'dataset=' + dataset + '&subdataset=' + subdataset,
'method': 'GET',
'dataType': 'json',
'success': function(data){
chart.addSeries({
name: seriename,
data: data,
type : 'column'
});
},
'timeout': 30000,
'global' : true
});
});
$(".control-btn-cls").click(function(e) {
for(i in chart.series)
{
chart.series[i].remove();
}
});
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','block');
});
$( document ).ajaxSend(function() {
$('#loading').css('display','none');
});
</script>

View File

@ -0,0 +1,48 @@
<?php
namespace Helpers;
// 三段
// 一段是微秒 一段是地址 一段是随机数
class Uuid
{
private $valueBeforeMD5;
private $valueAfterMD5;
function __construct()
{
$address = $this->getLocalHost();
$this->valueBeforeMD5 = $address.':'.$this->currentTimeMillis().':'.$this->nextLong();
$this->valueAfterMD5 = md5($this->valueBeforeMD5);
}
function toString()
{
$raw = strtoupper($this->valueAfterMD5);
return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
}
private function nextLong()
{
$tmp = rand(0,1)?'-':'';
return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
}
private function currentTimeMillis()
{
list($usec, $sec) = explode(" ",microtime());
return $sec.substr($usec, 2, 3);
}
private function getLocalHost()
{
$address = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"]."/":"".'/';
$address.= $_SERVER["SERVER_ADDR"];
return strtolower($address);
}
static function test($uuid)
{
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
return false;
}else{
return true;
}
}
}

View File

@ -1,206 +1,206 @@
<?php
namespace Helpers;
use \Helpers\View as view;
class dbh
{
private $db; //传入PDO对象.
private $product = 0; //产品环境
public $debug = 0;
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
}
function insert($table,$data,$return=false)
{
$fields = array();
$datas = array();
foreach($data as $k=>$v)
{
$fields[] = '"'.$k.'"';
if(is_int($v) || is_float($v) || is_bool($v))
{
$datas[] = $v;
}else{
if(preg_match("/\'/",$v))
{
$v = preg_replace("/\'/","''",$v);
}
$datas[] = "'".$v."'";
}
}
$fields = join(",",$fields);
$datas = join(",",$datas);
if($return == false){
$sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas)";
if($this->debug == 1)
{
view::Dump($sql,false);
}
try{
return $this->db->exec($sql);
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}else{
$sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas) RETURNING id";
if($this->debug == 1)
{
view::Dump($sql,false);
}
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
$temp = $sth->fetch(\PDO::FETCH_ASSOC);
return $temp['id'];
}else{
return false;
}
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}
}//insert
function update($table,$data,$condition="",$return=false)
{
$ups = array();
foreach($data as $k=>$v)
{
if(is_int($v) || is_float($v) || is_bool($v))
{
$ups[] = '"'.$k.'"='.$v;
}else{
if(preg_match("/\'/",$v))
{
$v = preg_replace("/\'/","''",$v);
}
if(preg_match("/\"/",$v))
{
$v = preg_replace("/\"/","''",$v);
}
$ups[] = '"'.$k.'"=\''.$v."'";
}
}
$fields = join(",",$ups);
if(!empty($condition))
{
$wheresql = " WHERE ".$condition;
}else{
$wheresql = "";
}
if($return == false){
try{
$sql = "UPDATE \"".$table."\" SET $fields $wheresql";
if($this->debug == 1)
{
view::Dump($sql,false);
}
if($this->db->exec($sql))
{
return true;
}else{
return false;
}
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}else{
try{
$sql = "UPDATE \"".$table."\" SET $fields $wheresql";
if($this->debug == 1)
{
view::Dump($sql,false);
}
return $this->db->exec($sql);
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo "<pre>";
echo $sql."\r\n";
echo 'Caught exception: '. $e->getMessage(). "\r\n";
echo "</pre>";
}
}
}
}//update
//select
public function select($opt,$debug = false)
{
$field = (isset($opt['field']) && !empty($opt['field'])) ? $opt['field']:"*";
$tbl = (isset($opt['table']) && !empty($opt['table'])) ? $opt['table'] : "";
$join = (isset($opt['join']) && !empty($opt['join'])) ? $opt['join'] : "";
$wheresql = (isset($opt['where']) && !empty($opt['where'])) ? " WHERE ".$opt['where']:" ";
$limit = (isset($opt['limit']) && !empty($opt['limit'])) ? " LIMIT ".$opt['limit']:"";
$offset = (isset($opt['start']) && !empty($opt['start'])) ? " OFFSET ".$opt['start']:"";
$order = (isset($opt['order']) && !empty($opt['order'])) ? " ORDER BY ".$opt['order']:"";
$order .= (isset($opt['sort']) && !empty($opt['sort']) && $order !== '') ? " ".$opt['sort']:"";
$sql = "SELECT $field FROM $tbl
" . $join . "
" . $wheresql . "
" . $order . "
" . $limit . "
" . $offset . "
";
if($debug) return $sql;
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
public function chk($p)
{
if(!isset($p) || empty($p))
{
return false;
}else{
return true;
}
}
<?php
namespace Helpers;
use \Helpers\View as view;
class dbh
{
private $db; //传入PDO对象.
private $product = 0; //产品环境
public $debug = 0;
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
}
function insert($table,$data,$return=false)
{
$fields = array();
$datas = array();
foreach($data as $k=>$v)
{
$fields[] = '"'.$k.'"';
if(is_int($v) || is_float($v) || is_bool($v))
{
$datas[] = $v;
}else{
if(preg_match("/\'/",$v))
{
$v = preg_replace("/\'/","''",$v);
}
$datas[] = "'".$v."'";
}
}
$fields = join(",",$fields);
$datas = join(",",$datas);
if($return == false){
$sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas)";
if($this->debug == 1)
{
view::Dump($sql,false);
}
try{
return $this->db->exec($sql);
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}else{
$sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas) RETURNING id";
if($this->debug == 1)
{
view::Dump($sql,false);
}
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
$temp = $sth->fetch(\PDO::FETCH_ASSOC);
return $temp['id'];
}else{
return false;
}
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}
}//insert
function update($table,$data,$condition="",$return=false)
{
$ups = array();
foreach($data as $k=>$v)
{
if(is_int($v) || is_float($v) || is_bool($v))
{
$ups[] = '"'.$k.'"='.$v;
}else{
if(preg_match("/\'/",$v))
{
$v = preg_replace("/\'/","''",$v);
}
if(preg_match("/\"/",$v))
{
$v = preg_replace("/\"/","\"",$v);
}
$ups[] = '"'.$k.'"=\''.$v."'";
}
}
$fields = join(",",$ups);
if(!empty($condition))
{
$wheresql = " WHERE ".$condition;
}else{
$wheresql = "";
}
if($return == false){
try{
$sql = "UPDATE \"".$table."\" SET $fields $wheresql";
if($this->debug == 1)
{
view::Dump($sql,false);
}
if($this->db->exec($sql))
{
return true;
}else{
return false;
}
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo 'Caught exception: '. $e->getMessage(). "\n";
}
}
}else{
try{
$sql = "UPDATE \"".$table."\" SET $fields $wheresql";
if($this->debug == 1)
{
view::Dump($sql,false);
}
return $this->db->exec($sql);
}catch (Exception $e) {
if($this->product)
{
return false;
}else{
echo "<pre>";
echo $sql."\r\n";
echo 'Caught exception: '. $e->getMessage(). "\r\n";
echo "</pre>";
}
}
}
}//update
//select
public function select($opt,$debug = false)
{
$field = (isset($opt['field']) && !empty($opt['field'])) ? $opt['field']:"*";
$tbl = (isset($opt['table']) && !empty($opt['table'])) ? $opt['table'] : "";
$join = (isset($opt['join']) && !empty($opt['join'])) ? $opt['join'] : "";
$wheresql = (isset($opt['where']) && !empty($opt['where'])) ? " WHERE ".$opt['where']:" ";
$limit = (isset($opt['limit']) && !empty($opt['limit'])) ? " LIMIT ".$opt['limit']:"";
$offset = (isset($opt['start']) && !empty($opt['start'])) ? " OFFSET ".$opt['start']:"";
$order = (isset($opt['order']) && !empty($opt['order'])) ? " ORDER BY ".$opt['order']:"";
$order .= (isset($opt['sort']) && !empty($opt['sort']) && $order !== '') ? " ".$opt['sort']:"";
$sql = "SELECT $field FROM $tbl
" . $join . "
" . $wheresql . "
" . $order . "
" . $limit . "
" . $offset . "
";
if($debug) return $sql;
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
public function chk($p)
{
if(!isset($p) || empty($p))
{
return false;
}else{
return true;
}
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Westdc\Metadata;
class Metadata
{
private $db; //传入PDO对象.
//使用到的公共变量
public $tbl_metadata = "metadata";
function __construct()
{
$this->db = \Zend_Registry::get('db');
}
function view($uuid)
{
if(\Helpers\Uuid::test($uuid) !== true)
{
return "参数错误";
}
$sql = "SELECT * FROM ".$this->tbl_metadata." WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
return $rs->fetch();
}
}

View File

@ -6,7 +6,7 @@ use \Helpers\View as view;
use \Helpers\Table;
//事件中存在的操作
class VisualHandle
class VisualHandle extends \Westdc\Visual\VariableEncoder
{
private $db; //传入PDO对象误
private $config; //全局配置
@ -40,7 +40,7 @@ class VisualHandle
{
$data = $e->getParam('data');
$data['vars'] = join(",",$data['vars']);
$data['vars'] = $this->encode($data['vars']);
if(!isset($data['status']))
{

View File

@ -0,0 +1,44 @@
<?php
namespace Westdc\Visual;
class VariableEncoder
{
function __construct()
{
}
public function __invoke($json)
{
$this->decode($json);
}
public function encode($vars)
{
$arr = [];
foreach($vars as $k=>$v)
{
$names = explode("|",$v);
$arr[] = [ 'dataset' => $names[0], 'subdataset' => $names[1],'seriename' => $names[2]];
}
return json_encode($arr);
}
public function decode($json)
{
$arr = json_decode($json,true);
//var_dump($arr);
$data = [];
foreach($arr as $k=>$v)
{
$data[$k] = join("|",$v);
}
return $data;
}
public function normaldecode($json)
{
return json_decode($json,true);
}
}

View File

@ -95,6 +95,6 @@ class Visual
{
$sql = "SELECT * FROM {$this->mainTable} WHERE uuid='$uuid' LIMIT 1";
$rs = $this->db->query($sql);
return $rs->fetch();
return $rs->fetch(\PDO::FETCH_ASSOC);
}
}