添加了ris导出功能

This commit is contained in:
Li Jianxuan 2013-11-04 09:04:07 +00:00
parent 6ae3223a84
commit 8d89e9f435
4 changed files with 246 additions and 0 deletions

View File

@ -2,6 +2,7 @@
use Helpers\View as view;
use Reference\Reference;
use Reference\Ris;
use Reference\RisOutput;
use Helpers\dbh;
use \Files\Files;
@ -1402,10 +1403,30 @@ class Admin_DataController extends Zend_Controller_Action
if(!empty($submit))
{
$mode = $this->_getParam('mode');
$risOutput = new RisOutput();
$preData = $risOutput->preRead($mode);
$risData = $risOutput->processArrayDataToRisData($preData);
$risText = $risOutput->output($risData);
view::Dump($risText);
}
}//ris output
if($ac == "ristest")
{
$this->_helper->viewRenderer('ref-ris');
$submit = $this->_getParam('submit');
if(!empty($submit))
{
$ris = new \Reference\Ris();
view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false);
}
}
}//文献管理 refAction()

View File

@ -0,0 +1,50 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/data">数据管理</a>');
$this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,"uploadify");
$this->theme->AppendPlus($this,'admin_plugin');
?>
<style>
table thead tr th {background:#EBF2F6;}
</style>
<div class="row-fluid">
<div class="span2">
<?= $this->partial('data/left.phtml'); ?>
</div>
<div class="span10">
<div>
<?= $this->partial('data/ref-nav.phtml',array('ac'=>$this->ac)); ?>
</div>
<?php if(!empty($this->error)) { ?>
<?= $this->error ?>
<?php } ?>
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<h3>RIS导出</h3>
<hr />
<div>
<?php if(!empty($this->years)) { ?>
按年份 :
<?php foreach($this->years as $k=>$v){ ?>
<a class="btn btn-info" href="?field[year]=<?= $v['year'] ?>"><?= empty($v['year']) ? "未知":$v['year'] ?>(<?= $v['num'] ?>)</a>
<?php } ?>
<hr />
<?php } ?>
</div>
<div>
其它方式:<a class="btn btn-info" href="?submit=1&mode=all">全部</a>
</div>
<?php } ?>
</div>
</div>
<!-- //页面内容 -->

View File

@ -575,4 +575,26 @@ class Reference
return;
}
//获得标签
public function getTagsByReference($id,$single = false)
{
if(is_numeric($id))
{
$sql = "SELECT * FROM {$this->table->reference_tag} WHERE id=$id";
$rs = $this->db->query($sql);
if(!$single)
{
return $rs->fetchAll();
}else{
foreach($rows = $rs->fetchAll() as $k=>$v)
{
$rows[$k] = (string)$v['tag'];
}
return $rows;
}
}
return;
}
}

View File

@ -0,0 +1,153 @@
<?php
namespace Reference;
use \Helpers\View as view;
use \Helpers\dbh;
//use \Reference\Listener\RisOutputListener as Listener;
use \Files\Files;
use \Reference\Reference;
use \Reference\Ris;
use \LibRIS\RISReader;
use \LibRIS\RISTags;
use \LibRIS\RISWriter;
class RisOutput
{
private $db; //传入PDO对象.
private $config; //站点设置
private $dbh;
protected $events = NULL;
public $table;
public $ris_records = NULL;
protected $ris;
public $attr;
public $attr_flip;
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 Listener();
//@$this->events()->attachAggregate($Listener);
$this->table = new \Helpers\Table();
}
public function events(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
//读取数据
public function preRead($mode = "all")
{
if($mode == "all")
{
$sql = "SELECT * FROM {$this->table->reference} ORDER BY year DESC,title ASC,id ASC";
$rs = $this->db->query($sql);
return $rs->fetchAll();
}
}//preRead
//将数据组成RIS数组格式
public function processArrayDataToRisData($arrayData,$risPrior = true,$mixAuthor = true,$mixTags = true)
{
if(!is_array($arrayData))
{
return false;
}
$risData = array();
if($risPrior === true)
{
$risReader = new RISReader();
}
$this->ris = new Ris();
$this->attr = $this->ris->attr;
$this->attr_flip = array_flip($this->ris->attr);
unset($this->ris);
$this->reference = new Reference();
foreach($arrayData as $k=>$v)
{
$risData[$k] = $this->transformToRis($v);
if($mixAuthor === true || $mixTags === true)
{
if($mixAuthor === true)
{
$author = $this->reference->getAuthorByReference($v['id'],true);
if(is_array($author) && count($author)>0)
{
$risData[$k] = array_merge($risData[$k],array("AU"=>$author));
}
unset($author);
}//mixAuthor
if($mixTags === true)
{
$tags = $this->reference->getTagsByReference($v['id'],true);
if(is_array($tags) && count($tags) > 0)
{
$risData[$k] = array_merge($risData[$k],array("KW"=>$tags));
}
unset($tags);
}
}
if(!is_array($risData[$k]) || count($risData[$k]) < 1)
{
unset($risData[$k]);
}
unset($arrayData[$k]);
}
return $risData;
}//processArrayDataToRisData
//单条记录的整编
public function transformToRis($record)
{
$arr = array();
foreach($record as $k=>$v)
{
if(!empty($v))
{
if(isset($this->attr_flip[$k]))
{
//echo $k ."-". $this->attr_flip[$k] . '-' .$v;
//echo "<br />";
$arr[$this->attr_flip[$k]] = array(0=>$v);
}
}
}
//echo "<br />";
return $arr;
}//transformToRis
//输出成文件
public function output($risData)
{
$risWirte = new RISWriter();
return @$risWirte->writeRecords($risData);
}//output
}