Source for file DBMS_TABLEOBJ.phpclass
Documentation is available at DBMS_TABLEOBJ.phpclass
* Class file dbms_tableobj.phpclass
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: DBMS_TABLEOBJ.phpclass,v 1.60 2008/12/17 16:28:52 peterkrebs Exp $
require_once __OCSP_PHPINCPATH__ .
'common' .
_OCSP_DIRSEP_ .
'OCSP_OBJ.phpclass';
require_once dirname(__FILE__
) .
_OCSP_DIRSEP_ .
"INFA_DBMS_TABLEOBJ.phpclass";
* Base class DBMS_TABLEOBJ to handel table data in an object
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: DBMS_TABLEOBJ.phpclass,v 1.60 2008/12/17 16:28:52 peterkrebs Exp $
/*** class constants --------------------------------------------- */
* @constant string CLASS_SRC_FILE
/*** class variables --------------------------------------------- */
* @staticvar array $staticClassVars vars which must not be copied
protected static $staticClassVars=
array('myClassSrcFile');
* array of already seen tables definitions
* @staticvar array $dbTableDefinitions
static $dbTableDefinitions =
array();
* @var array $myKeys array of db primary key columns
* @staticvar array $myFields array of db column description
* @var string $autoIncFld name of the auto incremental column
* @staticvar string $myTable NEED TO BE OVERRITTEN !!!!
* @var double $myCacheTS linux timestamp of the cache file
* @var int $myMode editing mode FRM_MODE_*
protected $myMode =
FRM_MODE_READONLY;
* @var double $valChangeTS timestamp values changed
* @var boolean $objError obj has errors
* @var string $objErrorMsg obj error message
* @var double $populateTS linux timestamp when DB_TBLOBJ::dbPopulateDB() was called
* @var double $initTS linux timestamp when DB_TBLOBJ::init() was called
* @var double $myObjValsPopulateTS
* array of linked (joined) table rows
* this is used if a form has subtables or joins which are
* not directly implemented in the table object class to change
* this values on insert,update or delete
* structure of the array:
* -- [ROW] => array COL => VALUE
* -- [OBJ] => DBMS_TABLEOBJ
* -- [CMD] => one of _OCSP_DBCMD_* cmd
* @var array $frmPostSubObjVals
if (!empty($tblName)) $this->myTable =
$tblName;
* sets the table name an recals init
* if $this->myTable != $aTablName
* @param string $aTblName
* @version pk-07-07-11 removed $gDBIDX param
if ($debug) echoDebug(__FILE__
,"<p>NO TABLE SET</p>",1);
if (!$this->initTS) $this->init($debug); // init tblobj if not done before
if ($debug) echoDebug(__FILE__
,"<p>table already initialized</p>",1);
$this->initTS=
0; // clear init timestamp
$this->init($debug,False); // <pk-06-05-27 />
* - tries to get the object from cache
* - if fails load it from db
* @param boolean $debug version pk-03-10-24
* @param boolean $noCache version pk-06-05-27
function init($debug=
False,$noCache=
False) {
echo
"<blockquote style=\"font-size: 60%;margin-right: 100px;\">";
if (empty($this->myTable)) { // <pk-06-05-27 />
if ($debug) echoDebug(__FILE__
,"<p>no Table set</p>",1);
} else if (!$this->cacheRestore($debug)) { // <pk-06-05-27 /> <pk-06-10-20/>
$this->initTS=
time(); // as cacheWriteTo only writes initialized objects this has to be set here
echo
"<p>initTS: ".
$this->initTS.
"</p></blockquote>";
* returns if the object is initialized
* returns the class source file
* if $this->classSrcFile is set
* add the following code to your class:
* * source file of the class
* * @staticvar string $classSrcFile
* protected $classSrcFile=__FILE__;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning \$this->classSrcFile: ".
$this->classSrcFile);
return $this->classSrcFile;
return $this->getClassFile(False,$debug);
* sets an array with keys
* @param boolean $debug since pk-06-05-28
foreach($keyArray as $key =>
$val) {
* @param boolean $debug since pk-06-05-28
function db_SetKey($kName,$kValue,$debug=
False) {
if ($debug) echoDebugMethod(__FILE__
,get_class($this),"DBMS_TABLEOBJ::db_SetKey",$kName.
" => ".
$kValue,0); // <pk-06-05-28 />
echoDebug(__FILE__
,"<p><b>ERROR</b>DBMS_TABLEOBJ::db_SetKey() EMPTY KEY (".
get_class($this).
")</p>",1);
* an array of all key fields
* returns if the primary key columns are set
foreach($this->myKeys as $str_col =>
$arr_desc)
if (!isset
($this->{$str_col}) ||
empty($this->{$str_col}))
* generates a where clause to select the object identfied by DBMS_TBLOBJ::myKeys
* @version pk-06-09-14 E_ALL
$s_query=
" WHERE "; // the return string
$s_and=
""; // used to add "AND" if more then one key is set
foreach($this->myKeys as $s_key =>
$val) {
if (!empty($s_key) && isset
($this->{$s_key})) { // <pk-06-09-14 />
if ($debug) echo
"<li>$s_key = ".
str_replace("'","\'",$this->{$s_key}).
"'</li>";
$s_query.=
$s_and .
$s_key.
" ='".
str_replace("'","\'",$this->{$s_key}).
"'";
} else if ($debug) { // <pk-06-09-14>
if ($s_query ==
" WHERE ") return "";
* returns the dbDesc array ($this->myFields);
if ($debug) echo
"<p>DBMS_TABLEOBJ::getDbDesc(...)</b> (".
get_class($this).
")</p>";
* returns the populate timestamp
* if it returns 0 the object has not been populated
* which means not that it is empty
* returns if populateTS > 0
* returns if valChangeTS > populateTS
* sets the changed flag ($this->valChangeTS > $this-populateTS)
* clears the changed flag
* populates the object from a key array
* NOTE if more columns fit $keys only the first is set
$str_query =
"SELECT * FROM ".
$this->myTable;
$str_query .=
$this->getDBObj('r')->qs_getWhereClause($keys,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Query: $str_query");
if ($arr_row =
$this->getDBObj('r')->quickQuery($str_query))
* populates the object by extracting keys from a value array
* @param array $arrValues
if (!is_array($arrValues)) return False;
foreach($arr_keys as $str_key =>
$arr_desc)
if (!isset
($arrValues[$str_key]))
$arr_filter[$str_key] =
$arrValues[$str_key];
* populates the object values form the database
* @since pk-03-12-18 calls $this->setDBRow() to set the object values
* @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
* @param boolean $debug SHOW DEBUG INFO
* @returns boolean found row ?
if ($debug) echo
"<blockquote style=\"font-size: 90%;background-color: #F0F0F0;\">";
if (empty($this->myTable)) { // from where ??
if ($debug) echo
"</blockquote>";
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"keys are not set",E_NOTICE);
if ($debug) echo
"</blockquote>";
$query =
"SELECT * FROM ".
$this->myTable;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Populate Query: $query");
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
if ($debug) echo
"</blockquote>";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Populate Query: $query");
if (!$row=
$this->getDBObj('r')->quickQuery($query)) {
if ($debug) echo
"</blockquote>";
if ($debug) echo
"</blockquote>";
$bol_ret =
$this->setDBRow($row,True,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"dbPopulate Returns: " .
($bol_ret ?
'True' :
'False'));
* populates the Object values
* @return int sizeof myObjVals
if ($debug) echo
"<p><b>DBMS_TABLEOBJ::populateObjVals()</b> (".
get_class($this).
")</p>";
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
// <pk-07-04-16 /> check if the outIncFld has a value
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<p>Object Value Query: <br />$s_Query</p>");
// -------------------------------------------------------
// db save methods (insert / replace (update) / delete)
// -------------------------------------------------------
* save the Object if $this->autoIncFld is not empty
* if (!empty($this->{$this->autoIncFld})) dbReplace is called else dbInsert
* overwrite in child classes to addopt to your needs
* @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
* @param boolean $debug SHOW DEBUG INFO
* @version pk-05-11-19 bugfix if no autoIncFld call replace
* @version pk-05-12-29 debug bugfix
* parame changed $mode -> $gDBIDX="USRDB",$debug=False
echoDebug(__FILE__
,__LINE__
,"<p>NO Auto Inc Field</p>");
* saves the object values
* @param boolean $clearFirst
if (!$this->hasObjVals()) return 0; // <pk-07-08-18 />
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"clear first:".
$s_Cmd);
$this->getDBObj('w')->executeCmd($s_Cmd);
foreach($this->myObjVals as $s_name =>
$a_row) {
if (!empty($a_row['OV_VALUE'])) {
if (empty($a_row['OV_TYPE'])) $a_row['OV_TYPE']=
"string";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"setting $s_name to (".
$a_row['OV_TYPE'].
") ".
$a_row['OV_VALUE']);
} else if (!$clearFirst) {
$s_Cmd =
"DELETE FROM ".
$this->myTable.
"_OV ";
$s_Cmd.=
" AND OV_NAME=".
$this->getDBObj('w')->qs_getSlashedValue($s_name);
$this->getDBObj('w')->executeCmd($s_Cmd);
* inserts a new row to the table
* @param boolean $debug show debug info
* @return int returns the autoIncFld ID if exists or 1 on success
* @version pk-08-03-07 linkedTables
if ($debug) echo
"<p>autoIncFld: ".
$this->autoIncFld.
"</p>";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<pre style=\"font-size: 75%\">".
print_r($a_row,True).
"</pre>");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<h1 style=\"color: red\">INSERT FAILED</h1>");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<h1 style=\"color: red\">INSERT FAILED</h1>");
* replaces a row in the table
* if the object has not been populated (!$this->populateTS)
* @param boolean $debug show debug info
* @param boolean $ignorPopulated (if False the table MUST have been populated)
* @version pk-07-12-06 $ignorPopulated added
function dbReplace($debug=
False,$ignorPopulated=
False)
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
if (empty($this->myTable)) { // into which table ??
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"dbReplace returns False: NO TABLE SET");
{ // table must be populated first
// this is for comatibility whith other dbs then mysql
// wich does not know REPLACE statement
// and REPLACE is done by insert and update
$this->setError("TABLE HAS NOT BEEN POPULATED");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"dbReplace returns False: TABLE HAS NOT BEEN POPULATED");
if ($debug) echo
"<blockquote>";
if ($debug) echo
"</blockquote>";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"dbReplace returns True");
foreach($arr_keys as $str_name =>
$arr_desc)
$arr_keyVals[$arr_desc['NAME']] =
$this->getDBField($arr_desc['NAME']);
//echo "KeyVals: <pre>".print_r($arr_keyVals,True)."</pre>";
foreach($arr_cmdRowList as $arr_cmdRow)
foreach($arr_keyVals as $str_col =>
$mix_val)
$arr_cmdRow['ROW'][$str_col] =
$mix_val;
switch($arr_cmdRow['CMD'])
$this->getDBObj('w')->insertArray($str_table,$arr_cmdRow['ROW'],$debug);
$this->getDBObj('w')->replaceArray($str_table,$arr_cmdRow['ROW'],$debug);
$this->getDBObj('w')->updateArray($str_table,$arr_cmdRow['ROW'],$debug);
$this->getDBObj('w')->deleteArray($str_table,$arr_cmdRow['ROW'],$debug);
ocsp_logError(__FILE__
,__LINE__
," linkedTable CMD " .
$arr_cmdRow['CMD'] .
" not implemented",E_ERROR);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"dbReplace returns False");
$this->setError("Konnte Datensatz nicht ersetzen");
* deletes the row from the database
* @param boolean $backupData
* @global array $OCSP_CONF
* @version pk-05-09-05 also delete object vals
* @version pk-05-11-17 bugfix output started
function dbDelete($backupData=
False,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,__LINE__
,"DBMS_TABLEOBJ::dbDelete($backupData,...)");
if (empty($this->myTable)) { // into which table ??
if ($debug) echo
"<p style='color=red;'>NO TABLE SET</p></blockquote><hr>";
if (!$this->populateTS) { // table must be populated first
// to be able to do the backup
if ($debug) echo
"<p style='color=red;'>TABLE HAS NOT BEEN POPULATED</p></blockquote><hr>";
$this->setError("LÖSCHEN: Datensatz nicht geladen");
ocsp_logError(__FILE__
,__LINE__
,"no database connection",E_ERROR);
$cmd=
"DELETE FROM ".
$this->myTable.
" ";
if (!($where=
$this->getWhere($debug))) {
$this->setError("LÖSCHEN: Keine WHERE Bedingung");
$int_backupMode=
(isset
($OCSP_CONF['DELBACKUPMODE']) ?
intval($OCSP_CONF['DELBACKUPMODE']) :
0);
switch($int_backupMode) {
// planed to add some different modes like db
if (empty($OCSP_CONF['BACKUPPATH'])) {
$backupDir=
$OCSP_CONF['BACKUPPATH'].
trim($this->myTable); // <pk-06-07-24 /> trim table name
foreach($this->myKeys as $key =>
$val) {
foreach($objVars as $var =>
$val) {
if (!empty($val)) { /* <pk-05-03-12> */
$varStr=
"b64Data['".
$var.
"']";
fwrite($fp,"\t\$".
$varStr.
"=\"".
$valStr.
"\";\n");
if ($this->hasObjVals()) // <pk-07-08-18 /> // <pk-05-09-05>
fwrite($fp,"\$a_b64OV=array();\n");
if ($o_cursor=
$this->getDBObj('r')->query($s_query)) {
while($a_row=
$o_cursor->fetchArrayFld()) {
if ($debug) echo
"<p style=\"color:red;font-weight:bold\">ERROR could not creat file ".
$backupDir.
"/".
$filename.
".rowsave".
"</p>";
if ($debug) echo
"<p style=\"color:red;font-weight:bold\">ERROR could not creat dir $backupDir</p>";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<blockquote><p>".
$cmd.
"</p></blockquote>");
if ($this->getDBObj('w')->executeCmd($cmd)) {
if ($this->hasObjVals()) // <pk-07-08-18 /> // <pk-05-09-05>
if ($debug) echo
"<blockquote>Deleting Object Vals<p>".
$s_cmd.
"</p></blockquote>";
$this->getDBObj('w')->executeCmd($s_cmd);
$this->setError("Konnte Datensatz nicht löschen");
// ----------------------------------------------------------
// ----------------------------------------------------------
* sets the row of an other table
* this method is used to cache form values of other tables
* which are joined in to $this->myTable
* this rows must be considert in insert,update,delete
* - _OCSP_DBCMD_INSERT_ (insert a new row)
* - _OCSP_DBCMD_REPLACE_ (update an existing row or insert if not exists)
* - _OCSP_DBCMD_UPDATE_ (update an existing row)
* - _OCSP_DBCMD_DELETE_ (delete an existing row)
* handels linked tables after insert
foreach($arr_tblEntries as $arr_rowcmd)
$this->saveLinkedRow($str_tbl,$arr_rowcmd['ROW'],$arr_rowcmd['CMD'],$debug);
* saves a linked row due to $cmd
* @param string $cmd (_OCSP_DBCMD_*)
foreach($this->myKeys as $str_col =>
$arr_desc)
$row[$str_col] =
$mix_val;
return $this->getDBObj('w')->insertArray($table,$row,$debug);
return $this->getDBObj('w')->replaceArray($table,$row,$debug);
return $this->getDBObj('w')->updateArray($table,$row,$debug);
return $this->getDBObj('w')->deleteArray($table,$row,$debug);
if ($debug) ocsp_logError(__FILE__
,__LINE__
," linkedTable CMD " .
$arr_cmdRow['CMD'] .
" not implemented",E_ERROR);
// ---------------------------------------------------------
// ---------------------------------------------------------
* returns if the table as a column named $colName
if (isset
($this->myFields[$colName])) return True;
* returns the value of a db column
* NOTE no check of the value is accurate
* @param string $aColumn (name of the db column and the obj var holding the value of the column)
* @param boolean $autoPopulate (populate the row if keysAreSet)
* @version pk-07-08-22 check if the object is populated
* @version pk-07-10-21 $autoPopulate to avoid enless loops
public function getDBField($aColumn,$debug=
False,$autoPopulate=
True)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"WARNING: " .
$aColumn .
" not in table " .
$this->myTable);
if ($debug) ocsp_logError(__FILE__
,__LINE__
,get_class($this).
" not populated when getting field $aColumn",E_NOTICE);
if (isset
($this->{$aColumn}))
return $this->{$aColumn};
* sets the value of a object var (DB COLUMN)
* NOTE: does not save youe have to call DBMS_TBLOBJ::dbsave() to save
* the value permanently in the database
* @param string $aField DB Column Name or Obj Field
* @param mixed $aValue the value to set
* @param boolean $debug since pk-05-07-28
* @param boolean $strict do not use objVals
public function setDBField($aField,$aValue,$debug=
False,$strict=
False) {
if ($this->hasObjVals() &&
(!isset
($this->myFields[$aField])) &&
(!$strict)) { // <pk-07-08-18 />
} else if (isset
($this->myFields[$aField])) {
} else if ((!$strict) &&
(!empty($aField))) { // <pk-06-10-24 />
* sets the value of an object var (DB COLUMN) if it differs with $aValue
* if you use this method you can check with $this::hasChanged() method if
* the object values differs from the database value.
* @param string $aField DB Column Name or Obj Field
* @param mixed $aValue the value to set
* @param boolean $debug since pk-05-07-28
if ($s_curVal !=
strval($aValue)) {
* sets the value of an column if it is empty or not set
* if you use this method you can check with $this::hasChanged() method if
* the object values differs from the database value.
* @param string $aField DB Column Name or Obj Field
* @param mixed $aValue the value to set
* @param boolean $debug since pk-05-07-28
* sets an object var if it's empty or null
* NOTE the object var has to be set already
* NOTE does not set the changed flag
* @return boolean (the value has been set)
if (isset
($this->{$varName}) &&
empty($this->{$varName}))
$this->{$varName}=
$value;
* returns an object value value
* @param boolean $autoPopulate
* sets an object value value
if ($debug) echo
"<p><b>DBMS_TABLEOBJ::setObjValValue($key,...)</b> (".
get_class($this).
")</p>";
* returns the object value array
if (isset
($this->{$this->autoIncFld})) // <pk-08-06-19>
* sets an array of values as object values
foreach($valArr as $s_key =>
$s_val) {
* returns a database form
* @param int $mode dbms form show mode
* @param string $frmName dbms form name
* @param boolean $debug since pk-05-01-11
* @param boolean $autonew generate a default form if no form is found
* @version pk-05-11-29 if $frmName like 'ID:000' it is asumed to be the form id
* @requires __OCSP_PHPINCPATH__."db/forms/forms.phpinc";
* @deprecated since pk-07-08-16
function &dbGetForm($mode,$frmName=
"",$debug=
False,$autoNew=
False) {
if ((empty($frmName)) &&
(empty($this->myTable))) { // no form ??
if ($debug) echo
"<p style='color=red;'>NO form</p>";
if (empty($frmName)) $frmName=
$this->myTable;
//if (!is_object($frmObj) && ($frmName != $this->myTable)) {
// $frmObj=&DBMS_form_loadName($frmName,$debug);
if (!empty($this->myClassSrcFile)) { // <pk-05-01-31>
if ($debug) echo
"<p>myClassSrcFile=".
$this->myClassSrcFile.
"</p>";
$frmObj->myDBMS_TABLEOBJ_include=
$this->myClassSrcFile;
$frmObj->myDBMS_TABLEOBJ_class =
get_class($this);
$frmObj->setFrmMode($mode);
* returns the required form name
* normaly this function return Null to let $this->getForm decide
* which form ($this->getMyTable()) to use. In some subclasses it can
* be useful to overwrite this methode to get a special form
* This is also a way to tell ajax reloads to change form. in jOCSP/formRPC.php
* is checked wether the currently loaded form (from the environment) fits to
* the forms tableobject if this function returns a value.
* returns the form class name to use
* if you overwrite this method make sure the returned form
* class source has been included
* replaces dbGetForm and returns a OCSP_FORM
* @param mixed $form (string) form name (int) form id
* @requires db/forms/OCSP_FORM.phpclass
* @version pk-08-11-01 getFormName() & getFormClassName added
function &getForm($mode=
FRM_MODE_READONLY,$form=
'',$frmClass=
'OCSP_FORM',$debug=
False)
$obj_form=
OCSP_FORM::factory_from_Name($form,$frmClass,$debug);
$obj_form->setMyTblObj($this);
$obj_form->setTblObjInc($str_classSrc);
} else if (!empty($this->myClassSrcFile)) {
$obj_form->setTblObjInc($this->myClassSrcFile);
ocsp_logError(__FILE__
,__LINE__
,"no source file for " .
get_class($this) .
" (" .
$str_classSrc .
");",E_WARNING);
$obj_form->setFrmMode($mode);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"form loaded Mode: $mode/".
$obj_form->getFrmMode());
//ocsp_logError(__FILE__,__LINE__,"Class: ".get_class($this)." Table: ".$this->myTable.":<br />could not get OCSP_FORM fallback to old method",E_NOTICE);
//return $this->dbGetForm($mode,$frmName,$debug,False);
* returns the db default value for aField
if (isset
($this->myFields[$aField]['DEFAULT'])) {
return $this->myFields[$aField]['DEFAULT'];
* returns an array of db default values
foreach($this->myFields as $key =>
$val) {
if (isset
($val['DEFAULT'])) {
$ret[$key]=
$val['DEFAULT'];
* sets the database default values to the fields
* COUTION overrides populated values
* @param boolean $debug show debug info
foreach($this->myFields as $key =>
$val) {
if (isset
($val['DEFAULT'])) {
$this->$key=
$val['DEFAULT'];
* returns a field => value array for dbms
* use this in cms and dbms elements to get
* overwrite this and add some special values
* @param boolean $setFIELDS if True $ret['_DBMS_FIELDS'] is filled
* @param boolean $debug show debug info?
* @param boolean $withObjVars add object var values to the returned array
* @version pk-04-08-10 debug info changed
* @version pk-06-05-21 debugging
function getDBVal($setFIELDS=
False,$debug=
False,$withObjVars=
True) {
if ($debug) {echo
"<pre>myFields\n";foreach($this->myFields as $key =>
$valArr){echo
"$key\n";};echo
"</pre>";}
foreach($this->myObjVals as $s_Name =>
$a_Row) {
$ret[$s_Name]=
$a_Row['OV_VALUE'];
$ret['_DBMS_FIELDS'].=
$sep.
$s_Name;
$debug=
True; echoDebugLine(__FILE__
,__LINE__
,"\$this->myFields NOT SET");
foreach($this->myFields as $key =>
$val) {
if (isset
($this->{$key})) {
$ret[$key]=
$this->{$key};
$ret['_DBMS_FIELDS'] .=
$sep.
$key;
if ($debug) echo
"$key not set <br />";
if ($debug) echo
"</blockquote>";
* returns a field => value array
* used also in insert and update statements
* make sure to not include some special values
* and object columns are serialised
* @param boolean $withoutNull if True null values are not added to the array
* @param boolean $withoutOV if False and $this->hasObjVals() the object value array is added with index __OCSP_OBJ_VALS__
* @param boolean $fldAutoPopulate
* done empty is not equal null !! pk-03-10-22
* @version pk-06-07-31 check if $this->myFields is an array
function getDBRow($withoutNull=
True,$debug=
False,$withoutOV=
False,$fldAutoPopulate=
True)
foreach($this->myFields as $str_key =>
$arr_dbDesc) {
$m_retVal=
$this->getDBField($str_key,$debug,$fldAutoPopulate);
$arr_ret[$str_key]=
$m_retVal;
$arr_ret[$str_key]=
$m_retVal;
* returns the the data array of a joins to the current row
* - $this->myTable must have an autoIncFld
* - the foreign table must have a column called like $this->autoIncFld
* - getDBField($this->autoIncFld) must return a value
* NOTE treats the join like 1:1 key means only the first matching row is returned
* @param array $filter (array(COLUMN => VALUE))
* @param boolean $withObjVars
* @todo DBMS_TABLEOBJ::dbGetDataArray() check the filter if the columns exists in foreign table
function dbGetDataArray($tables,$filter=
NULL,$withObjVars=
True,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,__LINE__
,"DBMS_TABLEOBJ::dbGetDataArray()","Tables: <pre>".
print_r($tables,True).
"</pre>Filter:<pre>".
print_r($filter,True).
"</pre>");
$arr_ret=
$this->getDBVal(False,$debug,$withObjVars);
foreach($tables as $str_tbl)
if ($arr_tmp=
$this->getDBObj('r')->getArray($str_tbl,$filter,0,1,$debug))
* sets all fields of an array to the objcet
function setDBVal($valArr,$debug=
False) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"\$valArr is not an array");
foreach($valArr as $s_key =>
$s_val) {
$str_debug =
"<p>setDBVAL():</p>";
$str_debug =
"<table><tr><th>\$valArr</th><th>DBVAL</th></tr><tr>";
$str_debug.=
"<td><pre>".
print_r($valArr,True).
"</pre></td>";
$str_debug.=
"</tr></table>";
return True; // <pk-05-10-04 />
* sets a database row to the object fields
* sets each key (=columname) value
* if $row['__OCSP_OBJ_VALS__'] isset and an array this values are set as object values
* else if $asPopulated object values are loaded
* @param array $row the row form a select * from DBMS_TABLEOBJ::myTable
* @param boolean $asPopulated set populateTS as if the object has been populated
* @since pk-03-12-13 more debug infos
function setDBRow($row,$asPopulated=
True,$debug=
False)
foreach($row as $key =>
$val) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"<pre style=\"font-size: 80%;padding-left:30px\">$str_debugOut</pre>");
ocsp_logError(__FILE__
,__LINE__
,"no row passed to set DBROW",E_WARNING);
if (isset
($row['__OCSP_OBJ_VALS__']))
if (is_array($row['__OCSP_OBJ_VALS__']))
} else if ($asPopulated) {
$this->myObjVals=
array(); // clear object vals
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"Object Values not loaded",E_NOTICE);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"setDBRow Returns: " .
($bol_ret ?
'True' :
'False'));
// #------------------------------------------------------------------#
// #------------------------------------------------------------------#
* @param boolean $fullMode
echo
"<h2 align=\"center\">DEBUGGING ".
get_class($this).
" </h2>";
echo
"array property: \t$var (".
sizeof($this->{$var}).
")\n";
echo
"object property:\t$var (Class: ".
get_class($this->{$var}).
")\n";
// #------------------------------------------------------------------#
// # CLASS AND CACHE METHODS PRIVATE USE ONLY #
// #------------------------------------------------------------------#
* overwrite in class implementation
* class method sets $this->myFields
$fields =
DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['fields'];
DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['fields'] =
$fields;
foreach($fields as $key =>
$fld) {
if ($fld['PRIMARY_KEY']) {
$this->myKeys[$key]['NAME']=
$key;
$this->myKeys[$key]['TYPE']=
$fld['TYPE'];
$this->myKeys[$key]['AUTO_INCREMENT']=
$fld['AUTO_INCREMENT'];
if ($fld['AUTO_INCREMENT'])
* PROTECTED check if cache is expired
* returns if chache has reached
* OCSP_OBJ::getConf('OBJCACHEPATH')
if (sizeof($this->myFields) <
2) { /*<pk-04-01-02 /> bugfix $sizeof($this->fields) */
if ($debug) echo
"<p>RETURN False (sizieof(\$this->myFields))</p>";
* PROTECTED get the name of the cache file
* returns the full path to the cache file name
* or False if cacheing is disabled by
* not setting $GLOBALS['PROJECT']['OBJCACHEPATH']
* @version pk-06-05-27 mytable added to filename
if (!empty($str_cacheDir)) {
// does not make sense to chache for such a shorte periode
* PROTECTED cache object to filesystem
* writes CLASS Variables to class Cache-File
* @returns bool False if an error occured or cacheing is disabled
if ($debug) echo
"<blockquote><p>OBJECT NOT INITIALIZED</p></blockquote>";
// only initialized objects can be cached
if ($debug) echo
"<blockquote><p>CACHE DISABLED</p></blockquote>";
if ($debug) echo
"<blockquote><p>Unable to create cache dir: ".
dirname($cacheFile).
"</p></blockquote>";
if ($fp=
fopen($cacheFile,"w")) {
//if (!sizeof($this->myKeys)) { $this->c_GetKeys(); }
//fwrite($fp," \$fields=\"".str_replace('"','\"',serialize($this->myFields))."\";\n");
fwrite($fp," \$this->hasObjVals=".
($this->hasObjVals() ?
"True" :
"False").
";\n"); // <pk-05-07-13 /> // <pk-07-08-18 />
return False; // file could not be opened
* looks for a class cache an laods it if possible
* @global array $OCSP_VAL
if ($debug) echo
"<blockquote><p>including file</p></blockquote>";
// $GLOBALS['OCSP_DBMS'][$this->get_gDBIDX()][$this->myTable]=unserialize($fields);
// $this->myFields =&$GLOBALS['OCSP_DBMS'][$this->get_gDBIDX()][$this->myTable]; /* <pk-04-12-21 /> */
if ($debug) echo
"<blockquote><p>no file</p></blockquote>";
// #------------------------------------------------------------------#
// #------------------------------------------------------------------#
* xmlExport of a Table Object
* NEED TO BE OVERWRITTEN!!!
function xmlExport($xmlfile=
"",$base64=
True,$debug=
False) {
if ($debug) echo
"<p><b>DBMS_TABLEOBJ::xmlExport($xmlfile,$base64,$debug)</b> (".
get_class($this).
")</p>";
if (empty($xmlfile)) return False;
$xmlfile=
$GLOBALS['PROJECT']['DBEXPORT'].
$this->getName().
".xml";
$domObj =
new domDocument();
$domRoot =
$domObj->createElement($this->myTable.
"_LIST");
$domObj->appendChild($domRoot);
* adds TableObject Contents to domRoot
* @param mixed &$domObj //reference to Parent DomObject
* @param string $domRoot //reference to Parent DomRoot
$valRoot =
$domObj->createElement($this->myTable);
$domRoot->appendChild($valRoot);
$TblContents =
$this->getDBRow(False,$debug);
foreach ($TblContents as $TblFld =>
$FldVal)
$str_xmlVal =
($FldVal ?
1 :
0);
$domElem =
$domObj->createElement($TblFld,utf8_encode($str_xmlVal));
$valRoot->appendChild($domElem);
/*** JSON ---------------------------------------- */
* returns a json string for the object data
Documentation generated on Thu, 08 Jan 2009 17:43:52 +0100 by phpDocumentor 1.4.0a2