Source for file OCSP_FORM_DBCONTROLL.phpclass

Documentation is available at OCSP_FORM_DBCONTROLL.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FORM_DBCONTROLL.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-08-04
  14.   *
  15.   ***/
  16.  
  17.     if (!defined('__OCSP_NO_DBFIELD__')) define('__OCSP_NO_DBFIELD__','__NO-DBFIELD__');
  18.  
  19. /**
  20.   * class OCSP_FORM_DBCONTROLL
  21.   *
  22.   * root class of database handling for form fields
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    forms
  26.   * @category   dbms_form
  27.   *
  28.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @since  pk-07-08-04
  32.   *
  33.   */
  34. {
  35.  
  36.     /**
  37.       * this constructure returns an object of the subclass able to
  38.       * deal with the database type of $aDBObj
  39.       *
  40.       * @param OCSP_DB $aDBObj 
  41.       * @param boolean $debug 
  42.       *
  43.       */
  44.     function newSubClass(&$aDBObj,$debug=FALSE)
  45.     {
  46.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_DBCONTROLL::newSubClass(".get_class($aDBObj).")");
  47.  
  48.         $str_subClassName=str_replace('OCSP_DB','OCSP_FORM_DBCTRL',get_class($aDBObj));
  49.         if (!class_exists($str_subClassName))
  50.         {
  51.             if (file_exists(dirname(__FILE__)._OCSP_DIRSEP_.$str_subClassName.".phpclass"))
  52.             {
  53.                 require_once dirname(__FILE__)._OCSP_DIRSEP_.$str_subClassName.".phpclass";
  54.             else {
  55.                 $str_subClassName=get_class($this);
  56.             }
  57.         }
  58.  
  59.         $str_cmd="\$obj_ret=new ".$str_subClassName."();";
  60.         eval($str_cmd);
  61.         if (!isset($obj_ret))
  62.         {
  63.             ocsp_logError(__FILE__,__LINE__,"could not eval $str_cmd");
  64.             return new OCSP_FORM_DBCONTROLL();
  65.         }
  66.         return $obj_ret;
  67.     }
  68.  
  69.     /** generates a colDesc
  70.       *
  71.       * @param string $colName 
  72.       * @param string $colType 
  73.       * @param string $table 
  74.       * @param string $size 
  75.       * @param boolean $debug 
  76.       *
  77.       * @return array 
  78.       *
  79.       */
  80.     function generateColDesc($colName,$colType,$table=__OCSP_NO_DBFIELD__,$size='0',$debug=FALSE)
  81.     {
  82.         return array(
  83.                 'NULL'              => TRUE,
  84.                 'AUTO_INCREMENT'    => FALSE,
  85.                 'PRIMARY_KEY'       => FALSE,
  86.                 'DEFAULT'           => '',
  87.                 'KEY'               => '',
  88.                 'COLNAME'           => $colName,
  89.                 'TABLE'             => $table,
  90.                 'TYPE'              => $colType,
  91.                 'LEN'               => $size,
  92.                 'FLAGS'             => NULL,
  93.             );
  94.     }
  95.  
  96.     /**
  97.       * @param array $colDesc 
  98.       * @param boolean $debug 
  99.       */
  100.     function generateField($colDesc,$debug=FALSE)
  101.     {
  102.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_DBCONTROLL::generateField()");
  103.  
  104.         require_once __OCSP_PHPINCPATH__."db"._OCSP_DIRSEP_."frmClasses"._OCSP_DIRSEP_."DBMS_FIELD.phpclass";
  105.         return new DBMS_FIELD($colDesc['TABLE'],$colDesc['COLNAME'],$colDesc);
  106.     }
  107.  
  108.     /**
  109.       * creates the field column in the database
  110.       *
  111.       * @param DBMS_FIELD $field (name or object)
  112.       * @param boolean $debug 
  113.       *
  114.       * @global array $OCSP_OBJ 
  115.       *
  116.       * @return boolean 
  117.       */
  118.     function createDBColumn(&$field,$debug)
  119.     {        
  120.         global $OCSP_OBJ;
  121.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_DBCTRL_mySQL::createDBColumn()");
  122.  
  123.         {
  124.             ocsp_logError(__FILE__,__LINE__,"no rights",E_NOTICE);
  125.             return FALSE;
  126.         }
  127.  
  128.         if (!pcf_is_instance_of($field,'DBMS_FIELD'))
  129.         {
  130.             ocsp_logError(__FILE__,__LINE__,"no field",E_WARNING);
  131.             return FALSE;
  132.         }
  133.  
  134.         $arr_desc=$field->getdbDesc();
  135.         $str_table=$field->getTable();
  136.  
  137.         if (!OCSP_OBJ::defaultReadDBObj()->tblExists($str_table))
  138.         {
  139.             
  140.             ocsp_logError(__FILE__,__LINE__,"$str_table does not exist",E_WARNING);
  141.             return FALSE;
  142.         }
  143.  
  144.         if (isset($arr_desc['NULL']&& !$arr_desc['NULL'])
  145.         {
  146.             if (!isset($arr_desc['DEFAULT']|| empty($arr_desc['DEFAULT']))
  147.             {
  148.                 $arr_desc['DEFAULT']=$field->getDefaultValue();
  149.                 if (empty($arr_desc['DEFAULT']))
  150.                 {
  151.                     $arr_desc['NULL']=TRUE;
  152.                 }
  153.             }
  154.         else {
  155.             $arr_desc['NULL']=TRUE;
  156.         }
  157.  
  158.         if (!isset($arr_desc['COLNAME']|| empty($arr_desc['COLNAME']))
  159.         {
  160.             $arr_desc['COLNAME']=$field->getName();
  161.             if (empty($arr_desc['COLNAME']))
  162.             {
  163.                 ocsp_logError(__FILE__,__LINE__,"no column name set",E_WARNING);
  164.                 return FALSE;
  165.             }
  166.         }
  167.  
  168.         if (OCSP_OBJ::defaultWriteDBObj()->addColumn($str_table,$arr_desc['COLNAME'],$arr_desc,$debug))
  169.         {
  170.             $field->setdbDesc($arr_desc);
  171.             return TRUE;
  172.         else {
  173.             return FALSE;
  174.         }
  175.     }
  176. }
  177.  
  178. ?>

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