2013-04-24 11:07:25 +00:00
|
|
|
<?php
|
|
|
|
class Doi extends Zend_Controller_Plugin_Abstract
|
|
|
|
{
|
|
|
|
private $db; //传入PDO对象.
|
|
|
|
private $auth = NULL; //Zend_Auth 对象
|
|
|
|
|
|
|
|
//使用到的公共变量
|
|
|
|
public $tbl_doi = "datadoi";
|
|
|
|
|
|
|
|
function __construct($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:39:23 +00:00
|
|
|
function fetch($uid=0)
|
2013-04-24 11:07:25 +00:00
|
|
|
{
|
2013-04-24 13:39:23 +00:00
|
|
|
if(empty($uid))
|
|
|
|
{
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_doi." ORDER BY id DESC";
|
|
|
|
}else{
|
|
|
|
$sql = "SELECT doi.* FROM ".$this->tbl_doi." doi
|
|
|
|
LEFT JOIN mdauthor a ON doi.uuid=a.uuid
|
|
|
|
WHERE a.userid=".$uid." AND a.status>0
|
2013-05-02 05:21:20 +00:00
|
|
|
ORDER BY ts_published desc,ts_submitted desc,ts_created DESC
|
2013-04-24 13:39:23 +00:00
|
|
|
";
|
|
|
|
}
|
2013-04-24 11:07:25 +00:00
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$rows = $rs->fetchAll();
|
|
|
|
return $rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add($data){
|
|
|
|
include_once("helper/dbh.php");
|
|
|
|
$dbh = new dbh($this->db);
|
|
|
|
$this->data_process_in($data);
|
|
|
|
//include_once("helper/view.php");
|
|
|
|
//view::Dump($data);
|
|
|
|
return $dbh->insert($this->tbl_doi,$data);
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:39:23 +00:00
|
|
|
function update($data,$uuid,$uid=0){
|
|
|
|
include_once("data/Author.php");
|
|
|
|
$author = new Author($this->db);
|
|
|
|
if($author->checkAuthor($uuid,$uid)==false)
|
|
|
|
{
|
|
|
|
return "您没有权限";
|
|
|
|
}
|
2013-04-24 11:07:25 +00:00
|
|
|
$doi_info = $this->view($uuid);
|
|
|
|
if($doi_info == false)
|
|
|
|
{
|
|
|
|
return $this->add($data);
|
|
|
|
}else {
|
|
|
|
$this->data_process_in($data);
|
|
|
|
//include_once("helper/view.php");
|
|
|
|
//view::Dump($data);
|
|
|
|
include_once("helper/dbh.php");
|
|
|
|
$dbh = new dbh($this->db);
|
|
|
|
if(is_numeric($uuid))
|
|
|
|
{
|
|
|
|
$condition = " id=$uuid ";
|
|
|
|
}else{
|
|
|
|
$condition = " uuid='$uuid' ";
|
|
|
|
}
|
|
|
|
$state = $dbh->update($this->tbl_doi,$data,$condition,true);
|
|
|
|
|
|
|
|
if( $state == true)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return $state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_process_in(&$data){
|
|
|
|
$authors = array();
|
|
|
|
$orgs = array();
|
|
|
|
foreach($data['info'] as $k=>$v)
|
|
|
|
{
|
|
|
|
$authors[$v['order']] = $v['author'];
|
|
|
|
$orgs[$v['order']] = $v['organization'];
|
|
|
|
}
|
|
|
|
$authors = "{".join(",",$authors)."}";
|
|
|
|
$orgs = "{".join(",",$orgs)."}";
|
|
|
|
$data['authors'] = $authors;
|
|
|
|
$data['organization'] = $orgs;
|
|
|
|
unset($data['info']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function data_process_out(&$data){
|
|
|
|
$authors = str_replace("{",'',$data['authors']);
|
|
|
|
$authors = str_replace("}",'',$authors);
|
|
|
|
$authors = split(",",$authors);
|
|
|
|
$orgs = str_replace("{",'',$data['organization']);
|
|
|
|
$orgs = str_replace("}",'',$orgs);
|
|
|
|
$orgs = split(",",$orgs);
|
|
|
|
$info = array();
|
|
|
|
foreach($authors as $k=>$v)
|
|
|
|
{
|
|
|
|
$info[$k] = array(
|
|
|
|
'author'=>$authors[$k],
|
|
|
|
'organization'=>$orgs[$k],
|
2013-04-24 13:39:23 +00:00
|
|
|
'order'=> 5*count($authors)-($k*5)
|
2013-04-24 11:07:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
//include_once("helper/view.php");
|
|
|
|
//view::Dump($info);
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function view($id)
|
|
|
|
{
|
|
|
|
if(is_numeric($id))
|
|
|
|
{
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_doi." WHERE id=$id";
|
|
|
|
}else{
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_doi." WHERE uuid='$id'";
|
|
|
|
}
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$row = $rs->fetch();
|
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:39:23 +00:00
|
|
|
function delete($id,$uid=0){
|
2013-04-24 11:07:25 +00:00
|
|
|
if(!is_numeric($id))
|
|
|
|
{
|
|
|
|
return "参数错误";
|
|
|
|
}
|
2013-04-24 13:39:23 +00:00
|
|
|
if($uid != 0){
|
|
|
|
$sql = "SELECT uuid FROM ".$this->tbl_doi." WHERE id=$id";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$row = $rs->fetch();
|
|
|
|
if(isset($row['uuid']) && !empty($row['uuid'])){
|
|
|
|
include_once("data/Author.php");
|
|
|
|
$author = new Author($this->db);
|
|
|
|
if($author->checkAuthor($row['uuid'],$uid)==false)
|
|
|
|
{
|
|
|
|
return "您没有权限";
|
|
|
|
}
|
|
|
|
$condition = " id=$id ";
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_doi." WHERE $condition";
|
|
|
|
return $this->db->exec($sql);
|
|
|
|
}else{
|
|
|
|
return "该记录不存在";
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$condition = " id=$id ";
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_doi." WHERE $condition";
|
|
|
|
return $this->db->exec($sql);
|
|
|
|
}
|
2013-04-24 11:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _getParams(Zend_Controller_Request_Abstract $request)
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'doi' => trim($request->getParam('doi')),
|
|
|
|
'uuid' => trim($request->getParam('uuid')),
|
|
|
|
'publisher' => trim($request->getParam('publisher')),
|
|
|
|
'url' => trim($request->getParam('url')),
|
|
|
|
'title' => trim($request->getParam('title')),
|
|
|
|
'info'=>$_POST['info']
|
|
|
|
);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkinfo($info){
|
|
|
|
if(!is_array($info)){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
foreach($info as $k=>$v)
|
|
|
|
{
|
|
|
|
if(empty($v['author']) && empty($v['organization']) && empty($v['order']))
|
|
|
|
{
|
|
|
|
unset($info[$k]);
|
|
|
|
}else{
|
|
|
|
if(empty($v['author']))
|
|
|
|
{
|
|
|
|
return "请输入 $k 中的作者";
|
|
|
|
}
|
|
|
|
if(empty($v['organization']))
|
|
|
|
{
|
|
|
|
return "请输入 $k 中的单位";
|
|
|
|
}
|
|
|
|
if(empty($v['order']))
|
|
|
|
{
|
|
|
|
return "请输入 $k 中的排序";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sksort($array,$key,$type=SORT_DESC) {
|
|
|
|
$sortArray = array();
|
|
|
|
|
|
|
|
foreach($array as $v){
|
|
|
|
foreach($v as $key=>$value){
|
|
|
|
if(!isset($sortArray[$key])){
|
|
|
|
$sortArray[$key] = array();
|
|
|
|
}
|
|
|
|
$sortArray[$key][] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(array_multisort($sortArray[$key],$type,$array))
|
|
|
|
{
|
|
|
|
return $array;
|
|
|
|
}else{
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|