Author: dr
Date: Thu Aug  2 11:52:54 2007
New Revision: 5806

Log:
- Implemented multiple datafields updates and storage for the Database store.

Modified:
    trunk/Tree/src/stores/db_external.php
    trunk/Tree/tests/db_parent_child_tree.php
    trunk/Tree/tests/db_tree.php
    trunk/Tree/tests/files/parent_child.dba

Modified: trunk/Tree/src/stores/db_external.php
==============================================================================
--- trunk/Tree/src/stores/db_external.php [iso-8859-1] (original)
+++ trunk/Tree/src/stores/db_external.php [iso-8859-1] Thu Aug  2 11:52:54 2007
@@ -120,6 +120,7 @@
     {
         if ( $this->dataField === null )
         {
+            unset( $data[$this->idField] );
             return $data;
         }
         return $data[$this->dataField];
@@ -220,6 +221,10 @@
         // Add set statements
         if ( $this->dataField === null )
         {
+            foreach( $node->data as $field => $value )
+            {
+               $q->set( $db->quoteIdentifier( $field ), $q->bindValue( $value 
) );
+            }
         }
         else
         {

Modified: trunk/Tree/tests/db_parent_child_tree.php
==============================================================================
--- trunk/Tree/tests/db_parent_child_tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/db_parent_child_tree.php [iso-8859-1] Thu Aug  2 11:52:54 
2007
@@ -276,7 +276,49 @@
         $node8 = $tree->fetchNodeById( 8 ); // returns 8
         self::assertType( 'ezcTreeNode', $node8 );
         self::assertSame( '8', $node8->id );
-        self::assertSame( array( 'data' => 'Node 8', 'id' => '8' ), 
$node8->data );
+        self::assertSame( array( 'data' => 'Node 8' ), $node8->data );
+    }
+
+    public function testStoreUpdatedDataMultipleDataFields()
+    {
+        $this->emptyTables();
+
+        $store = new ezcTreeDbExternalTableDataStore( $this->dbh, 'datam', 
'id' );
+        $tree = ezcTreeDbParentChild::create(
+            $this->dbh,
+            'parent_child',
+            $store
+        );
+
+        $root = $tree->createNode( 1, array( 'name' => 'Harald V', 'born' => 
'1937' ) );
+        $tree->setRootNode( $root );
+
+        $root->addChild( $tree->createNode( 2, array( 'name' => 'Haakon', 
'born' => '1973' ) ) );
+        $root->addChild( $tree->createNode( 3, array( 'name' => 'Märtha 
Louise', 'born' => '1971' ) ) );
+
+        // start over
+        $store = new ezcTreeDbExternalTableDataStore( $this->dbh, 'datam', 
'id' );
+        $tree = new ezcTreeDbParentChild(
+            $this->dbh,
+            'parent_child',
+            $store
+        );
+
+        $haakon = $tree->fetchNodeById( 2 );
+        self::assertEquals( array( 'name' => 'Haakon', 'born' => '1973' ), 
$haakon->data );
+        $haakon->data = array( 'name' => 'Haakon', 'born' => 1981 );
+        $haakon->data = array( 'name' => 'Haakon', 'born' => 1983 );
+
+        // start over
+        $store = new ezcTreeDbExternalTableDataStore( $this->dbh, 'datam', 
'id' );
+        $tree = new ezcTreeDbParentChild(
+            $this->dbh,
+            'parent_child',
+            $store
+        );
+
+        $haakon = $tree->fetchNodeById( 2 );
+        self::assertEquals( array( 'name' => 'Haakon', 'born' => '1983' ), 
$haakon->data );
     }
 
     public static function suite()

Modified: trunk/Tree/tests/db_tree.php
==============================================================================
--- trunk/Tree/tests/db_tree.php [iso-8859-1] (original)
+++ trunk/Tree/tests/db_tree.php [iso-8859-1] Thu Aug  2 11:52:54 2007
@@ -69,6 +69,7 @@
         {
             $this->dbh->exec( 'DROP TABLE parent_child' );
             $this->dbh->exec( 'DROP TABLE data' );
+            $this->dbh->exec( 'DROP TABLE datam' );
         }
         catch ( Exception $e )
         {

Modified: trunk/Tree/tests/files/parent_child.dba
==============================================================================
--- trunk/Tree/tests/files/parent_child.dba [iso-8859-1] (original)
+++ trunk/Tree/tests/files/parent_child.dba [iso-8859-1] Thu Aug  2 11:52:54 
2007
@@ -80,6 +80,54 @@
         )),
       ),
     )),
+    'datam' => 
+    ezcDbSchemaTable::__set_state(array(
+       'fields' => 
+      array (
+        'id' => 
+        ezcDbSchemaField::__set_state(array(
+           'type' => 'integer',
+           'length' => 0,
+           'notNull' => true,
+           'default' => NULL,
+           'autoIncrement' => false,
+           'unsigned' => false,
+        )),
+        'name' => 
+        ezcDbSchemaField::__set_state(array(
+           'type' => 'text',
+           'length' => 255,
+           'notNull' => true,
+           'default' => NULL,
+           'autoIncrement' => false,
+           'unsigned' => false,
+        )),
+        'born' => 
+        ezcDbSchemaField::__set_state(array(
+           'type' => 'text',
+           'length' => 5,
+           'notNull' => true,
+           'default' => NULL,
+           'autoIncrement' => false,
+           'unsigned' => false,
+        )),
+      ),
+      'indexes' => 
+      array (
+        'primary' => 
+        ezcDbSchemaIndex::__set_state(array(
+          'indexFields' => 
+          array (
+            'id' => 
+            ezcDbSchemaIndexField::__set_state(array(
+               'sorting' => NULL,
+            )),
+          ),
+          'primary' => true,
+          'unique' => true,
+        )),
+      ),
+    )),
   ),
   1 =>
   array(


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to