修改了作者管理、添加了新建元数据

This commit is contained in:
Li Jianxuan 2012-05-31 06:51:00 +00:00
parent 574baab0b2
commit bee1b06d83
1 changed files with 214 additions and 3 deletions

View File

@ -2159,6 +2159,7 @@ class Admin_DataController extends Zend_Controller_Action
public function authorAction(){ public function authorAction(){
$ac = $this->_getParam('ac'); $ac = $this->_getParam('ac');
$uuid = $this->_getParam('uuid');
if(empty($ac)) if(empty($ac))
@ -2287,7 +2288,7 @@ class Admin_DataController extends Zend_Controller_Action
}//ajax 添加作者 }//ajax 添加作者
if($ac == "edit") if($ac == "edit" || !empty($uuid))
{ {
$window = $this->_getParam('window'); $window = $this->_getParam('window');
@ -2300,8 +2301,6 @@ class Admin_DataController extends Zend_Controller_Action
$this->_helper->viewRenderer('author-edit'); $this->_helper->viewRenderer('author-edit');
} }
$uuid = $this->_getParam('uuid');
$sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a $sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a
LEFT JOIN metadata md ON a.uuid=md.uuid LEFT JOIN metadata md ON a.uuid=md.uuid
LEFT JOIN users u ON a.userid=u.id LEFT JOIN users u ON a.userid=u.id
@ -2369,6 +2368,218 @@ class Admin_DataController extends Zend_Controller_Action
}//authorAction() 数据作者管理 }//authorAction() 数据作者管理
//newdataAction() 新建元数据
public function newdataAction(){
$ac = $this->_request->getParam('ac');
$id = $this->_request->getParam('id');
$this->wdb=Zend_Db::factory($this->view->config->geonetwork);
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$u_id = $user->id;
}
//在geonetwork中查看单条数据
if (!empty($id) && empty($ac))
{
$this->view->url='metadata.show?id='.$id;
$this->_helper->viewRenderer('newdata-view');
}
//查看属于自己的所有的未提交数据列表
else if((empty($ac) && empty($uuid))|| $ac=='list')
{
$sql = "SELECT (regexp_matches(gn.data,'<resTitle>(.*)</resTitle>'))[1] as title,gn.id,gn.uuid FROM geonetworkmetadata gn
WHERE gn.uuid not in (select uuid from metadata) and gn.owner=?
order by gn.id desc
";
$sth = $this->db->prepare($sql);
$sth->execute(array($u_id));
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(15);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
//元数据导入
else if($ac=="import")
{
$this->_helper->viewRenderer('newdata-import');
}
//从模板新建元数据
else if($ac=="add-by-template")
{
$keywords = $this->_request->getParam('q');
$sql="select id,(regexp_matches(data,'<resTitle>(.*)</resTitle>'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'";
if(!empty($keywords))
{
$this->view->q = $keywords;
$search=new Search($keywords);
$where=$search->sql_expr(array("data"));
$sql.=' and '.$where;
}
$sql.=" order by changedate desc";
$sth = $this->wdb->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('newdata-add');
}
else if($ac=="add-by-data")
{
$keywords = $this->_request->getParam('q');
$sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md
left join geonetworkmetadata gn on md.uuid=gn.uuid
WHERE gn.id is not null";
if(!empty($keywords))
{
$this->view->q = $keywords;
$search=new Search($keywords);
$where=$search->sql_expr(array("md.title","md.description"));
$sql.=' and '.$where;
}
$sql.=" order by md.ts_created desc";
$sth = $this->db->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
$this->_helper->viewRenderer('newdata-add-bydata');
}
//提交数据
else if($ac=="commit")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = "";
try{
$id = $this->_request->getParam('id');
if(empty($id) || !is_numeric($id))
{
$data = array("error"=>"参数错误");
$this->jsonexit($data);
return true;
}
$changelog = $this->_request->getParam('changelog');
if(empty($changelog))
{
$data = array("error"=>$this->alertbox('warning','请输入变更信息'));
$this->jsonexit($data);
return true;
}
// 1. 权限认定当前用户必须和其owner相同
// 数据应当没有评审状态,没有作者信息
$sql="select gn.id from geonetworkmetadata gn
left join mdstatus s on gn.uuid=s.uuid
left join mdauthor a on s.uuid=a.uuid
where s.id is not null and a.id is not null and gn.id=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($id));
$row=$sth->fetch();
if (!empty($row))
{
$data = array("error"=>'错误的入口');
$this->jsonexit($data);
return true;
}
// 保存数据作者信息
$sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)";
$this->db->query($sql,array($row['uuid'],$u_id));
// 2. 保存变化记录 save changelog & userid for the latest version
$sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)";
$this->db->query($sql,array($changelog,$u_id,$row['uuid']));
// 3. 保存数据评审状态
//导入元数据
$iso=new ISO19115();
@$iso->saveDB($this->db,$row['data']);
//进入评审库
$sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata where id=?";
$this->db->query($sql,array($u_id,$id));
//email to admin
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-new-admin",array(
'user' => $user->username,
'uuid' => $iso->uuid,
'email'=> $user->email,
//元数据标题
'title'=> $iso->resTitle,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
$mail->send();
unset($mail);
unset($mailtp);
//email to author
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mailtp=new EmailText($this->db,"metadata-new-author",array(
'user' => $user->username,
'uuid' => $iso->uuid,
'email'=> $user->email,
//元数据标题
'title'=> $iso->resTitle,
));
$mail->setBodyText($mailtp->getBody());
$mail->setSubject($mailtp->getSubject());
if($this->debug==0)
{
$mail->addTo($user->email);
$mail->addCc($this->view->config->service->email);
}else{
$mail->addTo($this->debug_email);
}
@$mail->send();
$data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功提交,请等待数据中心进一步处理!'));
$this->jsonexit($data);
return true;
}catch(Exception $e) {
$msg = "提交失败,请确认权限后重试";
if($this->debug>0)
{$msg .= $e->getMessage();}
$data = array("error"=>$this->alertbox('error',$msg));
$this->jsonexit($data);
return true;
}
}
}// newdataAction() 新建元数据
/* /*
获得单个文件的信息 获得单个文件的信息
return array row return array row