284 lines
7.0 KiB
PHP
284 lines
7.0 KiB
PHP
<?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;
|
||
}
|
||
|
||
function fetch($uid=0,$keyword='')
|
||
{
|
||
$wheresql=' 1=1 ';
|
||
if(!empty($keyword))
|
||
{
|
||
if(preg_match("/\'/",$keyword))
|
||
{
|
||
$keyword = preg_replace("/\'/","''",$keyword);
|
||
}
|
||
$wheresql.=" and d.title like '%$keyword%'";
|
||
}
|
||
if(empty($uid))
|
||
{
|
||
$sql = "SELECT * FROM ".$this->tbl_doi." d where ".$wheresql."ORDER BY d.ts_published desc,d.ts_submitted desc,d.ts_created DESC";
|
||
}else{
|
||
$sql = "SELECT d.* FROM ".$this->tbl_doi." d
|
||
LEFT JOIN mdauthor a ON d.uuid=a.uuid
|
||
WHERE a.userid=".$uid." AND a.status>0 and ".$wheresql."
|
||
ORDER BY d.ts_published desc,d.ts_submitted desc,d.ts_created DESC
|
||
";
|
||
}
|
||
$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);
|
||
}
|
||
|
||
function update($data,$uuid,$uid=0){
|
||
if(!empty($uid))
|
||
{
|
||
include_once("data/Author.php");
|
||
$author = new Author($this->db);
|
||
if($author->checkAuthor($uuid,$uid)==false)
|
||
{
|
||
return "您没有权限";
|
||
}
|
||
}
|
||
$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 update_en($data,$uuid,$uid=0){
|
||
if(!empty($uid))
|
||
{
|
||
include_once("data/Author.php");
|
||
$author = new Author($this->db);
|
||
if($author->checkAuthor($uuid,$uid)==false)
|
||
{
|
||
return "您没有权限";
|
||
}
|
||
}
|
||
$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' ";
|
||
}
|
||
$data['publisher_en']=$data['publisher'];
|
||
$data['publisher']='';
|
||
$data['title_en']=$data['title'];
|
||
$data['title']='';
|
||
$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();
|
||
$authors_en = array();
|
||
$orgs_en = array();
|
||
foreach($data['info'] as $k=>$v)
|
||
{
|
||
$authors[$v['order']] = str_replace(",",",",$v['author']);
|
||
$orgs[$v['order']] = str_replace(",",",",$v['organization']);
|
||
$authors_en[$v['order']] = str_replace(",",",",$v['author_en']);
|
||
$orgs_en[$v['order']] = str_replace(",",",",$v['organization_en']);
|
||
}
|
||
$authors = "{".join(",",$authors)."}";
|
||
$orgs = "{".join(",",$orgs)."}";
|
||
$authors_en = "{".join(",",$authors_en)."}";
|
||
$orgs_en = "{".join(",",$orgs_en)."}";
|
||
$data['authors'] = $authors;
|
||
$data['organization'] = $orgs;
|
||
$data['author_en'] = $authors_en;
|
||
$data['organization_en'] = $orgs_en;
|
||
unset($data['info']);
|
||
}
|
||
|
||
function data_process_out(&$data){
|
||
$authors = $this->array_split($data['authors']);
|
||
$orgs = $this->array_split($data['organization']);
|
||
$authors_en = $this->array_split($data['author_en']);
|
||
$orgs_en = $this->array_split($data['organization_en']);
|
||
$info = array();
|
||
foreach($authors as $k=>$v)
|
||
{
|
||
$info[$k] = array(
|
||
'author'=>str_replace("\"","",$authors[$k]),
|
||
'organization'=>str_replace("\"","",$orgs[$k]),
|
||
'author_en'=>str_replace("\"","",$authors_en[$k]),
|
||
'organization_en'=>str_replace("\"","",$orgs_en[$k]),
|
||
'order'=> count($authors)+($k-1)
|
||
);
|
||
}
|
||
//include_once("helper/view.php");
|
||
//view::Dump($info);
|
||
return $info;
|
||
}
|
||
|
||
function array_split($a){
|
||
/*$a = str_replace("{",'',$a);
|
||
$a = str_replace("}",'',$a);
|
||
$a = explode(",",$a); */
|
||
return explode(',',substr($a,1,-1));
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
function delete($id,$uid=0){
|
||
if(!is_numeric($id))
|
||
{
|
||
return "参数错误";
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
|
||
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')),
|
||
'title_en' => trim($request->getParam('title_en')),
|
||
'publisher_en' => trim($request->getParam('publisher_en')),
|
||
'info'=>$_POST['info']
|
||
);
|
||
return $data;
|
||
}
|
||
|
||
function checkinfo($info){
|
||
if(!is_array($info)){
|
||
return NULL;
|
||
}
|
||
foreach($info as $k=>$v)
|
||
{
|
||
if(empty($v['order']) && empty($v['author_en']) && empty($v['organization_en']) )
|
||
{
|
||
unset($info[$k]);
|
||
}else{
|
||
if(empty($v['author_en']))
|
||
{
|
||
return "请输入 $k 中的作者英文";
|
||
}
|
||
if(empty($v['organization_en']))
|
||
{
|
||
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;
|
||
}
|
||
}
|
||
|
||
}
|