修改DOI中相关操作

This commit is contained in:
Li Jianxuan 2013-04-23 10:09:58 +00:00
parent 227a0ca119
commit 0af6ccfe94
3 changed files with 3841 additions and 3695 deletions

View File

@ -3572,11 +3572,32 @@ class Admin_DataController extends Zend_Controller_Action
$this->view->data = $doi->view($uuid);
if(empty($this->view->data))
{
$this->view->data['uuid'] = $uuid;
include('data/Metadata.php');
$md = new Metadata($this->db);
$metadata = $md->view($uuid);
$this->view->data = array(
'uuid'=>$uuid,
'title'=>$metadata['title'],
'url'=>"http://" . $_SERVER['HTTP_HOST'].'/data/uuid/'.$uuid,
'publisher'=>view::User('realname'),
);
}
}
}else{
$data = $doi->_getParams($this->_request);
if(!is_array($data))
{
$this->view->error = view::Error('alert-error',$data,-1);
return true;
}
if($doi->update($data,$uuid))
{
$this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/doi/uuid/'.$uuid);
return false;
}else{
$this->view->error = view::Error('alert-error',"参数错误",-1);
return false;
}
}
}//add

View File

@ -20,6 +20,58 @@ class Doi extends Zend_Controller_Plugin_Abstract
return $rows;
}
function add($data){
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
$this->data_process_in($data);
include_once("helper/view.php");
view::Dump($data);
return $dbh->insert($this->tbl_doi,$data);
}
function update($data,$uuid){
$doi_info = $this->view($uuid);
if(!$doi_info)
{
$this->data_process_in($data);
include_once("helper/view.php");
view::Dump($data);
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
if(is_numeric($uuid))
{
$condition = " id=$uuid ";
}else{
$condition = " uuid='$uuid' ";
}
$state = $dbh->update($this->tbl_doi,$data,$condition,true);
if( $state == true)
{
return true;
}else{
return $state;
}
}else{
$this->add($data);
}
}
function data_process_in(&$data){
$authors = array();
$orgs = array();
foreach($data['info'] as $k=>$v)
{
$authors[$v['order']] = $v['author'];
$orgs[$v['order']] = $v['organization'];
}
$authors = "{".join(",",$authors)."}";
$orgs = "{".join(",",$orgs)."}";
$data['authors'] = $authors;
$data['organization'] = $orgs;
unset($data['info']);
}
function view($id)
{
if(is_numeric($id))
@ -41,9 +93,61 @@ class Doi extends Zend_Controller_Plugin_Abstract
'publisher' => trim($request->getParam('publisher')),
'url' => trim($request->getParam('url')),
'title' => trim($request->getParam('title')),
'info'=>$_POST['info']
'info'=>$this->checkinfo($_POST['info'])
);
if(!is_array($data['info'])){
return $data['info'];
}else{
$data['info'] = $this->sksort($data['info'],"order",SORT_DESC);
}
return $data;
}
function checkinfo($info){
if(!is_array($info)){
return NULL;
}
foreach($info as $k=>$v)
{
if(empty($v['author']) && empty($v['organization']) && empty($v['order']))
{
unset($info[$k]);
}else{
if(empty($v['author']))
{
return "请输入 $k 中的作者";
}
if(empty($v['organization']))
{
return "请输入 $k 中的单位";
}
if(empty($v['order']))
{
return "请输入 $k 中的排序";
}
}
}
return $info;
}
function sksort($array,$key,$type=SORT_DESC) {
$sortArray = array();
foreach($array as $v){
foreach($v as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
if(array_multisort($sortArray[$key],$type,$array))
{
return $array;
}else{
return $array;
}
}
}

View File

@ -58,4 +58,25 @@ class view extends Zend_Controller_Plugin_Abstract
$html.= '</div>'."\r\n";
return $html;
}
static function User($param){
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
return $user->$param;
}else{
return false;
}
}
static function Dump($data,$exit = true){
echo "<pre>";
var_dump($data);
echo "</pre>";
if($exit)
{
exit();
}
}
}