westdc-core/Westdc/Reference/Handler/RisHandler.php

84 lines
2.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Westdc\Reference\Handler;
use Zend\EventManager\EventInterface;
use Westdc\Service\AbstractServiceManager;
//事件中存在的操作
class RisHandler extends AbstractServiceManager
{
private $db; //传入PDO对象误
private $config; //全局配置
private $table;
public $tbl_maillog = ""; //邮件日志表
function __construct($db = NULL)
{
$this->dbService = $this->getServiceManager()->get('Db');
$this->db = $this->dbService->getPdo();
$this->table = new \stdClass;
$this->table->reference = "reference";
$this->table->reference_author = "ref_author";
$this->table->reference_tag = "ref_tag";
}
//检查ris中的文献是否已经存在
public function checkRisReference(EventInterface $e)
{
$ref = $e->getParam('ref');
$wheresql = array();
if(preg_match("/\'/",$ref['title']))
{
$ref['title'] = preg_replace("/\'/","''",$ref['title']);
}
$wheresql[] = " lower(title)=lower('{$ref['title']}') ";
$wheresql[] = " year='{$ref['year']}' ";
//暂时不使用期刊限制
/*if(isset($ref['publisher']))
{
$wheresql[] = " publisher='{$ref['publisher']}' ";
}*/
if(count($wheresql) > 0)
{
$wheresql = " WHERE ".join(" and ",$wheresql);
}else{
$wheresql = "";
}
$sql="select * from {$this->table->reference} $wheresql";
$sth=$this->db->query($sql);
$row=$sth->fetch();
$id=$row['id'];
if(!empty($row['id']))
{
return $id;
}else{
return 0;
}
}
//删除作者
public function deleteAuthor(EventInterface $e)
{
$id = $e->getParam('id');
$sql = "DELETE FROM {$this->table->reference_author} WHERE id=$id ";
return $this->db->exec($sql);
}
public function deleteTag(EventInterface $e)
{
$id = $e->getParam('id');
$sql = "DELETE FROM {$this->table->reference_tag} WHERE id=$id ";
return $this->db->exec($sql);
}
}