Просмотр исходного кода

added WFS GetBlob, added link to GetBlob in TableAjax for blob fields

Piotr Labudda 8 лет назад
Родитель
Сommit
ea123d800b
2 измененных файлов с 57 добавлено и 1 удалено
  1. 48 0
      SE/se-lib/Api/WfsDataServer.php
  2. 9 1
      SE/se-lib/TableAjax.php

+ 48 - 0
SE/se-lib/Api/WfsDataServer.php

@@ -197,6 +197,7 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 
 
 		header('Content-type: application/xml; charset=utf-8');
+		// echo "\$args['filterFields']: ";print_r($args['filterFields']);echo "\$searchParams['cols']: ";print_r($searchParams['cols']);die("");
 		$xmlWriter = new Core_XmlWriter();
 		$xmlWriter->openUri('php://output');
 		// $xmlWriter->openMemory();// DBG
@@ -318,4 +319,51 @@ class Api_WfsDataServer extends Api_WfsServerBase {
 		exit;
 	}
 
+	public function GetBlobAction() {
+		$namespace = V::get('namespace', '', $_GET);
+		if (!$namespace) throw new Exception("Missing namespace");
+		$primaryKey = V::get('primaryKey', 0, $_GET, 'int');
+		if ($primaryKey < 0) throw new Exception("Missing primaryKey");
+		$fieldName = V::get('fieldName', '', $_GET);
+		if (!$fieldName) throw new Exception("Missing fieldName");
+		$acl = Core_AclHelper::getAclByNamespace($namespace);
+		$idDatabase = $acl->getDatabaseID();
+		$rootTableName = $acl->getRootTableName();
+		$sqlFieldName = $acl->getSqlFieldName($fieldName);
+		$sqlPkField = $acl->getSqlPrimaryKeyField();
+
+		$item = $acl->getItem($primaryKey);
+		if (!$item) throw new Exception("Record not exists '{$primaryKey}'");
+		if (!$acl->canReadObjectField($fieldName, $item)) throw new Exception("Access Denied for field '{$fieldName}'");
+
+
+		$pdo = DB::getPDO($idDatabase);
+		switch ($pdo->getType()) {
+			case 'mysql': {
+				$sql = "
+					select {$sqlFieldName}
+					from {$rootTableName}
+					where `{$sqlPkField}` = :pk
+					limit 1
+				";
+				$sth = $pdo->prepare($sql);
+				$sth->bindValue(':pk', $primaryKey, PDO::PARAM_STR);
+				$sth->execute();
+				$sth->bindColumn(1, $content, PDO::PARAM_LOB);
+				$sth->fetch();
+			} break;
+			default: throw new Exception("Not implemented database type '" . $pdo->getType() . "' in GetBlob");
+		}
+		if (empty($content)) throw new Exception("Brak danych");
+		$finfo = finfo_open(FILEINFO_MIME);
+		$mime = finfo_buffer($finfo, $content);
+		// $mime = "application/octet-stream";
+		header("Content-type: {$mime}");
+		// header("Content-Disposition: attachment; filename=\"{$fileName}\";" );
+		// header("Content-Transfer-Encoding: binary");
+		// header("Content-Length: ".strlen($content));
+		print $content;
+		exit;
+	}
+
 }

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

@@ -1138,7 +1138,6 @@ class TableAjax extends ViewAjax {
 				fldWidgetNode = priv.renderFieldWidget_TableCell(columnName, val, rowPK, props);
 				if (fldWidgetNode) {
 					cellCnt.empty();
-					// console.log('FieldWidget: row.pk('+rowPK+') col('+columnName+') typeof fldWidgetNode', typeof fldWidgetNode, fldWidgetNode);
 					cellCnt.append(fldWidgetNode);
 				} else if (fldWidgetNode === '') {
 					cellCnt.empty();
@@ -1164,6 +1163,15 @@ class TableAjax extends ViewAjax {
 					'&backRefField=' + columnProps.column +
 					'">przeglądaj</a>')
 
+				if (columnProps.xsdType && 'xsd:base64Binary' === columnProps.xsdType) {
+					cellCnt.empty();
+					if (val) {
+						cellCnt.append('<a target="_blank" href="wfs-data.php?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetBlob&namespace='+priv.options.namespace+'&primaryKey='+rowPK+'&fieldName='+columnName+'">'+"otwórz"+'</a>');
+					} else {
+						cellCnt.append('<span style="color:silver" title="Brak danych">N/S;</span>');
+					}
+				}
+
 				if (i > 1 && priv.options.longDesc) {// TODO: use better check for columns: functions and pk
 					cellNode.addClass('tbl-short-txt');
 					if (showTooltip) {