Source for file DBMS_JOINOBJ.phpclass

Documentation is available at DBMS_JOINOBJ.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file DBMS_JOINOBJ.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-09.07.2008
  12.   * @version $Id: DBMS_JOINOBJ.phpclass,v 1.1 2008/07/09 13:21:59 pitlinz Exp $
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.  
  19.     pcf_require_class('DBMS_TABLEOBJ',dirname(__FILE__)"/");
  20.  
  21. /**
  22.   * openCSP class DBMS_JOINOBJ
  23.   *
  24.   * @project Open CSP-Management
  25.   * @package default
  26.   *
  27.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  28.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  29.   *
  30.   * @since pk-09.07.2008
  31.   * @version $Id: DBMS_JOINOBJ.phpclass,v 1.1 2008/07/09 13:21:59 pitlinz Exp $
  32.   */
  33. class DBMS_JOINOBJ extends DBMS_TABLEOBJ
  34. {
  35.     // ---------------------------------------------------------------------------
  36.     // constants
  37.     // ---------------------------------------------------------------------------
  38.     
  39.     /**
  40.      * @constant string CLASS_SRC_FILE
  41.      */
  42.     const CLASS_SRC_FILE = __FILE__;
  43.  
  44.     // ---------------------------------------------------------------------------
  45.     // class (static)
  46.     // ---------------------------------------------------------------------------
  47.     
  48.     /*** class vars ------------------------------------------------------ */
  49.     
  50.     /*** class methods --------------------------------------------------- */
  51.     
  52.     // ---------------------------------------------------------------------------
  53.     // object vars
  54.     // ---------------------------------------------------------------------------
  55.     
  56.     /*** compostion --------------------------------------------------- */
  57.     
  58.     /*** attributes  -------------------------------------------------- */
  59.     
  60.     /**
  61.      * array of tables used
  62.      * 
  63.      * the order of the tables defines the join order
  64.      * $myTables[0] is treaten as the master table all other
  65.      * depends on
  66.      * 
  67.      * @var array $myTables 
  68.      */
  69.     protected $myTables = array();
  70.     
  71.     /**
  72.      * array of columns used in the join
  73.      * 
  74.      *  
  75.      *          
  76.      * @var array $myJoinCols 
  77.      */
  78.     protected $myJoinCols = array();
  79.     
  80.     // ---------------------------------------------------------------------------
  81.     // factory / construct
  82.     // ---------------------------------------------------------------------------
  83.     
  84.     /**
  85.       * initalize the object
  86.       *
  87.       *     - tries to get the object from cache
  88.       *     - if fails load it from db
  89.       *       and write it to chache
  90.       *     - set initTS to now
  91.       *
  92.       * @param boolean $debug      version pk-03-10-24
  93.       * @param boolean $noCache    version pk-06-05-27
  94.       *
  95.       */
  96.     function init($debug=False,$noCache=False)    
  97.     {
  98.         if($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_JOINOBJ::init()");
  99.         
  100.         if (!is_array($this->myTables|| !sizeof($this->myTables))
  101.         {
  102.             throw new Exception(_OCSP_EXCEP_NOTCONFIGURED_.": \$this->myTables not set");
  103.         }
  104.         
  105.         $this->myTable = $this->myTables[0];
  106.         
  107.         $this->_getDBFields($debug);
  108.         
  109.         $this->initTS=time();
  110.         $this->populateTS=0;        
  111.     }
  112.     
  113.     // ---------------------------------------------------------------------------
  114.     // getter / setter
  115.     // ---------------------------------------------------------------------------    
  116.  
  117.     // ---------------------------------------------------------------------------
  118.     // db table info methods
  119.     // ---------------------------------------------------------------------------    
  120.     
  121.     protected function _getDBFields($debug=False)
  122.     {
  123.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_JOINOBJ::_getDBFields");
  124.         
  125.         $arr_fields array();
  126.         foreach($this->myTables as $str_table)
  127.         {
  128.             if (isset(DBMS_TABLEOBJ::$dbTableDefinitions[$str_table]))
  129.             {
  130.                 $arr_tblFlds DBMS_TABLEOBJ::$dbTableDefinitions[$str_table];
  131.                 $arr_fields array_merge($arr_fields,$arr_tblFlds);    
  132.             else {
  133.                 pcf_require_class('OCSP_CACHE_FILE',"cache/");
  134.                 if ($arr_tblFlds OCSP_CACHE_FILE::getInstance('DBMS_TABLE_DESC')->getValue($str_table))
  135.                 {
  136.                     DBMS_TABLEOBJ::$dbTableDefinitions[$str_table$arr_tblFlds;
  137.                     $arr_fields array_merge($arr_fields,$arr_tblFlds);
  138.                 else if ($arr_tblFlds OCSP_OBJ::defaultReadDBObj()->getDBTblDesc($str_table)) {
  139.                     OCSP_CACHE_FILE::getInstance('DBMS_TABLE_DESC')->setValue($str_table,$arr_tblFlds,OCSP_CONF::getInstance('OCSP')->getValue('OBJCACHELIFETIME'));
  140.                     DBMS_TABLEOBJ::$dbTableDefinitions[$str_table$arr_tblFlds;
  141.                     $arr_fields array_merge($arr_fields,$arr_tblFlds);
  142.                 else {
  143.                     throw new Exception(_OCSP_EXCEP_TABLENOTFOUND_ ":" $str_table);
  144.                 }                
  145.             }
  146.             
  147.             foreach($arr_fields as $str_key => $arr_fld
  148.             {
  149.                 if ($debugechoDebugLine(__FILE__,__LINE__,"\$arr_fld: <pre>" print_r($arr_fld,True"</pre>");
  150.                 $this->myFields[$str_key]=$arr_fld;
  151.                 if ($arr_fld['PRIMARY_KEY']{
  152.                     if ($debugechoDebugLine(__FILE__,__LINE__,"PRIMARY_KEY: " print_r($arr_fld,True)."</pre>");
  153.                     $this->myKeys[$str_key]['NAME']                $str_key;
  154.                     $this->myKeys[$str_key]['TYPE']                $arr_fld['TYPE'];
  155.                     $this->myKeys[$str_key]['AUTO_INCREMENT']    $arr_fld['AUTO_INCREMENT'];
  156.                     $this->myKeys[$str_key]['TABLE']             $str_table;
  157.                 }
  158.             }            
  159.             
  160.         }
  161.         
  162.     }
  163.     
  164.     
  165. }
  166.  
  167. ?>

Documentation generated on Thu, 08 Jan 2009 17:43:40 +0100 by phpDocumentor 1.4.0a2