From 6d65e945b2fe7aa28ef95413e55616911c3a0a17 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 14 Jan 2015 05:59:20 +0000 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=AE=9E=E7=8E=B0=E5=85=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E6=97=B6=E7=A9=BA=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 99 +++++++++- .../admin/views/scripts/data/left.phtml | 1 + application/admin/views/scripts/data/md.phtml | 3 + .../views/scripts/data/spatial-add.phtml | 121 ++++++++++++ .../admin/views/scripts/data/spatial.phtml | 167 ++++++++++++++++ application/models/data/DataSpatial.php | 180 ++++++++++++++++++ 6 files changed, 570 insertions(+), 1 deletion(-) create mode 100644 application/admin/views/scripts/data/spatial-add.phtml create mode 100644 application/admin/views/scripts/data/spatial.phtml create mode 100644 application/models/data/DataSpatial.php diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 53dd872b..3201ab89 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -499,12 +499,13 @@ class Admin_DataController extends Zend_Controller_Action }//search else{ - $sql = "SELECT md.*,s.viewed,g.id as gid,gen.id as genid,st.status as mdstatus,ds.id as datasetid FROM metadata md + $sql = "SELECT md.*,s.viewed,g.id as gid,gen.id as genid,st.status as mdstatus,ds.id as datasetid,dataspatial.id as stid FROM metadata md LEFT JOIN mdstat s ON md.uuid=s.uuid LEFT JOIN geonetworkmetadata g ON g.uuid=md.uuid LEFT JOIN mdstatus st ON md.uuid=st.uuid LEFT JOIN dataset ds ON md.uuid=ds.uuid left join en.geonetworkmetadata gen on gen.uuid=md.uuid + left join dataspatial on dataspatial.uuid=md.uuid ORDER BY md.id DESC"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -4198,6 +4199,102 @@ class Admin_DataController extends Zend_Controller_Action } }//doi + public function spatialAction() + { + $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $uuid = $this->_getParam('uuid'); + $q=$this->_getParam('q'); + $this->view->q=$q; + + include_once("data/DataSpatial.php"); + $spatial = new DataSpatial($this->db); + include_once("helper/view.php"); + + if( empty($ac) || $ac == "index") + { + if(empty($uuid)) + { + $rows = $spatial->fetch(0,$q); + view::addPaginator($rows,$this,10); + }else{ + $this->_redirect('/admin/data/spatial/ac/edit/uuid/'.$uuid); + return true; + } + return true; + }//index + + else if($ac == "edit") + { + $this->_helper->viewRenderer('spatial-add'); + $id = $this->_getParam('id'); + if(empty($uuid) && empty($id)) + { + view::Msg('alert-error',"参数错误",-1); + return false; + } + + if(empty($submit)){ + if(!empty($uuid)) + { + $this->view->uuid = $uuid; + $this->view->data = $spatial->view($uuid); + if(empty($this->view->data)) + { + include('data/Metadata.php'); + $md = new Metadata($this->db); + $metadata = $md->view($uuid); + $data['title']=$metadata['title']; + $data['temporal']=$spatial->mktemporal($metadata['timebegin'],$metadata['timeend']); + $data['spatial']=$spatial->mkspatial($metadata['east'],$metadata['south'],$metadata['west'],$metadata['north']); + $this->view->data[0]=$data; + } + } + }else{ + $data = $spatial->_getParams($this->_request); + $this->view->data = $data; + $data['info'] = $spatial->checkinfo($data['info']); + if(!is_array($data['info'])){ + $this->view->error = view::Error($data['info']); + return true; + } + $state = $spatial->update($data,$uuid); + if($state) + { + $this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/spatial/uuid/'.$uuid); + return false; + }else{ + $this->view->error = view::Error("修改失败"); + return false; + } + } + }//edit + + else if($ac == "del") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($spatial->delete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + + }//del + }//spatial + //发送邀请专家的邮件 public function sendMailToExpert($pid,$name,$email,$code,$test=0) { diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index c13f975e..9a7397de 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -25,5 +25,6 @@ + \ No newline at end of file diff --git a/application/admin/views/scripts/data/md.phtml b/application/admin/views/scripts/data/md.phtml index 2a8aa172..e5d55ea7 100644 --- a/application/admin/views/scripts/data/md.phtml +++ b/application/admin/views/scripts/data/md.phtml @@ -76,6 +76,9 @@ 0) : ?> 导入英文版 + 0) : ?> + 数据时空范围采集 +

数据贡献者:

diff --git a/application/admin/views/scripts/data/spatial-add.phtml b/application/admin/views/scripts/data/spatial-add.phtml new file mode 100644 index 00000000..9b7125cd --- /dev/null +++ b/application/admin/views/scripts/data/spatial-add.phtml @@ -0,0 +1,121 @@ +headTitle($this->config->title->site); +$this->headTitle('后台管理'); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/admin.css'); +$this->breadcrumb('首页'); +$this->breadcrumb('数据管理'); +$this->breadcrumb('数据时空范围'); +$this->breadcrumb()->setSeparator(' > '); +$this->theme->AppendPlus($this,'colorbox'); +?> +
+ +
+
+ +
+
+ error)) { ?> + error ?> + + msg)) { ?> + msg ?> + +

+
+ +

提示

+ 1. 空间范围请使用经纬度(dd)格式进行添加。
+ 2. 日期精确到天。中括号代表包含,小括号代表不包含。 +
+

data[0]['title']; ?>

+
+
+ data)): ?> + + + + + + + + + + data as $item): + if (isset($item['id']) && $item['id']>0) : + $autoindex++; ?> + + + + + + + data)==1) && !isset($this->data[0]['id'])) : + $item=$this->data[0]; ?> + + + + + + + + +
空间范围时间范围操作
+ 编辑:点 线 矩形 多边形 + 删除 +
+ 点 线 矩形 多边形 + 编辑 +
+
+ +
+
+ + uuid)) { ?> + + + +
+
+
+ +
+
+
+ + \ No newline at end of file diff --git a/application/admin/views/scripts/data/spatial.phtml b/application/admin/views/scripts/data/spatial.phtml new file mode 100644 index 00000000..23c5e919 --- /dev/null +++ b/application/admin/views/scripts/data/spatial.phtml @@ -0,0 +1,167 @@ +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('数据管理'); + $this->breadcrumb('数据时空范围'); + $this->breadcrumb()->setSeparator(' > '); + // $this->theme->AppendPlus($this,'colorbox'); + $this->theme->AppendPlus($this,'admin_plugin'); + $this->headScript()->appendFile('/js/lib/colorbox/jquery.colorbox-min.js'); + $this->headLink()->appendStylesheet('/js/lib/colorbox/colorbox.css'); +?> +
+ +
+
+ +
+
+
+ + +
+
+ + error)) { ?> + error ?> + + msg)) { ?> + msg ?> + +
+ paginator)): ?> + + + + + + + + + + + + paginator as $item): + $autoindex++;?> + + + + + + + + + +
元数据空间范围时间范围修改时间操作
+ 编辑 + 删除 +
+ + +
+ +
+
+ + diff --git a/application/models/data/DataSpatial.php b/application/models/data/DataSpatial.php new file mode 100644 index 00000000..265eec06 --- /dev/null +++ b/application/models/data/DataSpatial.php @@ -0,0 +1,180 @@ +db = $db; + } + + function fetch($uid=0,$keyword='') + { + $wheresql=' 1=1 '; + if(!empty($keyword)) + { + if(preg_match("/\'/",$keyword)) + { + $keyword = preg_replace("/\'/","''",$keyword); + } + $wheresql.=" and m.title like '%$keyword%'"; + } + if(empty($uid)) + { + $sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid where ".$wheresql."ORDER BY d.ts_changed desc"; + }else{ + $sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d + left join metadata m on d.uuid=m.uuid + LEFT JOIN mdauthor a ON d.uuid=a.uuid + WHERE a.userid=".$uid." AND a.status>0 and ".$wheresql." + ORDER BY d.ts_published desc,d.ts_submitted desc,d.ts_created DESC + "; + } + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + + function update($data,$uuid,$uid=0){ + if(!empty($uid)) + { + include_once("data/Author.php"); + $author = new Author($this->db); + if($author->checkAuthor($uuid,$uid)==false) + { + return "您没有权限"; + } + } + $this->db->beginTransaction(); + try + { + foreach($data['info'] as $item) + { + if ($item['id']>0) + { + //update + if (isset($item['temporal'])) + $sql="update $this->tbl set the_geom=ST_GeometryFromText('SRID=4326;".$item['spatial']."'),temporal='".$item['temporal']."',ts_changed=now() where id=".$item['id']." and uuid='".$data['uuid']."'"; + else + $sql="update $this->tbl set the_geom=ST_GeometryFromText('SRID=4326;".$item['spatial']."'),ts_changed=now() where id=".$item['id']." and uuid='".$data['uuid']."'"; + } else { + //insert + if (isset($item['temporal'])) + $sql="insert into $this->tbl (uuid,the_geom,temporal) values('".$data['uuid']."',ST_GeometryFromText('SRID=4326;".$item['spatial']."'),'".$item['temporal']."')"; + else + $sql="insert into $this->tbl (uuid,the_geom) values('".$data['uuid']."',ST_GeometryFromText('SRID=4326;".$item['spatial']."'))"; + } + $this->db->exec($sql); + } + $this->db->commit(); + return true; + } catch (Exception $e) { + $this->db->rollBack(); + return $e->getMessage(); + } + } + + function view($id) + { + if(is_numeric($id)) + { + $sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid WHERE d.id=$id"; + }else{ + $sql = "SELECT m.title,d.id,d.uuid,st_astext(d.the_geom) as spatial,d.temporal,d.ts_changed FROM ".$this->tbl." d left join metadata m on d.uuid=m.uuid WHERE d.uuid='$id'"; + } + $rs = $this->db->query($sql); + $row = $rs->fetchAll(); + return $row; + } + + function delete($id,$uid=0){ + if(!is_numeric($id)) + { + return "参数错误"; + } + if($uid != 0){ + $sql = "SELECT uuid FROM ".$this->tbl." WHERE id=$id"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + if(isset($row['uuid']) && !empty($row['uuid'])){ + include_once("data/Author.php"); + $author = new Author($this->db); + if($author->checkAuthor($row['uuid'],$uid)==false) + { + return "您没有权限"; + } + $condition = " id=$id "; + $sql = "DELETE FROM ".$this->tbl." WHERE $condition"; + return $this->db->exec($sql); + }else{ + return "该记录不存在"; + } + }else{ + $condition = " id=$id "; + $sql = "DELETE FROM ".$this->tbl." WHERE $condition"; + return $this->db->exec($sql); + } + } + + function _getParams(Zend_Controller_Request_Abstract $request) + { + $data = array( + 'uuid' => trim($request->getParam('uuid')), + 'info'=>$_POST['info'] + ); + return $data; + } + + function checkinfo($info){ + if(!is_array($info)){ + return NULL; + } + foreach($info as $k=>$v) + { + if(empty($v['spatial']) && empty($v['temporal'])) + { + unset($info[$k]); + }else{ + if(empty($v['spatial'])) + { + return "请输入 $k 中的空间范围"; + } + } + } + return $info; + } + + function mkspatial($e,$s,$w,$n) + { + $str='GeometryCollection('; + if (($e==$w) && ($s==$n)) + { + $str.="Point($e $s)"; + } else { + $str.="Polygon(($e $s,$e $n,$w $n,$w $s,$e $s))"; + } + $str.=')'; + return $str; + } + + function mktemporal($begin,$end=null) + { + if (!$begin) return ''; + $str='['; + $begin=date('Y-m-d',strtotime($begin)); + if (isset($end)) $end=date('Y-m-d',strtotime($end)); + if (isset($end) && ($end!=$begin)) + { + $str.="$begin,$end"; + } else { + $str.="$begin,$begin"; + } + $str.=']'; + return $str; + } + +}