home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / daogen / actions / generateVo.php < prev   
PHP Script  |  2004-03-08  |  3KB  |  110 lines

  1. <?php
  2. /*
  3. Copyright T & M Web Enterprises 2003
  4. Author: Mike Hostetler <mike@tm-web.com>
  5. Version: 1.0 Release date: 01 November 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. /**
  14.  *
  15.  *@NAME:        generateVo
  16.  *@PURPOSE:     To take an array of input parameters and generate a php Value Object
  17.  *@INPUT:       
  18.  *                @param $classname The name of the Vo class
  19.  *                @param $varname An indexed array of the variable names for the Value Object
  20.  *@ACTION:      Generate the code in ASCII text and return it
  21.  *@OUTPUT:      ASCII text of Vo code
  22.  *@EXCEPTIONS:  None
  23.  *@REMARKS:     None
  24.  *
  25.  */
  26.  
  27. function generateVo($classname,$varname) {
  28.     //We want to buffer all of this to return it
  29.     ob_start();
  30. ?>
  31. /**
  32. * <?php echo $classname;?> Value Object.
  33. * This class is a value object representing the database table. 
  34. * It is intented to be used together with associated Dao object. 
  35. */
  36.  
  37. /**
  38.  * Replace this with an inclusion of the parent valueObject class
  39.  */
  40.  
  41. class <?php echo $classname;?>Vo extends valueObject {
  42.  
  43.     /** 
  44.      * Persistent Instance variables. This data is directly 
  45.      * mapped to the columns of database table.
  46.      */
  47. <?php
  48.     foreach( $varname as $v )
  49.     {
  50.         printf("\tvar $%s = '';\n",$v);
  51.     }
  52.     ?>
  53.  
  54.     /** 
  55.      * Constructors. DaoGen generates two constructors by default.
  56.      * The first one takes no arguments and provides the most simple
  57.      * way to create object instance. The another one takes one
  58.      * argument, which is the primary key of the corresponding table.
  59.      */
  60.  
  61.     function  <?php echo $classname;?>Vo(<?php
  62.     $a = "";
  63.     foreach( $varname as $v )
  64.     {
  65.         $a .= sprintf("$%s = '', ",$v);
  66.     }
  67.     $a = substr_replace ( $a, "", -2 );
  68.     echo $a;
  69.     ?>) 
  70.     {
  71. <?php
  72.     foreach( $varname as $v )
  73.     {
  74.         printf("\t\t\$this->%s = $%s;\n",$v,$v);
  75.     }
  76.     ?>
  77.     }
  78.  
  79.  
  80.     /** 
  81.      * equals-method will compaire two vo instances
  82.      * and return true if they contain same values in all
  83.      * instance variables. If two objects are equal, it does
  84.      * not mean that they are the same instance. However it
  85.      * does mean that in that moment, they contain exactly 
  86.      * same data. (ie. they are mapped to same row in database.)
  87.      */
  88.     function equals(&$vo) 
  89.     {
  90. <?php
  91.     $a = "";
  92.     $b = "";
  93.     foreach( $varname as $v )
  94.     {
  95.         printf("\t\t%sif(\$this->%s != \$vo->%s)\n\t\t{\n\t\t\treturn FALSE;\n\t\t}\n",
  96.                 $b,$v,$v);
  97.         $b = "else";
  98.     }
  99.     echo $a;
  100.     ?>
  101.         return TRUE;
  102.     }
  103. }
  104. <?php
  105.     $contents = ob_get_contents();
  106.     ob_end_clean();
  107.     return $contents;
  108. }
  109. ?>
  110.