eZ components PHP Cross Reference Developer Tools

Source: /PersistentObject/tests/data/persistent_test_object.php - 117 lines - 4128 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 PersistentTestObject
  18  {
  19      public $id = null;
  20      public $varchar = null;
  21      public $integer = null;
  22      public $decimal = null;
  23      public $text = null;
  24  
  25      /**
  26       * Inserts some data to use for testing.
  27       */
  28      public static function insertCleanData()
  29      {
  30          $db = ezcDbInstance::get();
  31          $db->exec( "insert into " . $db->quoteIdentifier( "PO_test" ) . " (" 
  32              . $db->quoteIdentifier( "type_varchar" ) . ", " . $db->quoteIdentifier( "type_integer" ) . ", "
  33              . $db->quoteIdentifier( "type_decimal" ) . ", " . $db->quoteIdentifier( "type_text" ) . " )
  34                      VALUES ('Sweden', 9006405, 449.96, 'Sweden has nice girls!' )" );
  35  
  36          $db->exec( "insert into " . $db->quoteIdentifier( "PO_test" ) . " ("
  37              . $db->quoteIdentifier( "type_varchar" ) . ", " . $db->quoteIdentifier( "type_integer" ) . ", "
  38              . $db->quoteIdentifier( "type_decimal" ) . ", " . $db->quoteIdentifier( "type_text" ) . " )
  39                      VALUES ('Norway', 4593041, 385.19, 'Norway has brown goat cheese!' )" );
  40  
  41          $db->exec( "insert into " . $db->quoteIdentifier( "PO_test" ) . " ("
  42              . $db->quoteIdentifier( "type_varchar" ) . ", " . $db->quoteIdentifier( "type_integer" ) . ", "
  43              . $db->quoteIdentifier( "type_decimal" ) . ", " . $db->quoteIdentifier( "type_text" ) . " )
  44                      VALUES ('Ukraine', 47732079, 603.70, 'Ukraine has a long coastline to the black see.' )" );
  45  
  46          $db->exec( "insert into " . $db->quoteIdentifier( "PO_test" ) . " ("
  47              . $db->quoteIdentifier( "type_varchar" ) . ", " . $db->quoteIdentifier( "type_integer" ) . ", "
  48              . $db->quoteIdentifier( "type_decimal" ) . ", " . $db->quoteIdentifier( "type_text" ) . " )
  49                      VALUES ('Germany', 82443000, 357.02, 'Home of the lederhosen!.' )" );
  50      }
  51  
  52      /**
  53       * Saves the schema from database to file.
  54       *
  55       * Use this method if you have changed the definition of the persistent object
  56       * and need to update the file on disk.
  57       */
  58      public function saveSchema()
  59      {
  60          $db = ezcDbInstance::get();
  61          $schema = ezcDbSchema::createFromDb( $db );
  62          $schema->writeToFile( 'array', dirname( __FILE__ ) . '/persistent_test_object.dba' );
  63      }
  64  
  65      /**
  66       * Loads the schema from file into the database.
  67       *
  68       * If autoIncrement is set to false a schema with the id field not set to autoincrement is used.
  69       */
  70      public static function setupTable()
  71      {
  72          $db = ezcDbInstance::get();
  73          $schema = ezcDbSchema::createFromFile( 'array', dirname( __FILE__ ) . '/persistent_test_object.dba' );
  74          $schema->writeToDb( $db );
  75      }
  76  
  77      public static function cleanup()
  78      {
  79          $db = ezcDbInstance::get();
  80          if ( $db->getName() == "oracle" )
  81          {
  82              $db->exec( "DROP SEQUENCE " . $db->quoteIdentifier( "PO_test_id_seq" ) );
  83          }
  84          $db->exec( "DROP TABLE " . $db->quoteIdentifier( "PO_test" ) );
  85      }
  86  
  87      /*
  88      public function saveSqlSchemas()
  89      {
  90          $db = ezcDbInstance::get();
  91          $schema = ezcDbSchema::createFromFile( 'php', dirname( __FILE__ ) . '/persistent_test_object.dba' );
  92          $schema->writeToFile( dirname( __FILE__ ) . '/persistent_test_object-pgsql.sql', 'pgsql-file', 'schema' );
  93      }
  94      */
  95  
  96      public function setState( array $state )
  97      {
  98          foreach ( $state as $key => $value )
  99          {
 100              $this->$key = $value;
 101          }
 102      }
 103  
 104      public function getState()
 105      {
 106          $result = array();
 107          $result['id'] = $this->id;
 108          $result['decimal'] = $this->decimal;
 109          $result['varchar'] = $this->varchar;
 110          $result['integer'] = $this->integer;
 111          $result['text'] = $this->text;
 112          $result['no_such_var'] = "bah"; // This is here to make sure it does not provoke an error.
 113          return $result;
 114      }
 115  }
 116  
 117  ?>

title

Description

title

Description

title

Description

title

title

Body