2013-05-06 09:01:14 +00:00
|
|
|
<?php
|
|
|
|
class Author extends Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
|
|
|
public $db; //传入PDO对象.
|
|
|
|
private $auth = NULL; //Zend_Auth 对象
|
|
|
|
|
|
|
|
//使用到的公共变量
|
|
|
|
public $tbl_metadata = "metadata"; //元数据
|
|
|
|
public $tbl_author = "mdauthor"; //数据作者表
|
2013-05-10 08:53:24 +00:00
|
|
|
public $tbl_user = "users";
|
2013-05-06 09:01:14 +00:00
|
|
|
|
|
|
|
function __construct($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
//检查前台用户对某条数据的权限
|
|
|
|
function checkAuthor($uuid,$uid=0)
|
|
|
|
{
|
|
|
|
if(empty($uid))
|
|
|
|
{
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
if($auth->hasIdentity())
|
|
|
|
{
|
|
|
|
$user = $auth->getIdentity();
|
|
|
|
$uid = $user->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!empty($uid))
|
|
|
|
{
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_author." WHERE uuid='$uuid' AND userid=$uid";
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$row = $rs->fetch(PDO::FETCH_BOTH);
|
|
|
|
if($row['status']>0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 08:53:24 +00:00
|
|
|
|
|
|
|
//获取某数据的所有作者
|
|
|
|
function getAuthor($uuid,$field = "")
|
|
|
|
{
|
|
|
|
$sql = "SELECT md.title,u.email FROM ".$this->tbl_metadata." md
|
|
|
|
LEFT JOIN ".$this->tbl_author." a ON md.uuid=a.uuid
|
|
|
|
LEFT JOIN ".$this->tbl_user." u ON a.userid=u.id
|
|
|
|
WHERE md.uuid='$uuid'";
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
|
|
|
|
if(empty($field))
|
|
|
|
{
|
|
|
|
return $rows;
|
|
|
|
}else{
|
|
|
|
$datas = array();
|
|
|
|
foreach($rows as $k=>$v)
|
|
|
|
{
|
|
|
|
$datas[] = $v[$field];
|
|
|
|
}
|
|
|
|
return $datas;
|
|
|
|
}
|
|
|
|
}
|
2013-05-06 09:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Literature extends Author
|
|
|
|
{
|
|
|
|
public function __construct($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
2013-06-27 06:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getOne($id,$uuid = ""){
|
|
|
|
$sql = "select m.uuid,r.reference,r.link,m.reftype,r.id as refid from reference r left join mdref m on r.id=m.refid where m.id=?";
|
|
|
|
$sth = $this->db->prepare($sql);
|
|
|
|
$sth->execute(array($id));
|
|
|
|
$row = $sth->fetch();
|
|
|
|
return $row;
|
|
|
|
}
|
2013-05-06 09:01:14 +00:00
|
|
|
|
|
|
|
function byuuid($uuid){
|
|
|
|
include_once("helper/view.php");
|
|
|
|
$uid = view::User('id');
|
2013-05-08 02:33:48 +00:00
|
|
|
$sql = "SELECT md.title,md.uuid,r.id,r.reference,r.link,mr.place,mr.id as mrid FROM mdref mr
|
2013-05-06 09:01:14 +00:00
|
|
|
LEFT JOIN metadata md ON md.uuid=mr.uuid
|
|
|
|
LEFT JOIN mdauthor a ON md.uuid=a.uuid
|
|
|
|
left join reference r on mr.refid=r.id
|
|
|
|
WHERE md.title IS NOT NULL AND a.userid=? and mr.uuid=? AND a.status=1
|
|
|
|
order by mr.place ASC,r.id DESC,md.ts_created desc
|
|
|
|
";
|
|
|
|
$sth = $this->db->prepare($sql);
|
|
|
|
$sth->execute(array($uid,$uuid));
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
2013-06-27 06:27:59 +00:00
|
|
|
function edit($mdrefid,$refid,$uuid,$content,$link,$reftype){
|
2013-05-06 09:01:14 +00:00
|
|
|
include_once("helper/dbh.php");
|
|
|
|
$dbh = new dbh($this->db);
|
|
|
|
|
|
|
|
$data = array(
|
2013-06-27 06:27:59 +00:00
|
|
|
'reference' => $content,
|
|
|
|
'link'=>$link
|
2013-05-06 09:01:14 +00:00
|
|
|
);
|
|
|
|
|
2013-06-27 06:27:59 +00:00
|
|
|
$s = $dbh->update("reference",$data," id=$refid ",false);
|
|
|
|
|
|
|
|
if($s)
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'reftype'=>$reftype
|
|
|
|
);
|
|
|
|
$d = $dbh->update("mdref",$data," id=$mdrefid ",false);
|
|
|
|
if($d)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-06 09:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function order($id,$order){
|
|
|
|
include_once("helper/dbh.php");
|
|
|
|
$dbh = new dbh($this->db);
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'place' => $order
|
|
|
|
);
|
|
|
|
|
2013-05-08 02:33:48 +00:00
|
|
|
$s = $dbh->update("mdref",$data," id=$id ",false);
|
2013-05-06 09:01:14 +00:00
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function bydata($keywords=""){
|
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
if($auth->hasIdentity())
|
|
|
|
{
|
|
|
|
$user = $auth->getIdentity();
|
|
|
|
$uid = $user->id;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT md.title,md.uuid,count(mr.id) as c FROM metadata md
|
|
|
|
LEFT JOIN mdref mr ON md.uuid=mr.uuid
|
|
|
|
LEFT JOIN mdauthor a ON md.uuid=a.uuid
|
|
|
|
left join reference r on mr.refid=r.id
|
|
|
|
WHERE md.title IS NOT NULL AND a.userid=$uid AND a.status=1";
|
|
|
|
if(!empty($keywords))
|
|
|
|
{
|
|
|
|
include_once('SimpleSearch.php');
|
|
|
|
$search=new SimpleSearch($keywords);
|
|
|
|
$where=$search->sql_expr(array("md.title","md.description"));
|
|
|
|
$sql.=' and '.$where;
|
|
|
|
}
|
|
|
|
$sql.=" group by md.uuid,md.title";
|
|
|
|
|
|
|
|
$sth = $this->db->query($sql);
|
|
|
|
$rows = $sth->fetchAll();
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
}
|