Преглед изворни кода

Dodanie znaczka do pobrania punktów georeferencyjnych w postaci pliku CSV

Mariusz Muszyński пре 8 година
родитељ
комит
f8448215ce

+ 39 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -615,6 +615,45 @@ class Route_ViewTableAjax extends RouteBase {
 		return $response;
 	}
 
+	public function getCsvTheGeomAjaxAction() {
+		try {
+			self::getCsvTheGeomAjax();
+		} catch (Exception $e) {
+			SE_Layout::gora();
+			SE_Layout::menu();
+			SE_Layout::alert('danger', $e->getMessage());
+?>
+<div style="text-align: center;">
+  <a href="<?=$_SERVER['HTTP_REFERER']?>" class="btn btn-primary" style="width: 80px;">Powrót</a>
+</div>
+<?php
+			SE_Layout::dol();
+		}
+	}
+
+	public function getCsvTheGeomAjax() {
+		Lib::loadClass('EpsgConversion');
+		$namespace = V::get('namespace', '', $_GET, 'word');
+		$acl = Core_AclHelper::getAclByNamespace($namespace);
+		$table = $acl->getRootTableName();
+		$id = V::get('id', 0, $_GET, 'int');
+
+		$query = "select st_astext(`the_geom`) as `the_geom` from `{$table}` where `ID` = {$id}";
+		try {
+			$result = DB::getPDO()->fetchValue($query);
+		} catch (Exception $e) {
+			throw new Exception('Błąd zapytania SQL');
+		}
+		if (!preg_match('/^[[:alpha:]]+\((.*)\)$/', $result, $matches)) throw new Exception('Błąd danych georeferencyjnych');
+		$points = explode(',', $matches[1]);
+		$csv = implode("\n", array_map(function ($point, $i) {
+			list($x, $y) = explode(" ", $point, 2);
+			$wgs84 = EpsgConversion::LonLatToPUWGWGS84($x, $y);
+			return $i++ . ',' . round($wgs84->y, 3) . ',' . round($wgs84->x, 3) . ',0,Pikieta';
+		}, $points, range(1, count($points))));
+		Response::sendCsv($csv, "{$table}.{$id}");
+	}
+
 	public function moreFunctionsCellAjaxAction() {
 		Response::sendTryCatchJson(array($this, 'moreFunctionsCell'), $args = $_GET);
 	}

+ 1 - 0
SE/se-lib/TableAjax.php

@@ -588,6 +588,7 @@ class TableAjax extends ViewAjax {
 			'FIRCE_FILTER_INIT' => $forceFilterInit,
 			'PAGE_SIZE' => $pageSize,
 			'PAGE_SIZES' => $pageSizes,
+			'URL_GET_CSV_THE_GEOM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=getCsvTheGeomAjax",
 			'URL_REMOVE_THE_GEOM_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=removeTheGeomAjax",
 			'URL_MORE_FUNCTIONS_CELL_AJAX' => "{$this->syncUrl}&_hash={$this->_htmlID}&_task=moreFunctionsCellAjax",
 			'URL_EDIT_INLINE_SAVE' => "index-ajax.php?_zasobID={$this->_zasobID}&_cls={$className}&_hash={$this->_htmlID}&_task=EDIT_INLINE_SAVE",

+ 5 - 1
SE/se-lib/TableAjax.php.GeomField.js

@@ -16,9 +16,10 @@
 			linkClassNamePrefix: 'TableAjaxGeomField',
 			linkSelectClassName: 'select',
 			linkSelectAddClassNames: '', // 'glyphicon glyphicon-map-marker'
+			getCsvUrl: '',
+			linkGetCsvAddClassNames: '', // 'glyphicon glyphicon-download'
 			linkRemoveClassName: 'remove',
 			linkRemoveAddClassNames: '', // 'glyphicon glyphicon-remove'
-			removeUrl: '',
 			onSelect: null,
 			onRemove: null,
 			debug: false
@@ -52,6 +53,8 @@
 				}
 			});
 
+			var cellMapGetCsv = jQuery('<a href="'+priv.options.getCsvUrl+'&id='+priv.options.recordID+'"><i title="Pobierz punkty referencyjne w CSV" class="'+priv.options.linkGetCsvAddClassNames+'"></i></a>');
+
 			var node = $(state.id);
 			node.empty();
 			node.addClass(state.linkClassNamePrefix);
@@ -61,6 +64,7 @@
 			}
 
 			node.append(cellMapSelect);
+			if (state.fieldValue) node.append(cellMapGetCsv);
 			node.append(cellMapRemove);
 		};
 

+ 3 - 0
SE/se-lib/TableAjax.php.TableAjax.js

@@ -11,6 +11,7 @@ var TableAjax = function() {
 		namespace: '',
 		url: '', //webservice url
 		urlPost: false, //use POST instead of GET
+		getCsvTheGeomAjaxUrl: '',
 		removeTheGeomAjaxUrl: '',
 		moreFunctionsCellAjaxUrl: '',
 		editInlineSaveUrl: '',
@@ -515,6 +516,8 @@ var TableAjax = function() {
 							linkClassNamePrefix: 'cell-mapfld',
 							linkSelectClassName: 'select',
 							linkSelectAddClassNames: 'glyphicon glyphicon-map-marker',
+							getCsvUrl: priv.options.getCsvTheGeomAjaxUrl,
+							linkGetCsvAddClassNames: 'glyphicon glyphicon-download',
 							linkRemoveClassName: 'remove',
 							linkRemoveAddClassNames: 'glyphicon glyphicon-remove',
 							onSelect: function(recordID, geomShape) {

+ 1 - 0
SE/se-lib/TableAjax.php.init.js

@@ -2,6 +2,7 @@ jQuery(document).ready(function(){
 	jQuery('#' + TABLE_AJAX_NODE_ID).TableAjax({
 		namespace: NAMESPACE,
 		url: URL_LOAD_AJAX_BASE,
+		getCsvTheGeomAjaxUrl: URL_GET_CSV_THE_GEOM_AJAX,
 		removeTheGeomAjaxUrl: URL_REMOVE_THE_GEOM_AJAX,
 		moreFunctionsCellAjaxUrl: URL_MORE_FUNCTIONS_CELL_AJAX,
 		editInlineSaveUrl: URL_EDIT_INLINE_SAVE,