westdc-zf1/application/module/Westdc/Metadata/Statistics.php

91 lines
1.9 KiB
PHP
Raw Normal View History

2014-06-12 08:39:57 +00:00
<?php
namespace Westdc\Metadata;
class Statistics extends Metadata
{
function __construct()
{
parent::__construct();
}
public function total()
{
$sql = "SELECT count(id) as num FROM {$this->tbl_metadata}";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['num'];
}
public function getMetadataCountByDay($utcTimeReplace = false)
{
$sql = "SELECT
extract(YEAR from ts_created) as y ,
extract(MONTH from ts_created) as m ,
extract(DAY from ts_created) as d,
count(id) as value
FROM {$this->tbl_metadata}
GROUP BY
extract(YEAR from ts_created),
extract(MONTH from ts_created),
extract(DAY from ts_created)
ORDER BY
extract(YEAR from ts_created) ASC,
extract(MONTH from ts_created) ASC,
extract(DAY from ts_created) ASC";
$rs = $this->db->query($sql);
//输出highchart用得数据
if($utcTimeReplace !== false)
{
$data = [];
while($row = $rs->fetch())
{
$data[] = [mktime(0,0,0,$row['m'],$row['d'],$row['y'])*1000,$row['value']];
}
return $data;
}
//输出表格数据
else{
return $rs->fetchAll();
}
}
public function review($type = "accept")
{
switch($type){
case "accept":
$sql = "select count(m.uuid) as num from mdstatus m
right join {$this->tbl_metadata} md on md.uuid=m.uuid
where m.status in (1,2,3,4)";
break;
case "finish":
$sql = "select count(m.uuid) as num from mdstatus m
right join {$this->tbl_metadata} md on md.uuid=m.uuid
where m.status = 5";
break;
}
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['num'];
}
public function visual()
{
$sql = "SELECT count(md.id) as num FROM {$this->tbl_metadata} md
LEFT JOIN datavisual v ON v.uuid = md.uuid
WHERE v.uuid IS NOT NULL";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['num'];
}
}