Custom Classess: BizDataObj

OpenBiz will use the BizDataObj php class in order to save data defined in the XML BizDataObj file.  This can be overridden by specifying another file by editing the BizDataObj XML file from:

<?xml version="1.0" encoding="UTF-8"?>
<BizDataObj AccessRule="" Class="BizDataObj" DBName="my_camp_office" DeleteCondition="" Description="Add description of BizDataObj" IdGeneration="Identity" InheritFrom="" Name="BOAccount" OtherSQLRule="" Package="account" SearchRule="" SortRule="" Table="account" UpdateCondition="">
<BizFieldList>

to

<?xml version="1.0" encoding="UTF-8"?>
<BizDataObj AccessRule="" Class="account.BOAccount" DBName="my_camp_office" DeleteCondition="" Description="Add description of BizDataObj" IdGeneration="Identity" InheritFrom="" Name="BOAccount" OtherSQLRule="" Package="account" SearchRule="" SortRule="" Table="account" UpdateCondition="">
<BizFieldList>

This new entry specifies a destination and file in realation to your application's bin folder.  Something like:

MYAPPLICATION/bin/account/BOAccount.php

That is the easy part, now we have to create a new class that we will customize for writing data to the database.   But first, a word about OpenBiz's BizDataObj class.

The BizDataObj has a couple of functions that handle your basic CRUD operations.  These are the functions that you oftern times want to override in your custom class. 

CREATE:  InsertRecord(&$recArr, $exsitingRecord=false)
READ:     Query($page)
UPDATE:  UpdateRecord(&$recArr)
DELETE:  DeleteRecord($recArr=null, $cascadeObjNames=null)

Further inspection shows that these functions follow a basic pattern.  Build the SQL query, connect to the database and run the query performing the occassional helper function along the way.   If you have complex Create/Update/Delete queries you plan to run, consider overwriting these functions in your custom class.   You can skip OpenBiz's BuildQuery function and write you own queries directly.  Heck, go crazy and write several queries and run them all from within one of these functions.  For example...

  public function UpdateRecord(&$recArr)
   {
    .......
      //$sql = $this->BuildUpdateSQL();
      $sql = "UPDATE tablex SET columna='value' where index_id = ".$recArr['id']."';";
      BizSystem::log(LOG_DEBUG, "DATAOBJ", "Update Sql = $sql");
      $db = $this->GetDBConnection();
      try {
         $db->query($sql);
      }
      catch (Exception $e) {
         $this->m_ErrorMessage = "Error in query: " . $sql . ". " . $e->getMessage();
         return null;
      }

      $sql = "UPDATE tabley SET columna='value2' where index_id = ".$recArr['id']."';";
      BizSystem::log(LOG_DEBUG, "DATAOBJ", "Update Sql = $sql");
      $db = $this->GetDBConnection();
      try {
         $db->query($sql);
      }
      catch (Exception $e) {
         $this->m_ErrorMessage = "Error in query: " . $sql . ". " . $e->getMessage();
         return null;
      }
.....

}

**Warning** Some functions in BO are set to be private and may not be called from an inheriting class.  I went into the BizDataObj class and changed them to protected.

Some developers may have only modest changes to the SQL queries generated they should consider overridding a CRUD functions BuildQuery function.

 

I've run out of time and have to go but more to come!