[Mapbender-commits] r10046 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Feb 5 08:37:46 PST 2019


Author: armin11
Date: 2019-02-05 08:37:46 -0800 (Tue, 05 Feb 2019)
New Revision: 10046

Modified:
   trunk/mapbender/http/classes/class_ckanApi.php
   trunk/mapbender/http/classes/class_group.php
   trunk/mapbender/http/classes/class_syncCkan.php
   trunk/mapbender/http/php/mod_syncCkan_server.php
Log:
New draft possibility to sync mb_group_table with ckan organizations

Modified: trunk/mapbender/http/classes/class_ckanApi.php
===================================================================
--- trunk/mapbender/http/classes/class_ckanApi.php	2019-02-01 12:32:55 UTC (rev 10045)
+++ trunk/mapbender/http/classes/class_ckanApi.php	2019-02-05 16:37:46 UTC (rev 10046)
@@ -143,6 +143,11 @@
 		'organization_update' => 'action/organization_update',
 		'organization_delete' => 'action/organization_delete',
 		'organization_list_for_user' => 'action/organization_list_for_user',
+		'organization_list' => 'action/organization_list',
+		'organization_purge' => 'action/organization_purge',
+		'organization_revision_list' => 'action/organization_revision_list',
+		'user_create' => 'action/user_create',
+		'user_show' => 'action/user_show',
 		'group_create' => 'action/group_create',
 		'group_update' => 'action/group_update',
 		'group_delete' => 'action/group_delete',
@@ -149,9 +154,8 @@
 		'group_show' => 'action/group_show',
 		'group_package_show' => 'action/group_package_show',
 		'member_create' => 'action/member_create',
-		'roles_show' => 'action/roles_show',
-		'member_create' => 'action/member_create',
 		'member_delete' => 'action/member_delete',
+		'member_list' => 'action/member_list',
 		'roles_show' => 'action/roles_show',
 		'package_owner_org_update' => 'package_owner_org_update',
 		'group_list_authz' => 'action/group_list_authz'
@@ -411,6 +415,37 @@
 			$this->actionList['package_search'], 
 			$query);
 	}
+
+	// user create 
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the newly created user
+	 * @link	http://docs.ckan.org/en/latest/apiv3.html#ckan.logic.action.create.package_create
+	 */
+	public function action_user_create($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['user_create'], 
+			$data);
+	}
+
+	// user show
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the newly created user
+	 * @link	http://docs.ckan.org/en/latest/apiv3.html#ckan.logic.action.create.package_create
+	 */
+	public function action_user_show($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['user_show'], 
+			$data);
+	}
+
 	// group create 
 
 	/**
@@ -471,6 +506,36 @@
 			$this->actionList['group_update'], 
 			$data);
 	}
+
+	// member list
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the member as dictionary
+	 * @link	http://docs.ckan.org/en/latest/apiv3.html#ckan.logic.action.update.package_update
+	 */
+	public function action_member_list($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['member_list'], 
+			$data);
+	}
+
+	// member create
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the member as dictionary
+	 * @link	http://docs.ckan.org/en/latest/apiv3.html#ckan.logic.action.update.package_update
+	 */
+	public function action_member_create($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['member_create'], 
+			$data);
+	}
 	
 	// organization create 
 
@@ -517,6 +582,37 @@
 			$data);
 	}
 
+	// organization list
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the organizations of the user to show as dictionary
+	 * @link	http://docs.ckan.org/en/latest/api/index.html
+	 */
+	public function action_organization_list($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['organization_list'], 
+			$data);
+	}
+
+	// organization purge
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the organizations of the user to show as dictionary
+	 * @link	http://docs.ckan.org/en/latest/api/index.html
+	 */
+	public function action_organization_purge($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['organization_purge'], 
+			$data);
+	}
+
+
 	// organization delete
 
 	/**
@@ -547,6 +643,21 @@
 			$data);
 	}
 
+	// organization revision list
+
+	/**
+	 * @access	public
+	 * @param  	
+	 * @return	the updated organization as dictionary
+	 * @link	http://docs.ckan.org/en/latest/api/index.html
+	 */
+	public function action_organization_revision_list($data)
+	{
+		return $this->make_request('POST', 
+			$this->actionList['organization_revision_list'], 
+			$data);
+	}
+
 	// resource_view show
 
 	/**
@@ -1030,7 +1141,8 @@
 		// Set cURL method.
 		curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
 		// Set cURL URI.
-		//$e = new mb_exception("testckan: ckan url to request: ".$this->base_url . $url);
+$e = new mb_notice("testckan: ckan url to request: ".$this->base_url . $url." - data: ".json_encode($data));
+
 		$curlUrl = $this->base_url . $url;
 		curl_setopt($this->ch, CURLOPT_URL, $curlUrl);
 //TODO - this is not secure - delete it in productive environments!

Modified: trunk/mapbender/http/classes/class_group.php
===================================================================
--- trunk/mapbender/http/classes/class_group.php	2019-02-01 12:32:55 UTC (rev 10045)
+++ trunk/mapbender/http/classes/class_group.php	2019-02-05 16:37:46 UTC (rev 10046)
@@ -47,6 +47,7 @@
 	var $uuid;
 	var $timestamp;
 	var $adminCode;
+        var $ckanId;
 
     	static $displayName = "Group";
     	static $internalName = "group";
@@ -109,6 +110,7 @@
 			"homepage" => $this->homepage,
 			"adminCode" => $this->adminCode,
 			"uuid" => $this->uuid
+			//"ckanId" => $this->ckanId
 		);
 	}
 	
@@ -291,6 +293,7 @@
 				$this->uuid = $row["uuid"];
 				$this->adminCode = $row["mb_group_admin_code"];
 				$this->timestamp = $row["timestamp"];
+				$this->ckanId = $row["mb_group_ckan_uuid"];
 				
 			} else {
 			 	throw new Exception("Group with ID " . $this->id . " does not exist.");
@@ -318,13 +321,13 @@
 		array(	groupAttribute => "email",
 			iso19139Path => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress/gco:CharacterString",
 			deleteElementPath => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:electronicMailAddress",
-			ckanName => false
+			ckanName => "department_email"
 		),
 		//deliveryPoint
 		array(	groupAttribute => "address",
 			iso19139Path => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint/gco:CharacterString",
 			deleteElementPath => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:deliveryPoint",
-			ckanName => false
+			ckanName => "department_address"
 		),
 		//administrativeArea
 		array(	groupAttribute => "adminCode",
@@ -336,7 +339,7 @@
 		array(	groupAttribute => "postcode",
 			iso19139Path => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode/gco:CharacterString",
 			deleteElementPath => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:postalCode",
-			ckanName => false
+			ckanName => "department_postcode"
 		),
 		//country
 		array(	groupAttribute => "country",
@@ -348,7 +351,7 @@
 		array(	groupAttribute => "city",
 			iso19139Path => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city/gco:CharacterString",
 			deleteElementPath => "/mb:groupcontact/gmd:CI_ResponsibleParty/gmd:contactInfo/gmd:CI_Contact/gmd:address/gmd:CI_Address/gmd:city",
-			ckanName => false
+			ckanName => "department_city"
 		),
 		//voicetelephone
 		array(	groupAttribute => "voicetelephone",
@@ -384,12 +387,18 @@
 		array(	groupAttribute => "title",
 			iso19139Path => false,
 			deleteElementPath => false,
-			ckanName => "title"
+			ckanName => array("title", "title_long")
 		),
 		//uuid
 		array(	groupAttribute => "uuid",
 			iso19139Path => false,
 			deleteElementPath => false,
+			ckanName => false
+		),
+		//ckan uuid
+		array(	groupAttribute => "ckanId",
+			iso19139Path => false,
+			deleteElementPath => false,
 			ckanName => "id"
 		),
 		//logo
@@ -396,7 +405,7 @@
 		array(	groupAttribute => "logo_path",
 			iso19139Path => false,
 			deleteElementPath => false,
-			ckanName => "image_display_url"
+			ckanName => array("image_display_url", "image_url")
 		)
 	);
 	switch ($outputFormat) {
@@ -455,11 +464,21 @@
 			//approval_status
 			for($a = 0; $a < count($mappingHash); $a++) {
 				if (isset($this->{$mappingHash[$a]['groupAttribute']}) && $this->{$mappingHash[$a]['groupAttribute']} !== "" && $mappingHash[$a]['ckanName'] !== false) {
-					$jsonOutput->{$mappingHash[$a]['ckanName']} = $this->{$mappingHash[$a]['groupAttribute']};
-					//$xpathContact->query($mappingHash[$a]['iso19139Path'])->item(0)->nodeValue = $this->{$mappingHash[$a]['groupAttribute']};
+					if ($this->{$mappingHash[$a]['groupAttribute']} == 'name') {
+						$jsonOutput->{$mappingHash[$a]['ckanName']} = str_replace('-','_',str_replace(' ','_',strtolower($this->{$mappingHash[$a]['groupAttribute']})));
+					} else {
+						if (is_array($mappingHash[$a]['ckanName'])) {
+							foreach($mappingHash[$a]['ckanName'] as $ckanAttributeName) {
+								$jsonOutput->{$ckanAttributeName} = $this->{$mappingHash[$a]['groupAttribute']};
+							}
+						} else {
+							$jsonOutput->{$mappingHash[$a]['ckanName']} = $this->{$mappingHash[$a]['groupAttribute']};
+						}
+					}
 				}
 			}
 			
+			$jsonOutput->state = "active";
 			$jsonOutput->is_organization = true;
 			$jsonOutput->type = "organization";
 			$json = json_encode($jsonOutput);

Modified: trunk/mapbender/http/classes/class_syncCkan.php
===================================================================
--- trunk/mapbender/http/classes/class_syncCkan.php	2019-02-01 12:32:55 UTC (rev 10045)
+++ trunk/mapbender/http/classes/class_syncCkan.php	2019-02-05 16:37:46 UTC (rev 10046)
@@ -39,6 +39,7 @@
     var $topicDataThemeCategoryMap;
     var $frequencyMap;
     var $compareTimestamps;
+    var $mapbenderUrl;
 
     public function __construct() {
         if (defined("CKAN_SERVER_PORT") && CKAN_SERVER_PORT !== '') {
@@ -56,6 +57,11 @@
 	} else {
     	    $this->ckanApiProtocol = 'https';
 	}
+        if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') { 
+	   $this->mapbenderUrl = MAPBENDER_PATH;
+        } else {
+	    $this->mapbenderUrl = "http://www.geoportal.rlp.de/mapbender";
+        }
 	$this->mapbenderUserId = 0;
 	$this->syncOrgaId = 0;
 	$this->topicCkanCategoryMap = $topicCkanCategoryMap; //from ckan.conf
@@ -125,6 +131,93 @@
         }
         return $array;
     }
+
+    public function getRemoteCkanOrga($orga_id) {
+        $ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_organization_show($orga_id);
+        return json_encode($result); 
+    }
+
+    public function purgeRemoteCkanOrga($orga_id) {
+        $ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_organization_purge($orga_id);
+        return json_encode($result);
+    }
+
+    public function getRemoteCkanOrgaRevList($orga_id) {
+        $ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_organization_revision_list($orga_id);
+        return json_encode($result);
+    }
+
+   public function createRemoteCkanOrga($orgaJson) {
+        $ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_organization_create($orgaJson);
+        return json_encode($result);
+   }
+
+   public function updateRemoteCkanOrga($orgaJson) {
+        $ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_organization_update($orgaJson);
+        return json_encode($result);
+   }
+
+   //function to get user info
+   public function getRemoteCkanUser ($userJson) {
+	$ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_user_show($userJson);
+        return json_encode($result);
+   }
+
+   //function to create user in special group/organization
+   public function createRemoteCkanUser ($userJson) {
+	$ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_user_create($userJson);
+        return json_encode($result);
+   }
+
+   //function to get member info
+   public function getRemoteCkanMember ($userJson) {
+	$ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_member_list($userJson);
+        return json_encode($result);
+   }
+
+   //function to create member 
+   public function createRemoteCkanMember ($userJson) {
+	$ckan = new ckanApi($this->ckanApiKey, CKAN_SERVER_IP);
+        $ckan->base_url = $this->ckanApiProtocol.'://'.$this->ckanApiUrl.'/api/3/';
+        $ckan->api_version = $this->ckanApiVersion;
+        $result = $ckan->action_member_create($userJson);
+        return json_encode($result);
+   }
+
+   public function getInternalOrgaAsCkan($mbGroupId) {
+        $localOrgaConnector = new connector(MAPBENDER_PATH."/php/mod_showOrganizationInfo.php?id=".$mbGroupId."&outputFormat=ckan");
+        $localOrgaConnector->set("timeOut", "3");
+        if ($localOrgaConnector->timedOut == true) {
+            return false;
+        } else {
+	    return $localOrgaConnector->file;
+	}
+    }
+
     //TODO - use paging for get record list!!!!!
     public function getRemoteCkanRecordList($orga_filter,$central_filter,$filter,$ckan_api_url,$ckan_api_version) {
         $ckanConnector = new connector($ckan_api_url.$ckan_api_version."/"."action/package_search?q=".$filter."&rows=1000"."&facet=true");
@@ -1084,11 +1177,6 @@
     }
 
     private function getCkanRepresentationFromCsw($cswId, $fileIdentifier, $ckan_orga_ident, $orgaTitle, $orgaEmail, $topicDataThemeCategoryMap, $ckanCategoryFilter) {
-        if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') { 
-	    $mapbenderUrl = MAPBENDER_PATH;
-	} else {
-	    $mapbenderUrl = "http://www.geoportal.rlp.de/mapbender";
-	}
 	//getRecordById
 	$csw = new csw();
 	$csw->createCatObjFromDB($cswId);
@@ -1117,7 +1205,7 @@
 		$format = (string)$format[0];
 		//$e = new mb_exception($metadataTitle);
 		//$e = new mb_exception($fileIdentifier);
-	        $originalMetadataUrl = $mapbenderUrl."/php/mod_exportIso19139.php?url=".urlencode($cswClient->operationUrl."?REQUEST=GetRecordById&VERSION=2.0.2&SERVICE=CSW&id=".$fileIdentifier);
+	        $originalMetadataUrl = $this->mapbenderUrl."/php/mod_exportIso19139.php?url=".urlencode($cswClient->operationUrl."?REQUEST=GetRecordById&VERSION=2.0.2&SERVICE=CSW&id=".$fileIdentifier);
 		//TODO
 	
         	//write json object
@@ -1210,13 +1298,8 @@
 
     //function to get ckan representation from mapbender metadata
     private function getCkanRepresentation($uuid, $layerArray, $featuretypeArray, $orgaId, $orgaTitle, $orgaEmail, $topicCkanCategoryMap, $resourceType = 'metadata') {
-        if (defined("MAPBENDER_PATH") && MAPBENDER_PATH != '') { 
-	    $mapbenderUrl = MAPBENDER_PATH;
-	} else {
-	    $mapbenderUrl = "http://www.geoportal.rlp.de/mapbender";
-	}
 	//alter protocol to https ;-)
-	$mapbenderUrl = str_replace("http://", "https://", $mapbenderUrl);
+	$this->mapbenderUrl = str_replace("http://", "https://", $this->mapbenderUrl);
 	//all or only those which have standardized licenses?
 	//$sql = "SELECT *, f_get_coupled_resources(metadata_id) from mb_metadata LEFT JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id WHERE mb_metadata.uuid = $1";
 	//$sql = "SELECT * , st_asgeojson(the_geom) as geojson from mb_metadata JOIN md_termsofuse ON mb_metadata.metadata_id = md_termsofuse.fkey_metadata_id JOIN termsofuse ON md_termsofuse.fkey_termsofuse_id = termsofuse.termsofuse_id WHERE mb_metadata.uuid = $1 AND export2csw IS true";
@@ -1325,10 +1408,10 @@
 
 	switch ($resourceType) {
 		case "layer":
-			$resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/php/mod_showMetadata.php?resource=layer&layout=tabs&redirectToMetadataUrl=1&id=".$metadataId;
+			$resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/php/mod_showMetadata.php?resource=layer&layout=tabs&redirectToMetadataUrl=1&id=".$metadataId;
 			break;
 		case "metadata":
-			$resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/php/mod_exportIso19139.php?url=http%3A%2F%2Fwww.geoportal.rlp.de%2Fmapbender%2Fphp%2Fmod_dataISOMetadata.php%3FoutputFormat%3Diso19139%26id%3D".$metadataUuid;
+			$resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/php/mod_exportIso19139.php?url=http%3A%2F%2Fwww.geoportal.rlp.de%2Fmapbender%2Fphp%2Fmod_dataISOMetadata.php%3FoutputFormat%3Diso19139%26id%3D".$metadataUuid;
 			break;
 	}
 
@@ -1354,7 +1437,7 @@
 	            $resourcesArray[$indexResourceArray]->name = "Onlinekarte";//: ".$row['layer_title'];
 	            $resourcesArray[$indexResourceArray]->id = $row['uuid']."_geoportalrlp_mobile";
 	            $resourcesArray[$indexResourceArray]->description = "Ebene: ".$row['layer_title']." - Vorschau im integrierten Kartenviewer";
-	            $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/extensions/mobilemap/map.php?layerid=".$row['layer_id'];
+	            $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/extensions/mobilemap/map.php?layerid=".$row['layer_id'];
 	            $resourcesArray[$indexResourceArray]->format = "Karte";
 		    //$resourcesArray[$indexResourceArray]->res_transparency_document_change_classification = "unaltered";
 	            $indexResourceArray++;
@@ -1373,7 +1456,7 @@
 	            $resourcesArray[$indexResourceArray]->name = "GeoPortal.rlp";//: ".$row['layer_title'];
 	            $resourcesArray[$indexResourceArray]->id = $row['uuid']."_geoportalrlp";
 	            $resourcesArray[$indexResourceArray]->description = "Ebene: ".$row['layer_title']." - Anzeige im GeoPortal.rlp";
-	            $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/../portal/karten.html?LAYER[zoom]=1&LAYER[id]=".$row['layer_id'];
+	            $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/../portal/karten.html?LAYER[zoom]=1&LAYER[id]=".$row['layer_id'];
 //Solve problem - don'Ät use https for invoking mapbender in geoportal 
 $resourcesArray[$indexResourceArray]->url = str_replace("https", "http", $resourcesArray[$indexResourceArray]->url);
 	            $resourcesArray[$indexResourceArray]->format = "Webanwendung";				
@@ -1382,7 +1465,7 @@
 	            $resourcesArray[$indexResourceArray]->name = "WMS Schnittstelle";// für ".$row['layer_title'];
 	            $resourcesArray[$indexResourceArray]->id = $row['uuid']."_capabilities";
 	            $resourcesArray[$indexResourceArray]->description = "Ebene: ".$row['layer_title'];
-	            $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/php/wms.php?layer_id=".$row['layer_id']."&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
+	            $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/php/wms.php?layer_id=".$row['layer_id']."&REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS";
 	            $resourcesArray[$indexResourceArray]->format = "WMS";
 	            $indexResourceArray++;
 	        }
@@ -1402,7 +1485,7 @@
                     $resourcesArray[$indexResourceArray]->name = "Download (INSPIRE)";//: ".$metadataObject->title;
                     $resourcesArray[$indexResourceArray]->id = $option->serviceUuid;
                     $resourcesArray[$indexResourceArray]->description = "Download von Rasterdaten über INSPIRE ATOM Feed: ".$metadataObject->title;
-                    $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=wmslayer&layerid=".$option->resourceId);
+                    $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$this->mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=wmslayer&layerid=".$option->resourceId);
                     $resourcesArray[$indexResourceArray]->format = "Diverse";
 		    //$resourcesArray[$indexResourceArray]->res_transparency_document_change_classification = "unaltered";
                     $indexResourceArray++;
@@ -1420,7 +1503,7 @@
                     $resourcesArray[$indexResourceArray]->name = "Download (INSPIRE)";//: ".$metadataObject->title;
                     $resourcesArray[$indexResourceArray]->id = $option->serviceUuid;
                     $resourcesArray[$indexResourceArray]->description = $metadataObject->title." - Download von verlinkten Daten über INSPIRE ATOM Feed";
-                    $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=dataurl&layerid=".$option->resourceId);
+                    $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$this->mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=dataurl&layerid=".$option->resourceId);
                     $resourcesArray[$indexResourceArray]->format = "Diverse"; 
                     //$resourcesArray[$indexResourceArray]->res_transparency_document_change_classification = "unaltered";
                     $indexResourceArray++;
@@ -1438,7 +1521,7 @@
                     $resourcesArray[$indexResourceArray]->name = "Download (INSPIRE)";//: ".$metadataObject->title;
                     $resourcesArray[$indexResourceArray]->id = $option->serviceUuid;
                     $resourcesArray[$indexResourceArray]->description = $metadataObject->title." - Download von Vektordaten (wfs-basiert) über INSPIRE ATOM Feed";
-                    $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=wfs&wfsid=".$option->serviceId);
+                    $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$this->mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=wfs&wfsid=".$option->serviceId);
                     $resourcesArray[$indexResourceArray]->format = "Diverse";
                     //$resourcesArray[$indexResourceArray]->res_transparency_document_change_classification = "unaltered";
                     $indexResourceArray++;
@@ -1456,7 +1539,7 @@
                     $resourcesArray[$indexResourceArray]->name = "Download (INSPIRE)";//: ".$metadataObject->title;
                     $resourcesArray[$indexResourceArray]->id = $metadataObject->uuid."_downloadlink"; //TODO - no uuid for service known in this case
                     $resourcesArray[$indexResourceArray]->description = $metadataObject->title." - Download von verlinkten Daten über INSPIRE ATOM Feed";
-                    $resourcesArray[$indexResourceArray]->url = $mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=metadata");
+                    $resourcesArray[$indexResourceArray]->url = $this->mapbenderUrl."/plugins/mb_downloadFeedClient.php?url=".urlencode(str_replace("https://","http://",$this->mapbenderUrl)."/php/mod_inspireDownloadFeed.php?id=".$metadataUuid."&type=SERVICE&generateFrom=metadata");
                     $resourcesArray[$indexResourceArray]->format = "Diverse";
                     //$resourcesArray[$indexResourceArray]->res_transparency_document_change_classification = "unaltered";
                     $indexResourceArray++;

Modified: trunk/mapbender/http/php/mod_syncCkan_server.php
===================================================================
--- trunk/mapbender/http/php/mod_syncCkan_server.php	2019-02-01 12:32:55 UTC (rev 10045)
+++ trunk/mapbender/http/php/mod_syncCkan_server.php	2019-02-05 16:37:46 UTC (rev 10046)
@@ -23,6 +23,10 @@
 //initiate resultObject to give back as json
 $resultObject->success = false;
 $operation = false;
+
+$showOnlyDatasetMetadata = "false";
+$showOnlyUnlinkedOrganizations = "false";
+
 //parse request parameter
 if (isset($_REQUEST["registratingDepartments"]) & $_REQUEST["registratingDepartments"] != "") {
 	//validate to csv integer list
@@ -64,8 +68,8 @@
 
 if (isset($_REQUEST["operation"]) && $_REQUEST["operation"] !== "" && $_REQUEST["operation"] !== null) {
         $testMatch = $_REQUEST["operation"];
- 	if (!($testMatch == 'listCatalogues' or $testMatch == 'syncCatalogue' or $testMatch == 'syncCsw' or $testMatch == 'syncCkan')){ 
-	 	$resultObject->error->message = 'Parameter operation is not valid (listCatalogues, syncCatalogue, syncCsw, syncCkan).'; 
+ 	if (!($testMatch == 'listCatalogues' or $testMatch == 'syncCatalogue' or $testMatch == 'syncCsw' or $testMatch == 'syncCkan' or $testMatch == 'syncCkanOrganizations')){ 
+	 	$resultObject->error->message = 'Parameter operation is not valid (listCatalogues, syncCatalogue, syncCsw, syncCkan, syncCkanOrganizations).'; 
 		echo json_encode($resultObject);	
 		die();	
  	}
@@ -124,6 +128,40 @@
 	$testMatch = NULL;
 }
 
+if (isset($_REQUEST["showOnlyDatasetMetadata"]) & $_REQUEST["showOnlyDatasetMetadata"] != "") {
+	$testMatch = $_REQUEST["showOnlyDatasetMetadata"];	
+ 	if (!($testMatch == 'true' or $testMatch == 'false')){ 
+		echo 'Parameter <b>showOnlyDatasetMetadata</b> is not valid (true,false (default to false)).<br/>'; 
+		die(); 		
+ 	}
+	switch ($testMatch) {
+		case "true":
+			$showOnlyDatasetMetadata = "true";
+		break;
+		case "false":
+			$showOnlyDatasetMetadata = "false";
+		break;	
+	}
+	$testMatch = NULL;
+}
+
+if (isset($_REQUEST["showOnlyUnlinkedOrganizations"]) & $_REQUEST["showOnlyUnlinkedOrganizations"] != "") {
+	$testMatch = $_REQUEST["showOnlyUnlinkedOrganizations"];	
+ 	if (!($testMatch == 'true' or $testMatch == 'false')){ 
+		echo 'Parameter <b>showOnlyUnlinkedOrganizations</b> is not valid (true,false (default to false)).<br/>'; 
+		die(); 		
+ 	}
+	switch ($testMatch) {
+		case "true":
+			$showOnlyUnlinkedOrganizations = "true";
+		break;
+		case "false":
+			$showOnlyUnlinkedOrganizations = "false";
+		break;	
+	}
+	$testMatch = NULL;
+}
+
 /*
 Serverside function of the ckan sync tool for metadata / service providers
 return values should work similar to ckans api functions
@@ -145,6 +183,7 @@
 }
 */
 
+
 $syncCkanClass = new SyncCkan();
 $syncCkanClass->mapbenderUserId = $userId;
 $syncCkanClass->compareTimestamps = $compareTimestamps;
@@ -154,6 +193,291 @@
 	$syncCkanClass->syncOrgaId = $syncDepartment;
 }
 
+if ($operation == 'syncCkanOrganizations') {
+	if ($userId !== "1") {
+		echo "You are not root user and therefor not allowed to sync organizations with ckan!";
+		die();
+	}
+	$sql = <<<SQL
+
+select opendata.*, mb_group.uuid, mb_group_id, mb_group_title, mb_group_description, mb_group_homepage, mb_group_logo_path, mb_group_address, mb_group_postcode, mb_group_city, mb_group_email, timestamp, mb_group.mb_group_ckan_uuid from mb_group, (select (sum(count_wms_layer)+sum(count_metadata)) as number_of_opendata_ressources, group_id,mb_group_name from (
+
+select count(open_published_layers.layer_id) as count_wms_layer, 0 as count_metadata,open_published_layers.group_id, mb_group_name from (select layer_id, group_id, mb_group_name from layer , (select wms_group.count, mb_group_name,group_id, wms_id from mb_group, (select count(wms_id) ,f_get_responsible_organization_for_ressource(wms_id, 'wms') as group_id,wms_id  from wms where wms_id in (select fkey_wms_id from wms_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id, wms_id) as wms_group where mb_group.mb_group_id = wms_group.group_id AND mb_group.export2ckan = TRUE) as open_published_wms where layer.fkey_wms_id = open_published_wms.wms_id and layer_searchable = 1 and export2csw is true ) as open_published_layers left join ows_relation_metadata on open_published_layers.layer_id = ows_relation_metadata.fkey_layer_id where fkey_layer_id is null group by open_published_layers.group_id, open_published_layers.mb_group_name 
+
+union
+
+select count_wms_layer, metadata_group.count_metadata, group_id,mb_group_name from mb_group, (select count(metadata_id) as count_metadata, 0 as count_wms_layer , f_get_responsible_organization_for_ressource(metadata_id, 'metadata') as group_id from mb_metadata where searchable is true and export2csw is true and metadata_id in (select fkey_metadata_id from md_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id) as metadata_group where mb_group.mb_group_id = metadata_group.group_id AND mb_group.export2ckan = TRUE
+
+) as opendata_ressources group by group_id, mb_group_name) as opendata 
+where opendata.group_id = mb_group.mb_group_id
+
+SQL;
+
+
+	$sql2 = <<<SQL
+
+select opendata.*, mb_group.uuid, mb_group_id, mb_group_title, mb_group_description, mb_group_homepage, mb_group_logo_path, mb_group_address, mb_group_postcode, mb_group_city, mb_group_email, timestamp, mb_group.mb_group_ckan_uuid from mb_group, (select (sum(count_wms_layer)+sum(count_metadata)) as number_of_opendata_ressources, group_id,mb_group_name from (
+
+select count_wms_layer, metadata_group.count_metadata, group_id,mb_group_name from mb_group, (select count(metadata_id) as count_metadata, 0 as count_wms_layer , f_get_responsible_organization_for_ressource(metadata_id, 'metadata') as group_id from mb_metadata where searchable is true and export2csw is true and metadata_id in (select fkey_metadata_id from md_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id) as metadata_group where mb_group.mb_group_id = metadata_group.group_id AND mb_group.export2ckan = TRUE
+
+) as opendata_ressources group by group_id, mb_group_name) as opendata 
+where opendata.group_id = mb_group.mb_group_id
+
+SQL;
+
+	$sql3 = <<<SQL
+
+select opendata.*, mb_group.uuid, mb_group_id, mb_group_title, mb_group_description, mb_group_homepage, mb_group_logo_path, mb_group_address, mb_group_postcode, mb_group_city, mb_group_email, timestamp, mb_group.mb_group_ckan_uuid from mb_group, (select (sum(count_wms_layer)+sum(count_metadata)) as number_of_opendata_ressources, group_id,mb_group_name from (
+
+select count(open_published_layers.layer_id) as count_wms_layer, 0 as count_metadata,open_published_layers.group_id, mb_group_name from (select layer_id, group_id, mb_group_name from layer , (select wms_group.count, mb_group_name,group_id, wms_id from mb_group, (select count(wms_id) ,f_get_responsible_organization_for_ressource(wms_id, 'wms') as group_id,wms_id  from wms where wms_id in (select fkey_wms_id from wms_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id, wms_id) as wms_group where mb_group.mb_group_id = wms_group.group_id AND mb_group.export2ckan = TRUE AND mb_group.mb_group_ckan_uuid IS  NULL) as open_published_wms where layer.fkey_wms_id = open_published_wms.wms_id and layer_searchable = 1 and export2csw is true ) as open_published_layers left join ows_relation_metadata on open_published_layers.layer_id = ows_relation_metadata.fkey_layer_id where fkey_layer_id is null group by open_published_layers.group_id
 , open_published_layers.mb_group_name 
+
+union
+
+select count_wms_layer, metadata_group.count_metadata, group_id,mb_group_name from mb_group, (select count(metadata_id) as count_metadata, 0 as count_wms_layer , f_get_responsible_organization_for_ressource(metadata_id, 'metadata') as group_id from mb_metadata where searchable is true and export2csw is true and metadata_id in (select fkey_metadata_id from md_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id) as metadata_group where mb_group.mb_group_id = metadata_group.group_id AND mb_group.export2ckan = TRUE AND mb_group.mb_group_ckan_uuid IS  NULL
+
+) as opendata_ressources group by group_id, mb_group_name) as opendata 
+where opendata.group_id = mb_group.mb_group_id
+
+SQL;
+
+
+	$sql4 = <<<SQL
+
+select opendata.*, mb_group.uuid, mb_group_id, mb_group_title, mb_group_description, mb_group_homepage, mb_group_logo_path, mb_group_address, mb_group_postcode, mb_group_city, mb_group_email, timestamp, mb_group.mb_group_ckan_uuid from mb_group, (select (sum(count_wms_layer)+sum(count_metadata)) as number_of_opendata_ressources, group_id, mb_group_name from (
+
+select count_wms_layer, metadata_group.count_metadata, group_id, mb_group_name from mb_group, (select count(metadata_id) as count_metadata, 0 as count_wms_layer , f_get_responsible_organization_for_ressource(metadata_id, 'metadata') as group_id from mb_metadata where searchable is true and export2csw is true and metadata_id in (select fkey_metadata_id from md_termsofuse where fkey_termsofuse_id in (select termsofuse_id from termsofuse where isopen = 1)) group by group_id) as metadata_group where mb_group.mb_group_id = metadata_group.group_id AND mb_group.export2ckan = TRUE AND mb_group.mb_group_ckan_uuid IS NULL
+
+) as opendata_ressources group by group_id, mb_group_name) as opendata 
+where opendata.group_id = mb_group.mb_group_id
+
+SQL;
+
+	switch ($showOnlyDatasetMetadata) {
+		case "true":
+			if ($showOnlyUnlinkedOrganizations == "true") {
+				$result = db_query($sql4);
+			} else {
+				$result = db_query($sql2);
+			}
+			break;
+		case "false":
+			if ($showOnlyUnlinkedOrganizations == "true") {
+				$result = db_query($sql3);
+			} else {
+				$result = db_query($sql);
+			}
+			break;
+	}
+	$returnObject = array();
+	//initialize ckanApi
+	$syncCkanClass->ckanApiKey = API_KEY;
+	while ($row = db_fetch_array($result)) {
+        	unset($orga);
+		$orga->serialId = $row['mb_group_id'];
+		$orga->id = $row['mb_group_ckan_uuid'];
+		$orga->department_address = $row['mb_group_address'];
+		$orga->department_city = $row['mb_group_city'];
+		$orga->department_postcode = $row['mb_group_postcode'];
+		$orga->department_email = $row['mb_group_email'];
+		$orga->title = $row['mb_group_title'];
+		$orga->description = $row['mb_group_description'];
+		$orga->image_url = $row['mb_group_logo_path'];
+		$orga->image_display_url = $row['mb_group_logo_path'];
+		$orga->is_organization = true;
+		$orga->display_name = $row['mb_group_title'];
+		$orga->state = "active";
+		$orga->type = "organization";
+		$orga->approval_status = "approved";
+		$orga->package_count = $row['number_of_opendata_ressources'];
+		$orga->updated = $row['timestamp'];
+		$returnObject[] = $orga;
+		if ($showOnlyUnlinkedOrganizations == true) {
+			//check if organization exists in connected ckan portal
+	 		if (isset($orga->id)) {
+				//try to get orga from external ckan and show it
+				$requestPost = new stdClass();
+				//$requestPost->{'name'} = (string)$ckanOrgaPreferredName;
+				//$requestPost->{'organizations'} = array((string)$ckanOrgaPreferredName);
+				$requestPost->{'id'} = (string)$orga->id;
+				$requestPostJson = json_encode($requestPost);
+				//try to read orga
+				$ckanResult = $syncCkanClass->getRemoteCkanOrga($requestPostJson);
+				$ckanResultObject = json_decode($ckanResult);
+				if ($ckanResultObject->success == true) {
+					//give back ckan id of organization
+$e = new mb_notice("orga found!");
+					//get revision_list of organization to get last change date!
+					$ckanResultOrgaRevList = $syncCkanClass->getRemoteCkanOrgaRevList($requestPostJson);
+$e = new mb_notice("orga rev list: ".$ckanResultOrgaRevList);
+					//extract last timestamp:
+					$ckanResultOrgaRevListObject = json_decode($ckanResultOrgaRevList);
+					//check for update if needed!
+					if ($ckanResultOrgaRevListObject->success == true) {
+						$dateTimeCkanOrga = new DateTime($ckanResultOrgaRevListObject->result[0]->timestamp);
+					} else {
+						$dateTimeCkanOrga = new DateTime($ckanResultObject->result->created);
+					}
+					//$dateTimeCkanOrga = new DateTime($ckanResultObject->result->created);
+                                	$dateTimeMapbenderOrga = new DateTime($orga->updated);
+
+$e = new mb_notice("datetime ckan: ".$dateTimeCkanOrga->format('Y-m-d H:i:s')." - datetime mapbender: ".$dateTimeMapbenderOrga->format('Y-m-d H:i:s'));
+    					if (($dateTimeCkanOrga < $dateTimeMapbenderOrga) || $ckanResultObject->result->state == "deleted") {
+						$ckanOrgaRepresentation = $syncCkanClass->getInternalOrgaAsCkan($orga->serialId);
+						$ckanResult = $syncCkanClass->updateRemoteCkanOrga($ckanOrgaRepresentation);
+$e = new mb_notice("update organization ! ".$ckanResult); //id needed!!!!
+    					} else {
+$e = new mb_notice("no update required!");
+					}
+				} else {
+$e = new mb_notice("organization not found - try to create it!");
+    					//try to create it
+    					$ckanResult = $syncCkanClass->createRemoteCkanOrga($ckanOrgaRepresentation);
+$e = new mb_notice("result of creation: ". $ckanResult);
+    					$ckanResultObject = json_decode($ckanResult);
+    					if ($ckanResultObject->success == true) {
+$e = new mb_notice("organization successfully created!: ");
+    					} else {
+						$e = new mb_notice("an error occured when trying to create organization via ckan api! ");
+    					}
+				}	
+			} else {
+				//read ckan representation of internal group from registry
+				$ckanOrgaRepresentation = $syncCkanClass->getInternalOrgaAsCkan($orga->serialId);
+				$ckanOrgaRepresentationObject = json_decode($ckanOrgaRepresentation);
+				$ckanOrgaPreferredName = $ckanOrgaRepresentationObject->name;
+				$requestPost = new stdClass();
+				$requestPost->{'id'} = (string)$ckanOrgaPreferredName;
+				$requestPostJson = json_encode($requestPost);
+				//check if already exists and/or state is "deleted"- than update and set to active
+				$ckanResult = $syncCkanClass->getRemoteCkanOrga($requestPostJson);
+$e = new mb_notice("remote ckan organization: ".$ckanResult);
+				$ckanResultObject = json_decode($ckanResult);
+				if ($ckanResultObject->success == false) {
+$e = new mb_notice("organization not found - try to create it!");
+    					//try to create it
+    					$ckanResult = $syncCkanClass->createRemoteCkanOrga($ckanOrgaRepresentation);
+$e = new mb_notice("result of creation: ". $ckanResult);
+    					$ckanResultObject = json_decode($ckanResult);
+    					if ($ckanResultObject->success == true) {
+$e = new mb_notice("organization successfully created!: ");
+						//store uuid of external created ckan organization into mapbender database as foreign key
+						$sql = "UPDATE mb_group SET mb_group_ckan_uuid = $1 WHERE mb_group_id = $2";
+						$v = array($ckanResultObject->result->id, $orga->serialId);		
+						$t = array('s', 'i');
+						$update_result = db_prep_query($sql,$v,$t);
+						if(!$update_result)	{
+							throw new Exception("Database error updating mb_group table with ckan uuid attribute!");
+							return false;
+						}
+						//set orga->id for further requests
+						$orga->id = $ckanResultObject->result->id;
+    					} else {
+						$e = new mb_notice("an error occured! ");
+    					}
+				} else {
+					//a organization was found with the requested name - get the id from this organisation and fill it into the mapbender database before updating
+					$sql = "UPDATE mb_group SET mb_group_ckan_uuid = $1 WHERE mb_group_id = $2";
+					$v = array($ckanResultObject->result->id, $orga->serialId);		
+					$t = array('s', 'i');
+					$update_result = db_prep_query($sql,$v,$t);
+					if(!$update_result)	{
+						throw new Exception("Database error updating mb_group table with ckan uuid attribute!");
+						return false;
+					}
+					//set orga->id for further requests
+					$orga->id = $ckanResultObject->result->id;
+					//add the id to the json object from mapbender database
+					$ckanOrgaRepresentationObject->id = $ckanResultObject->result->id;
+					$ckanOrgaRepresentation = json_encode($ckanOrgaRepresentationObject);
+					$ckanResultOrgaRevList = $syncCkanClass->getRemoteCkanOrgaRevList($requestPostJson);
+$e = new mb_notice("orga rev list: ".$ckanResultOrgaRevList);
+					//extract last timestamp:
+					$ckanResultOrgaRevListObject = json_decode($ckanResultOrgaRevList);
+					//check for update if needed!
+					if ($ckanResultOrgaRevListObject->success == true) {
+						$dateTimeCkanOrga = new DateTime($ckanResultOrgaRevListObject->result[0]->timestamp);
+					} else {
+						$dateTimeCkanOrga = new DateTime($ckanResultObject->result->created);
+					}
+    					//check if timestamp older than from mapbender db or state of organization is deleted
+					//compare timestamps
+					$dateTimeCkanOrga = new DateTime($ckanResultObject->result->created);
+                                	$dateTimeMapbenderOrga = new DateTime($orga->updated);
+    					if (($dateTimeCkanOrga < $dateTimeMapbenderOrga) || $ckanResultObject->result->state == "deleted") {
+						$ckanResult = $syncCkanClass->updateRemoteCkanOrga($ckanOrgaRepresentation);
+$e = new mb_notice("update organization ! ".$ckanResult); //id needed!!!!
+    					}
+				}
+			}
+			//wether ckan orga was identified or created - check editor account !
+			//check if user for editing exists - if not create him automagically
+			$editingUserName = "geoportal_editor_".$orga->serialId;
+			$requestPost = new stdClass();
+			$requestPost->{'id'} = $editingUserName;
+			$requestPostJson = json_encode($requestPost);
+			$ckanResultUser = $syncCkanClass->getRemoteCkanUser($requestPostJson);
+$e = new mb_notice("get user:  ".$ckanResultUser); //id needed!!!!
+			$ckanResultUserObject = json_decode($ckanResultUser);
+		
+			if ($ckanResultUserObject->success == true) {
+				//check if user has already editor role in organization
+			
+			} else {
+				//create user
+				$requestPost = new stdClass();
+				$requestPost->{'name'} = $editingUserName;
+				$requestPost->{'email'} = "kontakt at geoportal.rlp.de";
+				$requestPost->{'password'} = "1234".$editingUserName."5678";
+				$requestPostJson = json_encode($requestPost);
+				$ckanResultUser = $syncCkanClass->createRemoteCkanUser($requestPostJson);
+$e = new mb_notice("get user:  ".$ckanResultUser);
+				$ckanResultUserObject = json_decode($ckanResultUser);
+
+			}
+			//read apikey:
+			if ($ckanResultUserObject->success == true) {
+				$apiKey = $ckanResultUserObject->result->apikey;
+				$userId = $ckanResultUserObject->result->id;
+				//store key into mapbender group table
+				$sql = "UPDATE mb_group SET mb_group_ckan_api_key = $1 WHERE mb_group_id = $2";
+				$v = array($apiKey, $orga->serialId);		
+				$t = array('s', 'i');
+				$update_result = db_prep_query($sql,$v,$t);
+				if(!$update_result) {
+					throw new Exception("Database error updating mb_group table with ckan api-key attribute!");
+					return false;
+				}
+			}
+			//add user with role editor to current organization
+			//get membership if exists
+			$requestPost = new stdClass();
+			$requestPost->{'id'} = $orga->id;
+			$requestPost->{'object_type'} = "user";
+			$requestPost->{'capacity'} = "editor";
+			$requestPostJson = json_encode($requestPost);
+			$ckanResultMember = $syncCkanClass->getRemoteCkanMember($requestPostJson);
+$e = new mb_notice("get member:  ".$ckanResultMember);
+			$ckanResultMemberObject = json_decode($ckanResultMember);
+$e = new mb_notice("number of editors:  ".count($ckanResultMemberObject->result));
+			if (count($ckanResultMemberObject->result == 0)) {
+				//add membership for editor
+				$requestPost = new stdClass();
+				$requestPost->{'id'} = $orga->id;
+				$requestPost->{'object'} = $userId;
+				$requestPost->{'object_type'} = "user";
+				$requestPost->{'capacity'} = "editor";
+				$requestPostJson = json_encode($requestPost);
+				$ckanResultMember = $syncCkanClass->createRemoteCkanMember($requestPostJson);
+$e = new mb_notice("get member after creating:  ".$ckanResultMember);
+			}
+		}
+	}
+	header('Content-Type: application/json; charset='.CHARSET);
+	echo json_encode($returnObject, JSON_NUMERIC_CHECK);
+	die();
+}
+
+
 if ($operation == 'listCatalogues') {
 	//get orga id from mapbender group!! - where from?
 	$departmentsArray = $syncCkanClass->getMapbenderOrganizations();



More information about the Mapbender_commits mailing list