[Mapbender-commits] r7921 - in trunk/metador/mapbender: http/MeTaDor resources

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Jul 8 03:41:15 EDT 2011


Author: astrid_emde
Date: 2011-07-08 00:41:15 -0700 (Fri, 08 Jul 2011)
New Revision: 7921

Modified:
   trunk/metador/mapbender/http/MeTaDor/class_MdMetadata.php
   trunk/metador/mapbender/http/MeTaDor/inspirevalidate.php
   trunk/metador/mapbender/http/MeTaDor/mb_md_editor_search_data_server.php
   trunk/metador/mapbender/http/MeTaDor/xmlexport.php
   trunk/metador/mapbender/http/MeTaDor/xmlprint.php
   trunk/metador/mapbender/resources/update_2.7_metador_pgsql_UTF-8.sql
Log:
* change GUI Abstract to 'Application to edit metadata'

* changed SQLs in the scripts to store the data in table mb_metadata instead of mb_metadta_data
** changed columns 
*** metadata_id (instead of id), 
*** data (instead of xml), 
*** lastchanged (instead of date)

** changed view to view_mb_metadata instead of view_mb_metadta_data
**** view contains metadata_id as id as an additional column

Store origin 'MeTaDor-full' to know where the metadata came from


Modified: trunk/metador/mapbender/http/MeTaDor/class_MdMetadata.php
===================================================================
--- trunk/metador/mapbender/http/MeTaDor/class_MdMetadata.php	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/http/MeTaDor/class_MdMetadata.php	2011-07-08 07:41:15 UTC (rev 7921)
@@ -14,7 +14,7 @@
 
 class MdMetadata implements RPCObject {
 
-	private $id;
+	private $metadata_id;
 	var $uuid;
 	var $copyof;
 	var $title;
@@ -56,12 +56,12 @@
 
 
     /**
-     * Returns $id.
-     * @see MdMetadata::$id
+     * Returns $metadata_id.
+     * @see MdMetadata::$metadata_id
      */
     public function getId()
     {
-        return intval($this->id);
+        return intval($this->metadata_id);
     }
     
 
@@ -94,11 +94,11 @@
 	
 	public function __construct () {
 		if (func_num_args() === 1) {
-			$this->id = intval(func_get_arg(0));
+			$this->metadata_id = intval(func_get_arg(0));
 		}
 
 		try{
-			if (!is_null($this->id)) {
+			if (!is_null($this->metadata_id)) {
 				$this->load();
 			}
 		}
@@ -108,7 +108,7 @@
 	}
 	
 	public static function byUUID($uuid){
-		$sql = "SELECT id FROM view_mb_metadata_data";
+		$sql = "SELECT metadata_id FROM view_mb_metadata";
 
 		$filter = new Filter("AND", array(
 			new Filter("=", "uuid", $uuid), 
@@ -122,7 +122,7 @@
 		$res = db_prep_query($sql, $v, $t);
 		$row = db_fetch_assoc($res);
 		if ($row) {
-			return new self($row['id']);
+			return new self($row['metadata_id']);
 		}
 		else {
 			throw new Exception("Trying to load Record with invalid UUID: $uuid, $sql");
@@ -290,12 +290,12 @@
 
 	public function load () {
 
-		$sql = "SELECT id, uuid, copyof, title, status, responsible_party,responsible_party_name, responsible_party_id,
-fkey_mb_user_id, individual_name,individual_name_id, date, xml, visibility, type
-FROM view_mb_metadata_data";
+		$sql = "SELECT metadata_id, uuid, copyof, title, status, responsible_party,responsible_party_name, responsible_party_id,
+fkey_mb_user_id, individual_name,individual_name_id, lastchanged, data, visibility, type
+FROM view_mb_metadata";
 
 		$filter = new Filter("AND", array(
-			new Filter("=", "id", $this->getId()), 
+			new Filter("=", "metadata_id", $this->getId()), 
 			self::getReadAccessFilter()
 		));
 		$sqlObject = $filter->toSql();
@@ -319,13 +319,13 @@
 			$this->fkey_mb_user_id = $row["fkey_mb_user_id"];
 			$this->individual_name = $row["individual_name_id"];
 			$this->individual_name_name = $row["individual_name"];
-			$this->date = $row["date"];
-			$this->xml = new MdMetadataXml($row["xml"]);
+			$this->date = $row["lastchanged"];
+			$this->xml = new MdMetadataXml($row["data"]);
 			$this->type = $row["type"];
 			$this->visibility = $row["visibility"];
 		}
 		else {
-			$this->id = null;
+			$this->metadata_id = null;
 		}
 	}
 	
@@ -341,7 +341,7 @@
 			return false;
 		}
 		
-		$sql = "SELECT uuid from mb_metadata_data where uuid = $1";
+		$sql = "SELECT uuid from mb_metadata where uuid = $1";
 		$v = array($uuid);
 		$t = array('s');
 		$res = db_prep_query($sql,$v,$t);
@@ -352,7 +352,7 @@
 	}
 	
 	public static function getCount ($aFilter) {
-		$sql = "SELECT COUNT(id) FROM view_mb_metadata_data";
+		$sql = "SELECT COUNT(metadata_id) FROM view_mb_metadata";
 
 		$filter = new Filter("AND", array(
 			self::getReadAccessFilter(),
@@ -378,7 +378,7 @@
 		$limit = func_num_args() >= 3 ? func_get_arg(2) : null;
 		$offset = func_num_args() >= 4 ? func_get_arg(3) : null;
 		
-		$sql = "SELECT id FROM view_mb_metadata_data";
+		$sql = "SELECT metadata_id FROM view_mb_metadata";
 
 		$filter = new Filter("AND", array(
 			self::getReadAccessFilter(),
@@ -397,8 +397,8 @@
 		$res = db_prep_query($sql, $v, $t);
 		$metadataArray = array();
 		while ($row = db_fetch_assoc($res)) {
-			$id = intval($row["id"]);
-			$metadata = new MdMetadata($id);
+			$metadata_id = intval($row["metadata_id"]);
+			$metadata = new MdMetadata($metadata_id);
 			if ($metadata->isValid()) {
 				$metadataArray[]= $metadata;
 			}
@@ -407,7 +407,7 @@
 	}
 	
 	public function isValid () {
-		if (!is_null($this->id)) {
+		if (!is_null($this->metadata_id)) {
 			return true;
 		}
 		return false;
@@ -422,9 +422,9 @@
 		$this->date = date("Y-m-d");
 
 			$sql = <<<SQL
-UPDATE mb_metadata_data SET 
-fkey_mb_user_id = $1, date = $2, status = $3, xml = $4, title = $5, 
-responsible_party = $6, individual_name = $7, type = $8, visibility = $9,copyof = $10, uuid= $11, responsible_party_name = $12
+UPDATE mb_metadata SET 
+fkey_mb_user_id = $1, lastchanged = $2, status = $3, data = $4, title = $5, 
+responsible_party = $6, individual_name = $7, type = $8, visibility = $9,copyof = $10, uuid= $11, responsible_party_name = $12, origin = $13
 SQL;
 		$v = array(
 			Mapbender::session()->get('mb_user_id'),
@@ -438,17 +438,18 @@
 			$this->visibility,
 			$this->copyof,
 			$this->uuid,
-			$this->responsible_party_name
+			$this->responsible_party_name,
+			'MeTaDoR-full'
 		);
-		$t = array('i', 's', 's', 's', 's', 'i', 'i', 's', 's', 's','s','s');
-		if($this->id){
+		$t = array('i', 's', 's', 's', 's', 'i', 'i', 's', 's', 's','s','s','s');
+		if($this->metadata_id){
 
-			$sql .= " WHERE id = $13";
-			$v[] = $this->id;
+			$sql .= " WHERE metadata_id = $14";
+			$v[] = $this->metadata_id;
 			$t[] = 'i';
 
 		}else{
-			$sql .= " WHERE uuid = $13";
+			$sql .= " WHERE uuid = $14";
 			$v[] = $this->uuid;
 			$t[] = 's';
 		}
@@ -473,9 +474,9 @@
 			throw new Exception (_mb("Not allowed to remove metadata record."));
 		}
 
-		$sql = "DELETE FROM mb_metadata_data";
+		$sql = "DELETE FROM mb_metadata";
 
-		$filter = new Filter("=", "id", $this->getId());
+		$filter = new Filter("=", "metadata_id", $this->getId());
 		
 		$sqlObject = $filter->toSql();
 		$sql .= " WHERE " . $sqlObject->sql;
@@ -506,7 +507,7 @@
 		
 		db_begin();
 
-		$sql_group_create = "INSERT INTO mb_metadata_data (uuid) VALUES ($1)";
+		$sql_group_create = "INSERT INTO mb_metadata (uuid) VALUES ($1)";
 		$v = array($this->uuid);
 		$t = array("s");
 		$insert_result = db_prep_query($sql_group_create, $v, $t);
@@ -516,9 +517,9 @@
 			throw new Exception (_mb("Could not insert new metadata record."));
 		}
 		
-		$id = db_insertid($insert_result,'mb_metadata_data', 'id');
-		if ($id != 0) {
-			$this->id = intval($id);
+		$metadata_id = db_insertid($insert_result,'mb_metadata', 'metadata_id');
+		if ($metadata_id != 0) {
+			$this->metadata_id = intval($metadata_id);
 		}
 		
 		try {

Modified: trunk/metador/mapbender/http/MeTaDor/inspirevalidate.php
===================================================================
--- trunk/metador/mapbender/http/MeTaDor/inspirevalidate.php	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/http/MeTaDor/inspirevalidate.php	2011-07-08 07:41:15 UTC (rev 7921)
@@ -21,12 +21,12 @@
 $path = tempnam("/tmp","mb_inspireval");
 
 
-$recordSQL = "SELECT xml from mb_metadata_data WHERE id = $1;";
+$recordSQL = "SELECT data from mb_metadata WHERE metadata_id = $1;";
 $result = db_prep_query($recordSQL,array($id),array(i));
 $row = db_fetch_array($result);
 
 if($row){
-	file_put_contents($path,$row['xml']);
+	file_put_contents($path,$row['data']);
 }else{
 	die("invalid id");
 }

Modified: trunk/metador/mapbender/http/MeTaDor/mb_md_editor_search_data_server.php
===================================================================
--- trunk/metador/mapbender/http/MeTaDor/mb_md_editor_search_data_server.php	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/http/MeTaDor/mb_md_editor_search_data_server.php	2011-07-08 07:41:15 UTC (rev 7921)
@@ -43,7 +43,7 @@
 				$v[]= $reg->getId();
 				$t[]= "i";
 			}
-			$sql = "SELECT DISTINCT mb_group_name FROM mb_group, mb_metadata_data " . 
+			$sql = "SELECT DISTINCT mb_group_name FROM mb_group, mb_metadata " . 
 				"WHERE mb_group_id = responsible_party AND " . 
 				"responsible_party IN (" . implode(",", $vars) . ")";
 				
@@ -91,7 +91,7 @@
 				$v[]= $user->id;
 				$t[]= "i";
 			}
-			$sql = "SELECT DISTINCT mb_user_name FROM mb_user, mb_metadata_data " . 
+			$sql = "SELECT DISTINCT mb_user_name FROM mb_user, mb_metadata " . 
 				"WHERE mb_user_id = individual_name AND " . 
 				"individual_name IN (" . implode(",", $vars) . ")";
 				
@@ -137,7 +137,7 @@
 				$v[]= $user->id;
 				$t[]= "i";
 			}
-			$sql = "SELECT DISTINCT mb_user_name FROM mb_user, mb_metadata_data " . 
+			$sql = "SELECT DISTINCT mb_user_name FROM mb_user, mb_metadata " . 
 				"WHERE mb_user_id = fkey_mb_user_id AND " . 
 				"fkey_mb_user_id IN (" . implode(",", $vars) . ")";
 				

Modified: trunk/metador/mapbender/http/MeTaDor/xmlexport.php
===================================================================
--- trunk/metador/mapbender/http/MeTaDor/xmlexport.php	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/http/MeTaDor/xmlexport.php	2011-07-08 07:41:15 UTC (rev 7921)
@@ -21,15 +21,15 @@
 $path = tempnam("/tmp","mb_inspireval");
 
 
-$recordSQL = "SELECT uuid,xml from mb_metadata_data WHERE id = $1;";
+$recordSQL = "SELECT uuid, data from mb_metadata WHERE metadata_id = $1;";
 $result = db_prep_query($recordSQL,array($id),array(i));
 
 if($row = db_fetch_array($result)){
 	header("Content-Type: application/xml");
 	header("Content-Disposition: attachment; filename=metador_".$row['uuid'].".xml");
-	echo $row['xml'];
+	echo $row['data'];
 	exit;
 }else{
-	die("invalid id");
+	die("invalid metadata_id");
 }
 ?>

Modified: trunk/metador/mapbender/http/MeTaDor/xmlprint.php
===================================================================
--- trunk/metador/mapbender/http/MeTaDor/xmlprint.php	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/http/MeTaDor/xmlprint.php	2011-07-08 07:41:15 UTC (rev 7921)
@@ -11,7 +11,7 @@
 
 
 	if(is_numeric($_GET["id"])) {
-		$recordSQL = "SELECT uuid,xml from mb_metadata_data WHERE id = $1;";
+		$recordSQL = "SELECT uuid, data from mb_metadata WHERE metadata_id = $1;";
 		$result = db_prep_query($recordSQL,array($_GET["id"]),array(i));
 		$row = db_fetch_array($result);
 		
@@ -20,7 +20,7 @@
 
 			// GET TYPE
 			$tmp = new DOMDocument();
-			if(!$tmp->loadXML($row['xml'])) {
+			if(!$tmp->loadXML($row[data])) {
 				Throw new Exception(__FILE__." : could not load xml.");
 			}
 
@@ -45,7 +45,7 @@
 				default : $filename = "metadata_data.json";
 			}
 
-			$metadataPrint = new MetadataPrint($row['xml'],$pathJson.$filename);
+			$metadataPrint = new MetadataPrint($row['data'],$pathJson.$filename);
 
 			// LOAD TEMPLATE CLASS AND SET PATH
 			$template = new Template($pathTemplates);

Modified: trunk/metador/mapbender/resources/update_2.7_metador_pgsql_UTF-8.sql
===================================================================
--- trunk/metador/mapbender/resources/update_2.7_metador_pgsql_UTF-8.sql	2011-07-08 07:40:54 UTC (rev 7920)
+++ trunk/metador/mapbender/resources/update_2.7_metador_pgsql_UTF-8.sql	2011-07-08 07:41:15 UTC (rev 7921)
@@ -1,7 +1,7 @@
 
--- METADOR GUI
+-- METADOR Application
 
-INSERT INTO gui (gui_id, gui_name, gui_description, gui_public) VALUES ('MeTaDor','MeTaDor','application_metadata_editor',1);
+INSERT INTO gui (gui_id, gui_name, gui_description, gui_public) VALUES ('MeTaDor','MeTaDor','Application to edit metadata',1);
 INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element,e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires,e_url) VALUES ('MeTaDor','jq_ui',1,1,'The jQuery UI core','','','','',NULL ,NULL,NULL ,NULL,NULL ,'','','','','../extensions/jquery-ui-1.8.14.custom/js/jquery-ui-1.8.14.custom.min.js','','','');
 INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value, context, var_type) VALUES ('MeTaDor','jq_ui','css','../extensions/jquery-ui-1.7.2.custom/css/ui-lightness/jquery-ui-1.7.2.custom.css','','file/css');
 INSERT INTO gui_element (fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element,e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires,e_url) VALUES ('MeTaDor','mb_md_selectAction',1,1,'','Metadateneditorstartseite','div','','data="{path:''#mb_md_selectAction''}"',0,0,NULL ,NULL,NULL ,'','','div','../MeTaDor/mb_md_selectAction.js','','','','');
@@ -517,34 +517,50 @@
 
 
 -- METADATA TABLE
+-- Umschreiben auf die Tabelle mb_metadata
+--CREATE TABLE mb_metadata_data (
+--	id serial NOT NULL, -- metadata_id
+--	uuid character varying(100), -- uuid
+--	title character varying(250), -- t
+--	keywords text, -- ?
+--	date date, -- einfügedatum ? createdate lastchanged changedate --> lastchanged
+--	status character varying(50), -- status
+--	"type" character varying(50),--type
+--	"xml" text, --- data
+--	fkey_mb_user_id integer NOT NULL DEFAULT 1, -- wie
+--	responsible_party integer, --wie
+--	individual_name integer, -- wie
+--	visibility character varying(12), -- wie
+--	locked boolean DEFAULT false, -- wie 
+--	copyof character varying(100), -- wie
+--	responsible_party_name character varying(100) -- neu
+--);
+-- noch: origin MeTaDoR-full 
 
-CREATE TABLE mb_metadata_data (
-	id serial NOT NULL,
-	uuid character varying(100),
-	title character varying(250),
-	keywords text,
-	date date,
-	status character varying(50),
-	"type" character varying(50),
-	"xml" text,
-	fkey_mb_user_id integer NOT NULL DEFAULT 1,
-	responsible_party integer,
-	individual_name integer,
-	visibility character varying(12),
-	locked boolean DEFAULT false,
-	copyof character varying(100),
-	responsible_party_name character varying(100)
-);
-
-
 -- ADD VIEW
+-- new -- view on table mb_metadata
+DROP VIEW view_mb_metadata ;
+CREATE OR REPLACE VIEW view_mb_metadata AS
+ SELECT mb_metadata.metadata_id, 
+mb_metadata.metadata_id as id,  
+mb_metadata.uuid, 
+ mb_metadata.copyof, mb_metadata.title, 
+ mb_metadata.createdate, --date, 
+lastchanged,
+changedate,
+ mb_group.mb_group_name AS responsible_party, 
+mb_metadata.responsible_party_name,  -- neu
+ mb_group.mb_group_id AS responsible_party_id, 
+ kontakt.mb_user_name AS individual_name, 
+ kontakt.mb_user_id AS individual_name_id, 
+ mb_metadata.status, mb_metadata.visibility, 
+ mb_metadata.fkey_mb_user_id, 
+ mb_metadata.data, --xml, 
+ mb_metadata.type
+   FROM mb_user erfasser, mb_metadata
+   LEFT JOIN mb_group ON mb_metadata.responsible_party = mb_group.mb_group_id
+   LEFT JOIN mb_user kontakt ON mb_metadata.individual_name = kontakt.mb_user_id
+WHERE mb_metadata.fkey_mb_user_id = erfasser.mb_user_id;
 
-CREATE OR REPLACE VIEW view_mb_metadata_data AS
- SELECT mb_metadata_data.id, mb_metadata_data.uuid, mb_metadata_data.copyof, mb_metadata_data.title, mb_metadata_data.date, mb_group.mb_group_name AS responsible_party, mb_metadata_data.responsible_party_name, mb_group.mb_group_id AS responsible_party_id, kontakt.mb_user_name AS individual_name, kontakt.mb_user_id AS individual_name_id, mb_metadata_data.status, mb_metadata_data.visibility, mb_metadata_data.fkey_mb_user_id, mb_metadata_data.xml, mb_metadata_data.type
-   FROM mb_user erfasser, mb_metadata_data
-   LEFT JOIN mb_group ON mb_metadata_data.responsible_party = mb_group.mb_group_id
-   LEFT JOIN mb_user kontakt ON mb_metadata_data.individual_name = kontakt.mb_user_id
-WHERE mb_metadata_data.fkey_mb_user_id = erfasser.mb_user_id;
 
-
-
+ALTER TABLE mb_metadata ADD COLUMN responsible_party_name character varying(100);



More information about the Mapbender_commits mailing list