2014-06-13 06:00:56 +00:00
|
|
|
<?php
|
|
|
|
namespace Westdc\Visual;
|
|
|
|
|
|
|
|
class Record
|
|
|
|
{
|
|
|
|
|
|
|
|
public $db;
|
|
|
|
|
|
|
|
public $subdataset;
|
|
|
|
|
|
|
|
public $timeFiled = "utctime";
|
|
|
|
|
|
|
|
private $sql;
|
|
|
|
|
|
|
|
function __construct($uuid = NULL,$identifier = "")
|
|
|
|
{
|
|
|
|
$this->initDatabase();
|
|
|
|
|
|
|
|
if(!empty($identifier))
|
|
|
|
{
|
|
|
|
$this->subdataset = $identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($uuid) && !empty($identifier))
|
|
|
|
{
|
|
|
|
$this->initVisual($uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __invoke()
|
|
|
|
{
|
|
|
|
return $this->getData();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 initVisual($uuid)
|
|
|
|
{
|
|
|
|
$visual = new Visual;
|
|
|
|
|
|
|
|
$var_data = $visual->getVisualVars($uuid);
|
|
|
|
|
|
|
|
$this->sql = $this->makeSql($var_data['data'],$this->subdataset);
|
|
|
|
|
|
|
|
//echo $this->sql;exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSql()
|
|
|
|
{
|
|
|
|
return $this->sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getData()
|
|
|
|
{
|
|
|
|
$rs = $this->db->query($this->sql);
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
while($row = $rs->fetch(\PDO::FETCH_ASSOC))
|
|
|
|
{
|
|
|
|
|
|
|
|
$row['utctime'] = $this->utcMsTime(strtotime($row['utctime']));
|
|
|
|
//var_dump($row);
|
|
|
|
$data[] = array(
|
|
|
|
$row['utctime'],
|
|
|
|
$row['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeSql($table,$fieldValue)
|
|
|
|
{
|
|
|
|
$sql = "SELECT
|
|
|
|
{$this->timeFiled} as utctime , \"$fieldValue\" as value
|
|
|
|
FROM $table
|
|
|
|
ORDER BY
|
|
|
|
extract(YEAR from \"{$this->timeFiled}\") ASC,
|
|
|
|
extract(MONTH from \"{$this->timeFiled}\") ASC,
|
|
|
|
extract(DAY from \"{$this->timeFiled}\") ASC,
|
|
|
|
extract(HOUR from \"{$this->timeFiled}\") ASC,
|
|
|
|
extract(MINUTE from \"{$this->timeFiled}\") ASC,
|
|
|
|
extract(SECOND from \"{$this->timeFiled}\") ASC
|
|
|
|
";
|
|
|
|
|
|
|
|
return $sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function utcMsTime($time=''){
|
|
|
|
if(empty($time))
|
|
|
|
return (time()+8*3600)*1000;
|
|
|
|
else
|
2014-06-13 06:14:27 +00:00
|
|
|
return ($time)*1000;
|
2014-06-13 06:00:56 +00:00
|
|
|
}
|
2014-05-12 06:53:21 +00:00
|
|
|
}
|