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

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

@ -2,42 +2,63 @@
namespace Westdc\Visual\Handle;
use \Helpers\View as view;
use \Helpers\dbh;
use \Helpers\Table;
//事件中存在的操作
class VisualHandler
class VisualHandle
{
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)
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');
$ref = new Reference();
return $ref->deleteReferenceAuthor($id);
}
public function deleteTag(\Zend_EventManager_Event $e)
public function recordChanged(\Zend_EventManager_Event $e)
{
$id = $e->getParam('id');
$ref = new Reference();
return $ref->deleteReferenceTag($id);
}
}

View File

@ -1,6 +1,8 @@
<?php
namespace Westdc\Visual\Listener;
use Westdc\Visual\Handle\VisualHandle;
class VisualListener implements \Zend_EventManager_ListenerAggregate
{
private $event;
@ -12,9 +14,9 @@ class VisualListener implements \Zend_EventManager_ListenerAggregate
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);
$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);
}

View File

@ -1,18 +1,22 @@
<?php
namespace Westdc\Visual;
use Westdc\Visual\VisualListener;
use Westdc\Visual\Listener\VisualListener as Listener;
use Helpers\dbh;
class Visual
{
public $db;
protected $events;
function __construct($recordType)
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)
@ -42,11 +46,13 @@ class Visual
$dbh = new dbh();
if(empty($id))
{
$id = $dbh->insert($this->mainTable,$data,true);
$record = $this->getVisualVars($data['uuid']);
if(!empty($id) && is_numeric($id))
if(empty($record))
{
$id = $dbh->insert($this->mainTable,$data);
if($id)
{
$this->getEventManager()->trigger('submit.recordPosted', $this, $params);
return true;
@ -61,7 +67,7 @@ class Visual
}//add
else{
if(!$dbh->update($this->mainTable,$data," id=$id ",true))
if(!$dbh->update($this->mainTable,$data," uuid='{$data['uuid']}' "))
{
$this->getEventManager()->trigger('submit.recordChanged', $this, $params);
return "修改失败!请重试";
@ -73,14 +79,22 @@ class Visual
}// add()
//删除
public function del($id)
public function del($uuid)
{
if(!is_numeric($id) || empty($id) || $id< 0)
{
return false;
}
$sql = "DELETE FROM {$this->mainTable} WHERE id=$id";
$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();
}
}