2.0 User Contributed Guides

Members of the PHPOpenBiz community are encouraged to create additional pages in the manual and link to them here.

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!

 

Extending Permissions In OB

**DRAFT**

A permission scheme that can be customized using OB forms.

XML is pretty cool but sometimes you want to create parts of an application that can be modfied by users from the web.  On a current project I'm working on, I need to implement a permission system that allows the following:
-Staff can be in more than one role
-Staff determine which views are accessible to which roles

I will demonstrate how to create an interface allowing your users to modify permissions and roles via ordinary BizForms and BizObjs.  The key to this setup is replacing the access XML file with a database table.  This way OB's builtin Forms/Objs can be used to modify access permissions.

  • A sequence of steps can be broken down as...
  • Create tables in database
  • Create BizForms/Objects to manipulate tables
  • Override standard Profile class
  • Override standard Access class

My permissions system uses the following tables:

staff - holds basic user information with which to hold user accounts
list -  This is a generic table that I use to store any simple lists.  For this example, we'll store a list of Roles and Views.
view - a generic list of views that match the actual views in your application
role_staff - A join table connecting multiple roles to multiple staff
role_view - Another join table that assigns a views to a roles

Getting Custom Data into SMARTY

SMARTY is a neat templating engine and a nice compliment to PHPOpenBiz. In this Guide, I'll explain how I supply SMARTY with variables that contain my own custom business logic. The end result is a was to feed SMARTY templates variables containing simple arrays, strings or even full fledged blocks of HTML code.

The advantage is that OpenBiz can handle the scripting and feed SMARTY the end results in the form of HTML code or simple arrays to loop through. This strategy makes it easier to separate logic and theme data.

The 30 second version is:
Modify BizForm and BizView to call to a new function in each respective class called GetCustomVariables(&$Smarty) within the Render() or RenderHTML() function.

Than create child classes that override the GetCustomVariables($smarty) function adding new vars as needed. Once inside your custom child class that extends either BizForm or BizView you have plenty of room to operating in creating as many custom variables as you wish. You have access to the usual OpenBiz classes including that Forms BizDataObject.

TODO: What about making this a default feature within the BizForm and BizView?

OpenBiz 2.2 Requirements

Note: These are requirements for OpenBiz 2.2, for requirements involving 2.0 check here.

This is a list of requirements in order to use PHPOpenbiz 2.2 as well as it's supporting packages.

PHPOpenBiz
APC suggested
eAccelerator is a reported alternative
PHP 5.1 or greater
 *For installs greater than 5.1.6 see this fix...

Zend Framework
PDO extension and the PDO_YOURDATABASEOFCHOICE (ie. PDO_Mysql)
PHP 5.1 or greater

Smarty template engine