westdc-zf1/vendor/Westdc/Metadata/Extra/Unit.php

83 lines
2.1 KiB
PHP

<?php
namespace Westdc\Metadata\Extra;
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 Unit
{
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 getMetadataByUnit($unit)
{
$sql = "SELECT * FROM metadata as m
LEFT JOIN role as r ON m.uuid=r.uuid
LEFT JOIN responsible as s ON r.resid=s.id
WHERE r.role='pointOfContact' AND s.organisation='$unit'
";
$rs = $this->db->query($sql);
return $rs->fetchAll();
$select=$this->db->select();
$select->from('normalmetadata as m','*')->joinLeft('role as r','m.uuid=r.uuid')->joinLeft('responsible as s','r.resid=s.id')->where('r.role=?','pointOfContact')->where('s.organisation=?',$name)->order('m.title')->limitPage($page,$this->limit);
return $this->db->fetchAll($select);
}
public function getCountByUnit($unit)
{
$sql = "select count(m.id)
from metadata m left join role r on m.uuid=r.uuid
left join responsible s on r.resid=s.id
where r.role='pointOfContact' and s.organisation='$unit'";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['count'];
}
public function fetchAll()
{
$sql = "select distinct responsible.organisation from responsible left join role on role.resid=responsible.id where role.role='pointOfContact'";
$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();
}
}