fixed errors in Reference module,add new functions in File service
This commit is contained in:
parent
6e2cfad2cb
commit
c66f62089b
|
@ -41,4 +41,55 @@ class File implements ServiceManagerAwareInterface{
|
|||
return $filetype;
|
||||
}
|
||||
|
||||
//获取某个文件的信息
|
||||
public function get($id)
|
||||
{
|
||||
if(!is_numeric($id) || $id<1)
|
||||
return false;
|
||||
|
||||
$dbService = $this->serviceManager->get('Db');
|
||||
$db = $dbService->getPdo();
|
||||
$sql = "SELECT * FROM attachments WHERE id=$id";
|
||||
$rs = $db->query($sql);
|
||||
|
||||
return $rs->fetch();
|
||||
}
|
||||
|
||||
//删除文件
|
||||
public function delete($id)
|
||||
{
|
||||
if(!is_numeric($id) || $id<1)
|
||||
return false;
|
||||
|
||||
$file_info = $this->get($id);
|
||||
|
||||
$basePath = $this->getFileSaveDirByType($file_info['filetype']);
|
||||
|
||||
@unlink($basePath . $file_info['filename']);
|
||||
|
||||
$dbService = $this->serviceManager->get('Db');
|
||||
$db = $dbService->getPdo();
|
||||
|
||||
return $db->exec("DELETE FROM attachments WHERE id=$id");
|
||||
}
|
||||
|
||||
public function getFileSaveDirByType($fileType)
|
||||
{
|
||||
$configService = $this->serviceManager->get('ConfigService');
|
||||
|
||||
$basePath = "";
|
||||
|
||||
switch ($fileType){
|
||||
case "literature":
|
||||
$appConfig = $configService->get('application.ini');
|
||||
$basePath = $appConfig['reference_save_path'];
|
||||
break;
|
||||
}
|
||||
|
||||
if (!preg_match("/[\/|\\\]+$/", $basePath))
|
||||
$basePath .= "/";
|
||||
|
||||
return $basePath;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,14 +13,31 @@ class ReferenceListener implements \Zend_EventManager_ListenerAggregate
|
|||
|
||||
public function attach(\Zend_EventManager_EventCollection $events)
|
||||
{
|
||||
$Handler = new ReferenceHandler();
|
||||
$events->attach('submit.checkParam', array($Handler, 'checkReferenceParam'), 100);
|
||||
$events->attach('submit.processData', array($Handler, 'processReferenceData'), 100);
|
||||
|
||||
$events->attach('upload.insertToReferenceTable', array($Handler, 'insertToReferenceTable'), 100);
|
||||
|
||||
$events->attach('mdref.checkParam', array($Handler, 'checkMdrefParam'), 100);
|
||||
$events->attach('mdref.processData', array($Handler, 'processMdrefData'), 100);
|
||||
$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)
|
||||
|
|
|
@ -43,15 +43,20 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
|
|||
$this->table->reference = "reference";
|
||||
$this->table->reference_author = "ref_author";
|
||||
$this->table->source = "source";
|
||||
$this->table->metadata_reference = "mdref";
|
||||
$this->table->reference_tag = "ref_tag";
|
||||
}
|
||||
|
||||
|
||||
public function reference($id = 0)
|
||||
/**
|
||||
* 添加或编辑文献
|
||||
* @param $data
|
||||
* @param int $id
|
||||
* @return bool|string
|
||||
*/
|
||||
public function reference($data,$id = 0)
|
||||
{
|
||||
$data = $this->getReferenceParam();
|
||||
|
||||
$params = compact('data');
|
||||
$results = $this->events()->trigger('submit.checkParam', $this, $params);
|
||||
$results = $this->getEventManager()->trigger('submit.before', $this, $params);
|
||||
$cache_data = $results->bottom();
|
||||
|
||||
if($cache_data !== true)
|
||||
|
@ -59,12 +64,11 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
|
|||
return $cache_data;
|
||||
}
|
||||
|
||||
$results = $this->events()->trigger('submit.processData', $this, $params);
|
||||
$results = $this->getEventManager()->trigger('submit.processData', $this, $params);
|
||||
$data = $results->bottom();
|
||||
|
||||
unset($data['submit']);
|
||||
|
||||
$dbh = new dbh();
|
||||
|
||||
$dbServices = $this->serviceManager->get('Db');
|
||||
$dbh = $dbServices->getDbh();
|
||||
|
||||
if(empty($id))
|
||||
{
|
||||
|
@ -84,27 +88,6 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
|
|||
}
|
||||
}
|
||||
|
||||
//获得参数
|
||||
public function getReferenceParam(\Zend_Controller_Request_Abstract $request = NULL)
|
||||
{
|
||||
$request = new \Zend_Controller_Request_Http();
|
||||
$data = array(
|
||||
'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')),
|
||||
'note' => trim($request->getParam('note')),
|
||||
'attid' => (int)$request->getParam('attid'),
|
||||
'abstract' => $request->getParam('abstract'),
|
||||
'type' => $request->getParam('type'),
|
||||
'language' => $request->getParam('language'),
|
||||
'doi' => $request->getParam('doi'),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//上传文献PDF
|
||||
public function uploadReferencePdf($file,$autoread = false)
|
||||
{
|
||||
|
@ -119,33 +102,16 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
|
|||
{
|
||||
return array("error" => $file_info['error']);
|
||||
}
|
||||
|
||||
var_dump($file_info);
|
||||
exit();
|
||||
|
||||
$file_data = array(
|
||||
'filename' => $file_info['file_url'],
|
||||
'filetype' => 'literature',
|
||||
'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;
|
||||
|
||||
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);
|
||||
$file_info = array_merge($file_info,$cache_data);
|
||||
}
|
||||
|
||||
return $file_data;
|
||||
return $file_info;
|
||||
}
|
||||
|
||||
//通过文件名自动提取文章标题
|
||||
|
@ -420,8 +386,8 @@ class Reference extends AbstractEventManager implements ServiceManagerAwareInter
|
|||
$row = $rs->fetch();
|
||||
if ($row['attid'])
|
||||
{
|
||||
$files = new Files();
|
||||
$attfile = $files->getOne($row['attid']);
|
||||
$fileService = $this->serviceManager->get('File');
|
||||
$attfile = $fileService->get($row['attid']);
|
||||
|
||||
$row['file'] = $attfile;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue