eZ components PHP Cross Reference Developer Tools

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

title

Description

title

Description

title

Description

title

title

Body