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

139 lines
2.5 KiB
PHP

<?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;
}
}