[Mapbender-commits] r4731 - branches/ur_dev/install

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Sat Sep 26 13:37:18 EDT 2009


Author: uli
Date: 2009-09-26 13:37:17 -0400 (Sat, 26 Sep 2009)
New Revision: 4731

Added:
   branches/ur_dev/install/class_column.php
   branches/ur_dev/install/class_constraint.php
Modified:
   branches/ur_dev/install/class_database.php
   branches/ur_dev/install/class_dia.php
   branches/ur_dev/install/class_table.php
   branches/ur_dev/install/update.php
Log:


Added: branches/ur_dev/install/class_column.php
===================================================================
--- branches/ur_dev/install/class_column.php	                        (rev 0)
+++ branches/ur_dev/install/class_column.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -0,0 +1,18 @@
+<?php
+class Column{
+	private $name;
+	private $type;
+	private $value;
+	private $primaryKey;
+	
+	public function __construct($name,$type,$value,$primaryKey){
+		$this->name = $name;
+		$this->type = $type;
+		$this->value = $value;
+		$this->primaryKey = $primaryKey;
+	}
+	public function getName(){
+		return $this->name;
+	}
+}
+?>

Added: branches/ur_dev/install/class_constraint.php
===================================================================
--- branches/ur_dev/install/class_constraint.php	                        (rev 0)
+++ branches/ur_dev/install/class_constraint.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -0,0 +1,32 @@
+<?php
+abstract class Constraint{
+	protected $table;
+	
+}
+
+class ForeignKeyConstraint extends Constraint{
+
+	private $column;
+	private $referenceTable;
+	private $referenceColumn;
+	private $text;
+	
+	public function __construct($table, $column, $referenceTable, $referenceColumn, $text){
+		$this->table =  $table;
+		$this->column =  $column;
+		$this->referenceTable =  $referenceTable;
+		$this->referenceColumn =  $referenceColumn;
+		$this->text =  $text;
+	}
+}
+
+class PrimaryKeyConstraint extends Constraint{
+
+	private $columnArray;
+	
+	public function __construct($table, $columnArray){
+		$this->table = $table;
+		$this->columnArray = $columnArray;	
+	}
+}
+?>

Modified: branches/ur_dev/install/class_database.php
===================================================================
--- branches/ur_dev/install/class_database.php	2009-09-26 16:42:42 UTC (rev 4730)
+++ branches/ur_dev/install/class_database.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -1,8 +1,26 @@
 <?php
-class database{
+class Database{
+	private $tableArray = array();
+	
 	public function __construct(){
 		
 	}
 	
+	public function addTable($table){
+		if(is_a($table, "Table")){
+			$this->tableArray[] = $table;
+			return true;
+		}
+		return false;
+	}
+	
+	public function getTableByName($name){
+		foreach($this->tableArray as $table){
+			if($table->getName() == $name){
+				return $table;
+			}
+		}
+		return null;
+	}
 }
 ?>

Modified: branches/ur_dev/install/class_dia.php
===================================================================
--- branches/ur_dev/install/class_dia.php	2009-09-26 16:42:42 UTC (rev 4730)
+++ branches/ur_dev/install/class_dia.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -48,13 +48,13 @@
 			$key = $keys->item(0);
 			if ($i === 1) {
 				$left = $this->removeHash($key->firstChild->nodeValue);
-				$leftConnection = $key->parentNode->parentNode->nextSibling->firstChild->getAttribute("connection");
+				$leftConnection = $this->getTableNameById($key->parentNode->parentNode->nextSibling->firstChild->getAttribute("to"));
 				
 			}
 			else {
 				$right = $this->removeHash($key->firstChild->nodeValue);
 				$text = $this->removeHash($key->nextSibling->firstChild->nodeValue);
-				$rightConnection = $key->parentNode->parentNode->nextSibling->firstChild->nextSibling->getAttribute("connection");
+				$rightConnection = $this->getTableNameById($key->parentNode->parentNode->nextSibling->firstChild->nextSibling->getAttribute("to"));
 			}
 			
 
@@ -80,8 +80,7 @@
 		foreach($constraintIds as $constraintId){
 			$constraints[] = $this->getConstraintKeys($constraintId);
 		}
-		print_r($constraints);
-		return serialize($constraints);
+		return $constraints;
 	}
 	
 	private function getTableNodeById($id){
@@ -93,7 +92,18 @@
 			return $table;
 		}
 	}
+	private function getTableNameById($id){
+		$node = $this->getTableNodeById($id);
+		
+		$attributes = $node->childNodes;
+		foreach($attributes as $attribute){
+			if($attribute->getAttribute('name') == 'name'){
+				return $this->removeHash($attribute->firstChild->nodeValue);
+			}
+		}
+		
 	
+	}
 	
 	private function getTableIdByName($tablename){
 		$tables = $this->getTableNodes();

Modified: branches/ur_dev/install/class_table.php
===================================================================
--- branches/ur_dev/install/class_table.php	2009-09-26 16:42:42 UTC (rev 4730)
+++ branches/ur_dev/install/class_table.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -1,7 +1,40 @@
 <?php
-class table{
-	public function __construct(){
-		
+
+class Table{
+	
+	private $columnArray = array();
+	private $name;
+	private $constraintArray = array();
+	
+	public function __construct($name){
+		$this->name = $name;
 	}
+	
+	public function addColumn($column){
+		if(is_a($column, "Column")){
+			$this->columnArray[] = $column;
+			return true;
+		}
+		return false;
+	}
+	public function getName(){
+		return $this->name;
+	}
+	public function addConstraint($constraint){
+		if(is_a($constraint, "Constraint")){
+			$this->constraintArray[] = $constraint;
+			return true;
+		}
+		return false;
+	}
+	public function getColumnByName($name){
+		foreach($this->columnArray as $column){
+			if($column->getName() == $name){
+				return $column;
+			}
+		}
+		return null;
+	}
+	
 }
 ?>

Modified: branches/ur_dev/install/update.php
===================================================================
--- branches/ur_dev/install/update.php	2009-09-26 16:42:42 UTC (rev 4730)
+++ branches/ur_dev/install/update.php	2009-09-26 17:37:17 UTC (rev 4731)
@@ -1,5 +1,10 @@
 <?php
 include("class_dia.php");
+include("class_database.php");
+include("class_table.php");
+include("class_column.php");
+include("class_constraint.php");
+
 $defaultfile = "../resources/db/schema_2.6.dia";
 
 fwrite(STDOUT, "Please enter the path to you *.dia file\n");
@@ -23,15 +28,42 @@
 
 //fwrite(STDOUT, "Hello $name");
 
+$db = new Database();
+
 $tables = $dia->getTableNames();
+
+
 foreach($tables as $table){
 	fwrite(STDOUT, "Found Tables: ".$table."\n");
+	$tab = new Table($table);
+
+	$db->addTable($tab);
+	
 	$columns = $dia->getColumns($table);
-	#print_r($columns);
+	foreach($columns as $column){
+		$col = new Column($column["name"],$column["type"],$column["value"],$column["primaryKey"]);
+		$tab->addColumn($col);
+	}
 }
 
+
+
 $constraints = $dia->getConstraints();
 
+foreach($constraints as $constraint){
+	$table = $db->getTableByName($constraint["rightConnection"]);
+	$column = $table->getColumnByName($constraint["right"]);
+	
+	$referenceTable = $db->getTableByName($constraint["leftConnection"]);
+	$referenceColumn = $table->getColumnByName($constraint["left"]);
+	
+	$const = new ForeignKeyConstraint($table, $column, $referenceTable, $referenceColumn, $constraint["text"]);
+	$tab->addConstraint($const);
+}
+
+var_dump($db);
+//
+exit(0);
 # fwrite(STDOUT, "	constraint: ".$constraint."\n");
 
 // von den rightConnection noch alle pk löschen (auf 0)



More information about the Mapbender_commits mailing list