2013-09-26 08:26:29 +00:00
|
|
|
<?php
|
|
|
|
namespace Reference;
|
|
|
|
|
|
|
|
use \Helpers\View as view;
|
|
|
|
use \Helpers\dbh;
|
|
|
|
use \Reference\Listener\ReferenceListener;
|
|
|
|
use \Files\Files;
|
2013-09-29 10:06:49 +00:00
|
|
|
use \Search\Search;
|
2013-09-26 08:26:29 +00:00
|
|
|
|
|
|
|
class Reference
|
|
|
|
{
|
|
|
|
private $db; //传入PDO对象.
|
|
|
|
private $config; //站点设置
|
|
|
|
|
|
|
|
protected $events = NULL;
|
|
|
|
public $table;
|
2013-09-29 10:06:49 +00:00
|
|
|
public $keyword;
|
2013-09-26 08:26:29 +00:00
|
|
|
|
|
|
|
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 ReferenceListener();
|
|
|
|
@$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 reference($id = 0)
|
|
|
|
{
|
|
|
|
$data = $this->getReferenceParam();
|
|
|
|
|
|
|
|
$params = compact('data');
|
|
|
|
$results = $this->events()->trigger('submit.checkParam', $this, $params);
|
|
|
|
$cache_data = $results->bottom();
|
|
|
|
|
|
|
|
if($cache_data !== true)
|
|
|
|
{
|
|
|
|
return $cache_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
$results = $this->events()->trigger('submit.processData', $this, $params);
|
|
|
|
$data = $results->bottom();
|
|
|
|
|
|
|
|
unset($data['submit']);
|
|
|
|
|
|
|
|
$dbh = new dbh();
|
|
|
|
|
|
|
|
if(empty($id))
|
|
|
|
{
|
|
|
|
$id = $dbh->insert($this->table->reference,$data,true);
|
|
|
|
}else{
|
|
|
|
if(!$dbh->update($this->table->reference,$data," id=$id ",true))
|
|
|
|
{
|
|
|
|
return "修改失败!请重试";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($id) && is_numeric($id))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return "修改失败";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//获得参数
|
|
|
|
public function getReferenceParam(\Zend_Controller_Request_Abstract $request = NULL)
|
|
|
|
{
|
|
|
|
$request = new \Zend_Controller_Request_Http();
|
|
|
|
$data = array(
|
2013-09-29 10:06:49 +00:00
|
|
|
'reference' => trim($request->getParam('reference')),
|
|
|
|
'link' => trim($request->getParam('link')),
|
|
|
|
'publisher' => trim($request->getParam('publisher')),
|
|
|
|
'year' => (int)$request->getParam('year'),
|
|
|
|
'title' => trim($request->getParam('title')),
|
|
|
|
'ris' => trim($request->getParam('ris')),
|
|
|
|
'attid' => (int)$request->getParam('attid')
|
2013-09-26 08:26:29 +00:00
|
|
|
);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
//上传文献PDF
|
2013-09-29 10:06:49 +00:00
|
|
|
public function uploadReferencePdf($file,$autoread = false)
|
2013-09-26 08:26:29 +00:00
|
|
|
{
|
|
|
|
$files = new Files();
|
2013-09-28 06:16:55 +00:00
|
|
|
$file_info = $files->upload($file,'literature/',true);
|
2013-09-26 08:26:29 +00:00
|
|
|
|
|
|
|
if(isset($file_info['error']) && !empty($file_info['error']))
|
|
|
|
{
|
|
|
|
return array("error" => $file_info['error']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_data = array(
|
|
|
|
'filename' => $file_info['file_url'],
|
2013-09-28 06:16:55 +00:00
|
|
|
'filetype' => 'literature',
|
2013-09-26 08:26:29 +00:00
|
|
|
'filedesc' => $file_info['file_mime'],
|
|
|
|
'userid' => view::User('id'),
|
|
|
|
'filesize' => $file_info['file_size'],
|
|
|
|
'realname' => $file_info['realname']
|
|
|
|
);
|
|
|
|
|
|
|
|
$dbh = new dbh();
|
|
|
|
|
|
|
|
$file_id = $dbh->insert($this->table->attachments,$file_data,true);
|
|
|
|
$file_data['id'] = $file_id;
|
|
|
|
|
2013-09-29 10:06:49 +00:00
|
|
|
if($autoread)
|
|
|
|
{
|
|
|
|
$params = compact('file_data');
|
|
|
|
$results = $this->events()->trigger('upload.insertToReferenceTable', $this, $params);
|
|
|
|
$cache_data = $results->bottom();
|
|
|
|
$file_data = array_merge($file_data,$cache_data);
|
|
|
|
}
|
|
|
|
|
2013-09-26 08:26:29 +00:00
|
|
|
return $file_data;
|
|
|
|
}
|
|
|
|
|
2013-09-29 10:06:49 +00:00
|
|
|
//通过文件名自动提取文章标题
|
|
|
|
public function getReferenceTitleFromFilenName($filename)
|
|
|
|
{
|
|
|
|
$file = new Files();
|
|
|
|
$title = str_replace( ".".$file->getFileTextExt($filename),"",$filename);
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
2013-09-26 08:26:29 +00:00
|
|
|
//删除文献文件
|
|
|
|
public function deleteReferenceAttchment($attid)
|
|
|
|
{
|
|
|
|
if(empty($attid) || !is_numeric($attid))
|
|
|
|
{
|
|
|
|
return array("error"=>"参数错误");
|
|
|
|
}
|
|
|
|
|
|
|
|
$files = new Files();
|
|
|
|
$status = $files->delete($attid);
|
|
|
|
|
|
|
|
if($status !== true)
|
|
|
|
{
|
|
|
|
return array("error"=>$status);
|
|
|
|
}else{
|
|
|
|
return array("success"=>1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//所有文献
|
|
|
|
public function fetchReferences()
|
|
|
|
{
|
2013-09-29 10:06:49 +00:00
|
|
|
if(!empty($this->keyword))
|
|
|
|
{
|
|
|
|
$search = new Search();
|
|
|
|
$keyword = $search->splitKeyword($this->keyword);
|
|
|
|
}
|
2013-09-26 08:26:29 +00:00
|
|
|
$sql = "SELECT * FROM {$this->table->reference} ORDER BY id DESC";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
return $rs->fetchAll();
|
|
|
|
}
|
|
|
|
|
2013-09-28 03:21:40 +00:00
|
|
|
//获取专题数据的文献
|
|
|
|
public function fetchThemeReferences($code)
|
|
|
|
{
|
2013-09-29 10:06:49 +00:00
|
|
|
$sql="select distinct ref.* from mdref r left join {$this->table->reference} ref on r.refid=ref.id
|
|
|
|
left join datasource ds on r.uuid=ds.uuid left join {$this->table->source} s on s.id=ds.sourceid
|
2013-09-28 03:24:44 +00:00
|
|
|
where s.code='$code'
|
2013-09-28 03:21:40 +00:00
|
|
|
order by ref.year,ref.title";
|
|
|
|
$rs=$this->db->query($sql);
|
2013-09-28 03:22:48 +00:00
|
|
|
return $rs->fetchAll();
|
2013-09-28 03:21:40 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 08:26:29 +00:00
|
|
|
//单条文献的信息
|
|
|
|
public function getOneReferenceData($id)
|
|
|
|
{
|
|
|
|
if(empty($id) || !is_numeric($id))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM {$this->table->reference} WHERE id=$id LIMIT 1";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$row = $rs->fetch();
|
2013-09-28 02:17:33 +00:00
|
|
|
if ($row['attid'])
|
|
|
|
{
|
|
|
|
$files = new Files();
|
|
|
|
$attfile = $files->getOne($row['attid']);
|
2013-09-26 08:26:29 +00:00
|
|
|
|
2013-09-28 02:17:33 +00:00
|
|
|
$row['file'] = $attfile;
|
|
|
|
}
|
2013-09-26 08:26:29 +00:00
|
|
|
return $row;
|
|
|
|
}
|
2013-09-27 07:21:14 +00:00
|
|
|
|
|
|
|
//获得reference类型的附件
|
|
|
|
public function getReferenceFiles()
|
|
|
|
{
|
|
|
|
$sql = "SELECT att.*,ref.attid,ref.id as refid FROM {$this->table->attachments} att
|
|
|
|
LEFT JOIN {$this->table->reference} ref ON att.id=ref.attid
|
2013-09-28 06:16:55 +00:00
|
|
|
WHERE att.filetype='literature'";
|
2013-09-27 07:21:14 +00:00
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
$rows = $rs->fetchAll();
|
|
|
|
return $rows;
|
|
|
|
}
|
2013-09-29 10:06:49 +00:00
|
|
|
|
|
|
|
//删除文献
|
|
|
|
public function deleteReference($id,$delete_att = false)
|
|
|
|
{
|
|
|
|
if(empty($id) || !is_numeric($id))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($delete_att == false)
|
|
|
|
{
|
|
|
|
$sql = "DELETE FROM {$this->table->reference} WHERE id=$id";
|
|
|
|
return $this->db->exec($sql);
|
|
|
|
}else{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-09-26 08:26:29 +00:00
|
|
|
|
2013-09-28 02:17:33 +00:00
|
|
|
}
|