eZ components PHP Cross Reference Developer Tools

Source: /PersistentObject/tests/data/multi_relation_test_person.php - 125 lines - 4748 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3  CREATE TABLE PO_test
   4  (
   5    id integer unsigned not null auto_increment,
   6    type_varchar varchar(20),
   7    type_integer integer,
   8    type_decimal decimal(10,2),
   9    type_text text,
  10  
  11    PRIMARY KEY (id)
  12  ) TYPE=InnoDB;
  13  
  14    type_date date,
  15  */
  16  
  17  class MultiRelationTestPerson
  18  {
  19      public $id     = null;
  20      public $name   = null;
  21      public $mother = null;
  22      public $father = null;
  23                  
  24      /**
  25       * Inserts some data to use for testing.
  26       */
  27      public static function insertData()
  28      {
  29          $db = ezcDbInstance::get();
  30          $db->exec( "insert into " . $db->quoteIdentifier( "PO_person" ) . " (" 
  31              . $db->quoteIdentifier( "name" ) . " )
  32                      VALUES ('Root mother without parents.')" );
  33          $db->exec( "insert into " . $db->quoteIdentifier( "PO_person" ) . " (" 
  34              . $db->quoteIdentifier( "name" ) . " )
  35                      VALUES ('Root father without parents.')" );
  36  
  37          $db->exec( "insert into " . $db->quoteIdentifier( "PO_person" ) . " (" 
  38              . $db->quoteIdentifier( "name" ) . ", " . $db->quoteIdentifier( "mother" ) . ", "
  39              . $db->quoteIdentifier( "father" ) . " )
  40                      VALUES ('First level child.', 1, 2)" );
  41          $db->exec( "insert into " . $db->quoteIdentifier( "PO_person" ) . " (" 
  42              . $db->quoteIdentifier( "name" ) . ", " . $db->quoteIdentifier( "mother" ) . ", "
  43              . $db->quoteIdentifier( "father" ) . " )
  44                      VALUES ('Second first level child.', 1, 2)" );
  45          $db->exec( "insert into " . $db->quoteIdentifier( "PO_person" ) . " (" 
  46              . $db->quoteIdentifier( "name" ) . ", " . $db->quoteIdentifier( "mother" ) . ", "
  47              . $db->quoteIdentifier( "father" ) . " )
  48                      VALUES ('Third first level child.', 1, 2)" );
  49  
  50          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  51              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  52                      VALUES (3, 4)" );
  53          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  54              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  55                      VALUES (3, 5)" );
  56          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  57              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  58                      VALUES (4, 3)" );
  59          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  60              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  61                      VALUES (4, 5)" );
  62          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  63              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  64                      VALUES (5, 3)" );
  65          $db->exec( "insert into " . $db->quoteIdentifier( "PO_sibling" ) . " (" 
  66              . $db->quoteIdentifier( "person" ) . ", " . $db->quoteIdentifier( "sibling" ) . " )
  67                      VALUES (5, 4)" );
  68      }
  69  
  70      /**
  71       * Saves the schema from database to file.
  72       *
  73       * Use this method if you have changed the definition of the persistent object
  74       * and need to update the file on disk.
  75       */
  76      public function saveSchema()
  77      {
  78          $db = ezcDbInstance::get();
  79          $schema = ezcDbSchema::createFromDb( $db );
  80          $schema->writeToFile( 'array', dirname( __FILE__ ) . '/multi_relation.dba' );
  81      }
  82  
  83      /**
  84       * Loads the schema from file into the database.
  85       *
  86       * If autoIncrement is set to false a schema with the id field not set to autoincrement is used.
  87       */
  88      public static function setupTables( $autoIncrement = true )
  89      {
  90          $db = ezcDbInstance::get();
  91          $schema = ezcDbSchema::createFromFile( 'array', dirname( __FILE__ ) . '/multi_relation.dba' );
  92          $schema->writeToDb( $db );
  93      }
  94  
  95      public static function cleanup()
  96      {
  97          $db = ezcDbInstance::get();
  98          if ( $db->getName() == "oracle" )
  99          {
 100              $db->exec( "DROP SEQUENCE " . $db->quoteIdentifier( "PO_person_id_seq" ) );
 101          }
 102          $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_person" ) );
 103          $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_sibling" ) );
 104      }
 105  
 106      public function setState( array $state )
 107      {
 108          foreach ( $state as $key => $value )
 109          {
 110              $this->$key = $value;
 111          }
 112      }
 113  
 114      public function getState()
 115      {
 116          $result = array();
 117          $result['id'] = $this->id;
 118          $result['name'] = $this->name;
 119          $result['mother'] = $this->mother;
 120          $result['father'] = $this->father;
 121          return $result;
 122      }
 123  }
 124  
 125  ?>

title

Description

title

Description

title

Description

title

title

Body