91 lines
1.9 KiB
PHP
91 lines
1.9 KiB
PHP
<?php
|
|
namespace Westdc\Metadata;
|
|
|
|
use Sookon\Helpers\View as view;
|
|
use Sookon\Helpers\Dbh as dbh;
|
|
use Sookon\Helpers\Pdo;
|
|
use Sookon\Helpers\Config;
|
|
use Sookon\Helpers\Table;
|
|
use Zend\Http\PhpEnvironment\Request;
|
|
|
|
class Metadata
|
|
{
|
|
private $db; //传入PDO对象
|
|
private $config; //站点设置
|
|
private $table;
|
|
|
|
public $opt;
|
|
|
|
protected $events = NULL;
|
|
|
|
function __construct()
|
|
{
|
|
$this->db = new Pdo;
|
|
$this->config = Config::get();
|
|
$this->table = new Table;
|
|
|
|
$this->opt = new \stdClass();
|
|
|
|
$this->opt->sort = "DESC";
|
|
$this->opt->logic = "AND";
|
|
}
|
|
|
|
public function fetchAll()
|
|
{
|
|
$wheresql = array();
|
|
|
|
if(isset($this->opt->where) && !empty($this->opt->where))
|
|
$wheresql = array_merge($wheresql,$this->opt->where);
|
|
|
|
if(count($wheresql)>0)
|
|
{
|
|
$wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." ");
|
|
}else{
|
|
$wheresql = '';
|
|
}
|
|
|
|
if(!empty($this->opt->order))
|
|
{
|
|
$order = $this->opt->order;
|
|
}else{
|
|
$order = "m.id";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
m.*,md.viewed, ds.id as datasetid
|
|
FROM {$this->table->metadata} m
|
|
LEFT join {$this->table->metadata_stat} md on m.uuid=md.uuid
|
|
LEFT JOIN mdstatus st ON md.uuid=st.uuid
|
|
left join dataset ds on m.uuid=ds.uuid
|
|
$wheresql
|
|
ORDER BY $order {$this->opt->sort}";
|
|
|
|
if(!empty($this->opt->start))
|
|
{
|
|
$sql .= " START {$this->opt->start} ";
|
|
}
|
|
|
|
if(!empty($this->opt->limit)){
|
|
$sql .= " LIMIT {$this->opt->limit} ";
|
|
}
|
|
//view::Dump($sql);
|
|
$rs = $this->db->query($sql);
|
|
return $rs->fetchAll();
|
|
}
|
|
|
|
public function fetch($id)
|
|
{
|
|
if(is_numeric($id))
|
|
{
|
|
$sql = "SELECT * FROM {$this->table->metadata} WHERE id=$id";
|
|
}else if(\Sookon\Helpers\Uuid::test($id)){
|
|
$sql = "SELECT * FROM {$this->table->metadata} WHERE uuid='$id'";
|
|
}else{
|
|
return false;
|
|
}
|
|
|
|
$rs = $this->db->query($sql);
|
|
return $rs->fetch();
|
|
}
|
|
|
|
} |