完善后台数据可视化变量管理模块

This commit is contained in:
Li Jianxuan 2014-05-27 09:39:24 +00:00
parent a9e06eca09
commit aa3577176c
6 changed files with 264 additions and 203 deletions

View File

@ -3947,17 +3947,28 @@ class Admin_DataController extends Zend_Controller_Action
if(!empty($uuid))
{
$visual = new Visual\Visual;
$this->_helper->viewRenderer('visual-add');
$this->view->data = ['uuid' => $uuid];
if(empty($submit))
{
$data = $visual->getVisualVars($uuid);
if(!empty($data))
{
$this->view->info = $data;
}
return true;
}
$data = array(
'uuid' => $this->_getParam('uuid'),
'var' => $this->_getParam('var'),
'vars' => $this->_getParam('var'),
);
$visual = new Visual;
$status = $visual->add($data);
if($status === true)

View File

@ -28,14 +28,27 @@
<input type="text" id="inputUUID" placeholder="UUID" value="<?= $this->data['uuid'] ?>" class="input-block-level" name="uuid">
</div>
</div>
<?php if(empty($this->info['vars'])) { ?>
<div class="control-group">
<label class="control-label" for="inputVariable">可视化要素</label>
<div class="controls">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level" name="var[]">
</div>
</div>
<?php }else{ ?>
<?php $vars = explode(",",$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>
<div class="controls">
<input type="text" id="inputVariable" placeholder="Variable" class="input-block-level" name="var[]" value="<?= $v ?>">
</div>
</div>
<?php } ?>
<?php } ?>
<div class="control-group" id="last-control-group">
<div class="controls">
<input type="hidden" name="submit" value="1" />
<button type="button" class="btn btn-defualt" id="addVariable">添加要素</button>
<button type="submit" class="btn btn-primary">提交</button>
</div>

View File

@ -1,43 +1,64 @@
<?php
namespace Westdc\Visual\Handle;
use \Helpers\View as view;
use \Helpers\dbh;
use \Helpers\Table;
//事件中存在的操作
class VisualHandler
{
private $db; //传入PDO对象误
private $config; //全局配置
public $table;
public $tbl_maillog = ""; //邮件日志表
function __construct()
{
$this->db = \Zend_Registry::get('db');
$this->config = \Zend_Registry::get('config');
$this->table = new Table();
}
public function deleteAuthor(\Zend_EventManager_Event $e)
{
$id = $e->getParam('id');
$ref = new Reference();
return $ref->deleteReferenceAuthor($id);
}
public function deleteTag(\Zend_EventManager_Event $e)
{
$id = $e->getParam('id');
$ref = new Reference();
return $ref->deleteReferenceTag($id);
}
<?php
namespace Westdc\Visual\Handle;
use \Helpers\View as view;
use \Helpers\Table;
//事件中存在的操作
class VisualHandle
{
private $db; //传入PDO对象误
private $config; //全局配置
function __construct()
{
$this->db = \Zend_Registry::get('db');
$this->config = \Zend_Registry::get('config');
}
public function checkParam(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(empty($data['uuid']))
{
return "请填写数据UUID";
}
if(!is_array($data['vars']) || count($data['vars']) < 1)
{
return "参数错误";
}
return true;
}
public function processData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
$data['vars'] = join(",",$data['vars']);
if(!isset($data['status']))
{
$data['status'] = 1;
}
return $data;
}
public function recordPosted(\Zend_EventManager_Event $e)
{
$id = $e->getParam('id');
}
public function recordChanged(\Zend_EventManager_Event $e)
{
$id = $e->getParam('id');
}
}

View File

@ -1,27 +1,29 @@
<?php
namespace Westdc\Visual\Listener;
class VisualListener implements \Zend_EventManager_ListenerAggregate
{
private $event;
function __construct()
{
$this->event = new \Zend_EventManager_EventManager();
}
public function attach(\Zend_EventManager_EventCollection $events)
{
$Handler = new ReferenceHandler();
$events->attach('submit.checkParam', array($Handler, 'checkReferenceParam'), 100);
$events->attach('submit.processData', array($Handler, 'processReferenceData'), 100);
$events->attach('submit.recordPosted', array($Handler, 'recordPosted'), 100);
$events->attach('submit.recordChanged', array($Handler, 'recordChanged'), 100);
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
}
<?php
namespace Westdc\Visual\Listener;
use Westdc\Visual\Handle\VisualHandle;
class VisualListener implements \Zend_EventManager_ListenerAggregate
{
private $event;
function __construct()
{
$this->event = new \Zend_EventManager_EventManager();
}
public function attach(\Zend_EventManager_EventCollection $events)
{
$Handler = new VisualHandle();
$events->attach('submit.checkParam', array($Handler, 'checkParam'), 100);
$events->attach('submit.processData', array($Handler, 'processData'), 100);
$events->attach('submit.recordPosted', array($Handler, 'recordPosted'), 100);
$events->attach('submit.recordChanged', array($Handler, 'recordChanged'), 100);
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
}

View File

@ -1,48 +1,48 @@
<?php
namespace Westdc\Visual;
class Record
{
public $db;
function __construct($recordType)
{
$this->initDatabase();
}
public function initDatabase()
{
$config = \Zend_Registry::get('config');
$dsn = "pgsql:host={$config->visual_db->hostname};"
."port={$config->visual_db->port};"
."dbname={$config->visual_db->database};"
."user={$config->visual_db->username};"
."password={$config->visual_db->password}";
$this->db = new \PDO($dsn);
}
public function makeSql($table,$index,$fieldValue,$fieldTime)
{
$sql = "SELECT
\"$index\" as \"index\", \"$fieldValue\" as \"value\", \"$fieldTime\" as \"time\"
FROM \"$table\"
ORDER BY
extract(year from \"$fieldTime\") ASC,
extract(month from \"$fieldTime\") ASC,
extract(day from \"$fieldTime\") ASC,
";
$rs = $this->db->query($sql);
return $rs;
}
public function utcMsTime($time=''){
if(empty($time))
return (time()+8*3600)*1000;
else
return $time*1000;
}
<?php
namespace Westdc\Visual;
class Record
{
public $db;
function __construct($recordType)
{
$this->initDatabase();
}
public function initDatabase()
{
$config = \Zend_Registry::get('config');
$dsn = "pgsql:host={$config->visual_db->hostname};"
."port={$config->visual_db->port};"
."dbname={$config->visual_db->database};"
."user={$config->visual_db->username};"
."password={$config->visual_db->password}";
$this->db = new \PDO($dsn);
}
public function makeSql($table,$index,$fieldValue,$fieldTime)
{
$sql = "SELECT
\"$index\" as \"index\", \"$fieldValue\" as \"value\", \"$fieldTime\" as \"time\"
FROM \"$table\"
ORDER BY
extract(year from \"$fieldTime\") ASC,
extract(month from \"$fieldTime\") ASC,
extract(day from \"$fieldTime\") ASC,
";
$rs = $this->db->query($sql);
return $rs;
}
public function utcMsTime($time=''){
if(empty($time))
return (time()+8*3600)*1000;
else
return $time*1000;
}
}

View File

@ -1,86 +1,100 @@
<?php
namespace Westdc\Visual;
use Westdc\Visual\VisualListener;
class Visual
{
public $db;
function __construct($recordType)
{
$this->db = \Zend_Registry::get('db');
$Listener = new Listener();
@$this->getEventManager()->attachAggregate($Listener);
}
public function getEventManager(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
//添加
public function add($data,$id = 0)
{
$params = compact('data');
$results = $this->getEventManager()->trigger('submit.checkParam', $this, $params);
$cache_data = $results->last();
if($cache_data !== true)
{
return $cache_data;
}
$results = $this->getEventManager()->trigger('submit.processData', $this, $params);
$data = $results->last();
$dbh = new dbh();
if(empty($id))
{
$id = $dbh->insert($this->mainTable,$data,true);
if(!empty($id) && is_numeric($id))
{
$this->getEventManager()->trigger('submit.recordPosted', $this, $params);
return true;
}else{
if($id === false)
{
return '服务器开小差了,请稍后再试';
}else{
return '服务器处理中遇到错误,请联系管理员';
}
}
}//add
else{
if(!$dbh->update($this->mainTable,$data," id=$id ",true))
{
$this->getEventManager()->trigger('submit.recordChanged', $this, $params);
return "修改失败!请重试";
}else{
return true;
}
}//edit
}// add()
//删除
public function del($id)
{
if(!is_numeric($id) || empty($id) || $id< 0)
{
return false;
}
$sql = "DELETE FROM {$this->mainTable} WHERE id=$id";
return $this->db->exec($sql);
}
<?php
namespace Westdc\Visual;
use Westdc\Visual\Listener\VisualListener as Listener;
use Helpers\dbh;
class Visual
{
public $db;
protected $events;
function __construct()
{
$this->db = \Zend_Registry::get('db');
$this->mainTable = "datavisual";
$Listener = new Listener();
@$this->getEventManager()->attachAggregate($Listener);
}
public function getEventManager(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
//添加
public function add($data,$id = 0)
{
$params = compact('data');
$results = $this->getEventManager()->trigger('submit.checkParam', $this, $params);
$cache_data = $results->last();
if($cache_data !== true)
{
return $cache_data;
}
$results = $this->getEventManager()->trigger('submit.processData', $this, $params);
$data = $results->last();
$dbh = new dbh();
$record = $this->getVisualVars($data['uuid']);
if(empty($record))
{
$id = $dbh->insert($this->mainTable,$data);
if($id)
{
$this->getEventManager()->trigger('submit.recordPosted', $this, $params);
return true;
}else{
if($id === false)
{
return '服务器开小差了,请稍后再试';
}else{
return '服务器处理中遇到错误,请联系管理员';
}
}
}//add
else{
if(!$dbh->update($this->mainTable,$data," uuid='{$data['uuid']}' "))
{
$this->getEventManager()->trigger('submit.recordChanged', $this, $params);
return "修改失败!请重试";
}else{
return true;
}
}//edit
}// add()
//删除
public function del($uuid)
{
if(!is_numeric($id) || empty($id) || $id< 0)
{
return false;
}
$sql = "DELETE FROM {$this->mainTable} WHERE uuid='$uuid'";
return $this->db->exec($sql);
}
//获得可视化变量
public function getVisualVars($uuid)
{
$sql = "SELECT * FROM {$this->mainTable} WHERE uuid='$uuid' LIMIT 1";
$rs = $this->db->query($sql);
return $rs->fetch();
}
}