add class Ris in Reference module,remove useless files

This commit is contained in:
Jianxuan Li 2014-12-30 14:44:39 +08:00
parent c66f62089b
commit 39fb5b515b
7 changed files with 78 additions and 302 deletions

View File

@ -1,15 +0,0 @@
<?php
namespace Reference\Event;
interface ReferenceEvent
{
public function checkReferenceParam(\Zend_EventManager_Event $e);
public function processReferenceData(\Zend_EventManager_Event $e);
public function insertToReferenceTable(\Zend_EventManager_Event $e);
public function checkMdrefParam(\Zend_EventManager_Event $e);
public function processMdrefData(\Zend_EventManager_Event $e);
}

View File

@ -1,9 +0,0 @@
<?php
namespace Reference\Event;
interface RisEvent
{
public function checkRisReference(\Zend_EventManager_Event $e);
public function deleteAuthor(\Zend_EventManager_Event $e);
public function deleteTag(\Zend_EventManager_Event $e);
}

View File

@ -1,138 +0,0 @@
<?php
namespace Reference\Handler;
use \Helpers\View as view;
use \Helpers\dbh;
use \Helpers\Table;
use \Files\Files;
use \Reference\Reference;
//事件中存在的操作
class ReferenceHandler implements \Reference\Event\ReferenceEvent
{
private $db; //传入PDO对象误
private $config; //全局配置
public $table;
public $tbl_maillog = ""; //邮件日志表
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
$this->table = new Table();
}
public function checkReferenceParam(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(!is_array($data))
{
return "参数错误";
}
if(empty($data["title"]))
{
return "请输入标题";
}
if(empty($data['reference']))
{
return "请输入前台引用方式,并且唯一";
}
return true;
}
public function processReferenceData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(empty($data['attid']))
{
$data['attid'] = 0;
}
return $data;
}
public function insertToReferenceTable(\Zend_EventManager_Event $e)
{
$att = $e->getParam('file_data');
$reference = new Reference();
$title = $reference->getReferenceTitleFromFilenName($att['realname']);
$data = array(
'title'=>$title,
'attid'=>$att['id'],
'reference'=>$title.'---'.date("Y-m-d H:i:s").".".microtime().rand()
);
$dbh = new dbh();
$cache_data = array();
$cache_data['ref_id'] = $dbh->insert($this->table->reference,$data,true);
$cache_data['ref_title'] = $title;
return $cache_data;
}
public function checkMdrefParam(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(!is_array($data))
{
return "参数错误";
}
if(empty($data["refid"]))
{
return "请填写文献ID";
}
if(empty($data['uuid']))
{
return "请填写UUID";
}
if(!view::isUuid($data['uuid']))
{
return "UUID格式不正确";
}
if(($data['reftype']===''))
{
return "请选择文献类型";
}
return true;
}
public function processMdrefData(\Zend_EventManager_Event $e)
{
$data = $e->getParam('data');
if(empty($data['place']))
{
$data['place'] = 0;
}
if(!is_numeric($data['place']))
{
$data['place'] = 0;
}
return $data;
}
}

View File

@ -1,36 +1,31 @@
<?php
namespace Reference\Handler;
namespace Westdc\Reference\Handler;
use \Helpers\View as view;
use \Helpers\dbh;
use \Helpers\Table;
use \Files\Files;
use \Reference\Reference;
use Zend\EventManager\EventInterface;
use Westdc\Service\AbstractServiceManager;
//事件中存在的操作
class RisHandler implements \Reference\Event\RisEvent
class RisHandler extends AbstractServiceManager
{
private $db; //传入PDO对象误
private $config; //全局配置
public $table;
private $table;
public $tbl_maillog = ""; //邮件日志表
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->dbService = $this->getServiceManager()->get('Db');
$this->db = $this->dbService->getPdo();
$this->config = \Zend_Registry::get('config');
$this->table = new Table();
$this->table = new \stdClass;
$this->table->reference = "reference";
$this->table->reference_author = "ref_author";
$this->table->reference_tag = "ref_tag";
}
//检查ris中的文献是否已经存在
public function checkRisReference(\Zend_EventManager_Event $e)
public function checkRisReference(EventInterface $e)
{
$ref = $e->getParam('ref');
@ -71,21 +66,19 @@ class RisHandler implements \Reference\Event\RisEvent
}
//删除作者
public function deleteAuthor(\Zend_EventManager_Event $e)
public function deleteAuthor(EventInterface $e)
{
$id = $e->getParam('id');
$ref = new Reference();
return $ref->deleteReferenceAuthor($id);
$sql = "DELETE FROM {$this->table->reference_author} WHERE id=$id ";
return $this->db->exec($sql);
}
public function deleteTag(\Zend_EventManager_Event $e)
public function deleteTag(EventInterface $e)
{
$id = $e->getParam('id');
$ref = new Reference();
return $ref->deleteReferenceTag($id);
$sql = "DELETE FROM {$this->table->reference_tag} WHERE id=$id ";
return $this->db->exec($sql);
}
}

View File

@ -1,48 +0,0 @@
<?php
namespace Reference\Listener;
use Reference\Handler\ReferenceHandler;
class ReferenceListener implements \Zend_EventManager_ListenerAggregate
{
private $event;
function __construct()
{
$this->event = new \Zend_EventManager_EventManager();
}
public function attach(\Zend_EventManager_EventCollection $events)
{
$this->listeners[] = $events->attach('submit.before', function($e){
$data = $e->getParam('data');
if(!is_array($data))
return "参数错误";
if(empty($data["title"]))
return "请输入标题";
if(empty($data['reference']))
return "请输入前台引用方式,并且唯一";
return true;
}, 100); //参数检查
$this->listeners[] = $events->attach('submit.processData', function($e){
$data = $e->getParam('data');
if(empty($data['attid']))
{
$data['attid'] = 0;
}
return $data;
}, 50);
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
}

View File

@ -1,27 +1,29 @@
<?php
namespace Reference\Listener;
namespace Westdc\Reference\Listener;
use Reference\Handler\RisHandler;
use Westdc\Reference\Handler\RisHandler;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\EventManager\EventManagerInterface;
class RisListener implements \Zend_EventManager_ListenerAggregate
class RisListener implements ListenerAggregateInterface
{
private $event;
function __construct()
{
$this->event = new \Zend_EventManager_EventManager();
}
public function attach(\Zend_EventManager_EventCollection $events)
protected $listeners = array();
public function attach(EventManagerInterface $events)
{
$Handler = new RisHandler();
$events->attach('checkLoad', array($Handler, 'checkRisReference'), 100);
$events->attach('deleteAuthor', array($Handler, 'deleteAuthor'), 100);
$events->attach('deleteTag', array($Handler, 'deleteTag'), 100);
$events->attach('delete.after', array($Handler, 'deleteAuthor'), 100);
$events->attach('delete.after', array($Handler, 'deleteTag'), 80);
}
public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $index => $listener) {
if ($events->detach($listener)) {
unset($this->listeners[$index]);
}
}
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
}

View File

@ -1,49 +1,39 @@
<?php
namespace Reference;
namespace Westdc\Reference;
use \Helpers\View as view;
use \Helpers\dbh;
use \Reference\Listener\RisListener;
use \Files\Files;
use \LibRIS\RISReader;
use \LibRIS\RISTags;
use \LibRIS\RISWriter;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Westdc\EventModel\AbstractEventManager;
use Westdc\Reference\Listener\RisListener;
use LibRIS\RISReader;
use LibRIS\RISTags;
use LibRIS\RISWriter;
class Ris
class Ris extends AbstractEventManager implements ServiceManagerAwareInterface
{
private $db; //传入PDO对象.
private $config; //站点设置
private $dbh;
protected $events = NULL;
protected $serviceManager;
public $table;
public $ris_records = NULL;
function __construct($db = NULL,$mail = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
$Listener = new RisListener();
@$this->events()->attachAggregate($Listener);
$this->table = new \Helpers\Table();
}
public function events(\Zend_EventManager_EventCollection $events = NULL)
private $dbh;
public function setServiceManager(ServiceManager $serviceManager)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
$this->serviceManager = $serviceManager;
$this->init();
return $this;
}
public function init()
{
$Listener = new RisListener;
$this->getEventManager()->attachAggregate($Listener);
$this->table = new \stdClass;
$this->table->reference = "reference";
$this->table->reference_author = "ref_author";
$this->table->reference_tag = "ref_tag";
}
//ris导入
@ -156,8 +146,9 @@ class Ris
{
return false;
}
$dbh = $this->dbh = new dbh();
$dbService = $this->serviceManager->get('Db');
$dbh = $this->dbh = $dbService->getDbh();
foreach($data as $k=>$ref)
{
@ -171,14 +162,13 @@ class Ris
$ref['ris'] = $this->makeRisData(array(0=>$this->ris_records[$k]));
$results = $this->events()->trigger('checkLoad', $this, compact('ref'));
$results = $this->getEventManager()->trigger('checkLoad', $this, compact('ref'));
$id = $results->bottom();
if ($id > 0)
{
$this->unsetVar($ref);
$this->events()->trigger('deleteAuthor', $this, compact('id'));
$this->events()->trigger('deleteTag', $this, compact('id'));
$this->getEventManager()->trigger('delete.after', $this, compact('id'));
unset($ref['reference']);
@ -212,13 +202,14 @@ class Ris
$ref['ris'] = $this->makeRisData(array(0=>$this->ris_records[0]));
$this->events()->trigger('deleteAuthor', $this, compact('id'));
$this->events()->trigger('deleteTag', $this, compact('id'));
$this->getEventManager()->trigger('delete.after', $this, compact('id'));
$this->getEventManager()->trigger('delete.after', $this, compact('id'));
$this->unsetVar($ref);
if(isset($ref['reference'])) unset($ref['reference']);
$this->dbh = $dbh = new dbh();
$dbService = $this->serviceManager->get('Db');
$this->dbh = $dbh = $dbService->getDbh();
if($dbh->update($this->table->reference,$ref," id=$id "))
{