2014-06-11 08:12:05 +00:00
|
|
|
<?php
|
|
|
|
namespace Westdc\Visual;
|
|
|
|
|
|
|
|
use Westdc\Visual\Listener\VisualListener as Listener;
|
|
|
|
use Helpers\dbh;
|
|
|
|
|
|
|
|
class Visual
|
|
|
|
{
|
2014-06-12 01:51:59 +00:00
|
|
|
private $db;
|
|
|
|
private $config;
|
|
|
|
|
2014-06-11 08:12:05 +00:00
|
|
|
protected $events;
|
|
|
|
|
2014-06-12 01:51:59 +00:00
|
|
|
private $metadataTable;
|
|
|
|
|
2014-06-11 08:12:05 +00:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
$this->db = \Zend_Registry::get('db');
|
2014-06-12 01:51:59 +00:00
|
|
|
$this->config = \Zend_Registry::get('config');
|
2014-06-11 08:12:05 +00:00
|
|
|
|
|
|
|
$this->mainTable = "datavisual";
|
|
|
|
|
|
|
|
$Listener = new Listener();
|
|
|
|
@$this->getEventManager()->attachAggregate($Listener);
|
2014-06-12 01:51:59 +00:00
|
|
|
|
|
|
|
if(isset($this->config->sub->metadata) && !empty($this->config->sub->metadata))
|
|
|
|
{
|
|
|
|
$this->metadataTable = $this->config->sub->metadata;
|
|
|
|
}else{
|
|
|
|
$this->metadataTable = 'metadata';
|
|
|
|
}
|
2014-06-11 08:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$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(\PDO::FETCH_ASSOC);
|
|
|
|
}
|
|
|
|
|
|
|
|
//获得可以可视化的元数据
|
|
|
|
public function getVisualMetadata()
|
|
|
|
{
|
2014-06-12 01:51:59 +00:00
|
|
|
$sql = "SELECT * FROM {$this->metadataTable} md
|
2014-06-11 08:12:05 +00:00
|
|
|
LEFT JOIN {$this->mainTable} v ON v.uuid = md.uuid
|
|
|
|
WHERE v.uuid IS NOT NULL";
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
return $rs->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
}
|
2014-05-26 03:38:36 +00:00
|
|
|
}
|