Source for file dbobject.php

Documentation is available at dbobject.php

  1. <?php
  2. /**
  3. * database object base class (self-initialising and self-updating object)
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /** database connection script */
  17. require_once 'inc/db.php';
  18. /** sql manipulation routines */
  19. require_once 'sql.php';
  20. /** status codes for success/failure of database actions */
  21. require_once 'inc/statuscodes.php';
  22.  
  23. /**
  24. * database object base class (self-initialising and self-updating object)
  25. *
  26. @package    Bumblebee
  27. @subpackage FormsLibrary
  28. */
  29. class DBO {
  30.   /** @var string   db table from which to take data */
  31.   var $table;
  32.   /** @var string   db column that is the id/key */
  33.   var $idfield;
  34.   /** @var string   ??? FIXME: unused? */
  35.   var $idfieldreal;
  36.   /** @var string   the id/key value for this particlar row. -1 means not assigned yet (new object not in table) */
  37.   var $id=-1;
  38.   /** @var boolean  if true, *don't* use the ID field in updates etc */
  39.   var $ignoreId = false;
  40.   /** @var array    list of Field objects in this row */
  41.   var $fields;
  42.   /** @var boolean  this field is able to be edited by the user  */
  43.   var $editable = 0;
  44.   /** @var boolean  this field is able to be deleted (or marked as deleted) */
  45.   var $deletable = 1;
  46.   /** @var boolean  the fields in this row have changed cf the database */
  47.   var $changed = 0;
  48.   /** @var boolean  the data in the fields are valid */
  49.   var $isValid = 0;
  50.   /** @var boolean  don't do validation on the data */
  51.   var $suppressValidation = 0;
  52.   /** @var string   output when doing text dumps of the object */
  53.   var $dumpheader = 'DBO object';
  54.   /** @var boolean  sql errors should be considered fatal and the script will die()  */
  55.   var $fatal_sql = 1;
  56.   /** @var string   prefixed to all name="$field[name]" sections of the html code */
  57.   var $namebase;
  58.   /** @var string   current error message  */
  59.   var $errorMessage = '';
  60.   /** @var integer  status code from operation from statuscodes.php  */
  61.   var $oob_status = STATUS_NOOP;
  62.   /** @var string    */
  63.   var $oob_errorMessage = '';
  64.  
  65.   /** @var integer   debug level 0=off    */
  66.   var $DEBUG = 0;
  67.  
  68.   /**
  69.   *  Create a new database object, designed to be superclasses
  70.   *
  71.   * @param string $table   see $this->table
  72.   * @param string $id       see $this->id
  73.   * @param mixed $idfield  if string, $this->idfield. if array, ($this->idfield, $this->idfieldreal).
  74.   */
  75.   function DBO($table$id$idfield 'id'{
  76.     $this->table = $table;
  77.     $this->id = $id;
  78.     if (is_array($idfield)) {
  79.       $this->idfieldreal = $idfield[0];
  80.       $this->idfield = $idfield[1];
  81.     else {
  82.       $this->idfield = $idfield;
  83.     }
  84.     $this->fields = array();
  85.   }
  86.  
  87.   /**
  88.   *  Sets a new name base for row and all fields within it
  89.   *
  90.   * The name base is prepended to the field name in all html name="" sequences for the widgets
  91.   * @param string $newname  new name-base to use
  92.   */
  93.   function setNamebase($newname=''{
  94.     $this->namebase = $newname;
  95.     foreach (array_keys($this->fieldsas $k{
  96.       $this->fields[$k]->setNamebase($newname);
  97.     }
  98.   }
  99.  
  100.   /**
  101.   * Sets whether a row and all fields within it are editable
  102.   *
  103.   * @param boolean $editable  new editable state
  104.   */
  105.   function setEditable($editable=1{
  106.     $this->editable = $editable;
  107.     foreach (array_keys($this->fieldsas $k{
  108.       $this->fields[$k]->setEditable($editable);
  109.     }
  110.   }
  111.  
  112.   /**
  113.   * Create a quick text representation of the object
  114.   *
  115.   * @return string text representation
  116.   */
  117.   function text_dump({
  118.     $t  "<pre>$this->dumpheader $this->table (id=$this->id)\n{\n";
  119.     foreach ($this->fields as $v{
  120.       $t .= "\t".$v->text_dump();
  121.     }
  122.     $t .= "}\n</pre>";
  123.     return $t;
  124.   }
  125.  
  126.   /**
  127.   * Display the object
  128.   *
  129.   * @return string object representation
  130.   */
  131.   function display({
  132.     return $this->text_dump();
  133.   }
  134.  
  135.   /**
  136.   * Debug print function.
  137.   *
  138.   * @param string $logstring debug message to be output
  139.   * @param integer $priority  priority of the message, will not be written unless $priority <= $this->DEBUG
  140.   */
  141.   function log($logstring$priority=10{
  142.     if ($priority <= $this->DEBUG{
  143.       echo $logstring."<br />\n";
  144.     }
  145.   }
  146.  
  147.   /**
  148.   * PHP5 clone method
  149.   *
  150.   * PHP5 clone statement will perform only a shallow copy of the object. Any subobjects must also be cloned
  151.   */
  152.   function __clone({
  153.     //print "send in the clones! I'm cloning a ".get_class($this)."<br />";
  154.     //preDump($this->fields);
  155.     // Force a copy of contents of $this->fields array, otherwise the fields will only be references
  156.     $fields $this->fields;
  157.     $this->fields = array();
  158.     foreach ($fields as $k => $f{
  159.       //print "cloning $k<br />";
  160.       $this->fields[$kclone($f);
  161.     }
  162.     //print "done cloning";
  163.   }
  164.  
  165.  
  166. // class dbo
  167.  
  168. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:19 +0000 by phpDocumentor 1.3.0