Openbiz Best Practice1. Work on Openbiz metadata filesSince openbiz-based applications heavily depends on metadata files, editing metadata files is as important as writing code during application development. In a simple application, a web page includes a single data table that maps to a single database table. It is very easy to implement by configuring one BizDataObj, one BizForm and one BizView (this is covered by the simple tutorial). In case of building a complex application like CRM and school admin, database tables are related together by foreign keys, a page usually contains a driving form and multiple children forms which depends on the data of the driving form and one data object can be used in many places. Without careful design, managing metadata files becomes a tough job. This document is to discuss the best practice of managing your openbiz metadata files. In order to discuss the topic on a concrete base, a commercial CRM database schema from sugarcrm is used here. In the schema, the relationship between accounts table and contacts table is many-to-many. The intersection table of their relationship is accounts_contacts.
The requirement is to implement a contact page and and account page.
1.1 PreparationBefore starting editing the metadata files, we need to add database into openbiz eclipse plugin and openbiz application configurations. Metadata tree structure should be determined too.
1.2 Design the BizForm and BizDataObj objectsWhat are the objects in a view? A normal view with a little complexity may include a driving form and sub forms. A sub form may have a popup form to add a record into itself. Each form object has a corresponding data object behind it. We name the data object of the driving form as "main DO", the data object of a sub form as "reference DO" because it must be one of the ObjReferences of the main DO. Then we call the data object of a popup form as "popup DO".
When a BizDataObj has joined fields (from other tables' columns), users should be able to select a record on a popup form to join it to the base form. This base form can either be driving form or sub form.
Openbiz objects hierarchy Every database table should have a corresponding dataobj who has only fields mapping to its base table's columns. No join and object reference is in the dataobj. This dataobj is a slim dataobj that is the parent object of other fatter dataobj. If the parent dataobj includes all joins and object references, its children objects have them too. It'll hurt the performance. Other data objects (Main data object, Reference data object and Popup data object) inherit from the base data object.
A BizDataObj may be presented on UI with BizForms. Since different BizForms (even if they are based on same BizDataObj) usually have different UI layout which is rendered by smarty template, it might be easy to manage BizForms without inheritance. BizView is in fact a web page. Because web pages usually have different layout, inheritance is not well suitable for BizView. Naming convention of openbiz objects We need to have some naming convention of the objects so that we can tell the content of the objects from their names. Difference developers can different way to assigning names. In this article we uses prefix in the naming convention.
After knowing the objects in a view and objects hierarchy, applying the naming convention, finally we have objects chart drawn out as below.
1.3 Create Openbiz metadata filesDevelopers can recommended to use Openbiz Eclipse Plugin to compose Openbiz metadata files. Openbiz eclipse plugin provides several different ways to help developers to create Openbiz metadata files.
Once the metadata file created, open it with Openbiz Metadata editor to edit it in eclipse. Please see the Openbiz eclipse plugin user manual for more details. The the metadata file tree is shown as the following screenshot which is copied from eclipse Package Explorer view.
Other alternate metadata structure recommended by many other openbiz users separates BizDataObj, BizForm and BizView files under different directories. For example:
Change the Id generation algorithm for BizDataObj By looking at the sugarcrm tables, you would find the id (primary key) column does not generated with native mysql algorithm. Now we need to extend genIdService (Openbiz plugin service) to use application specific ID generation algorithm. - Create demoapp/bin/service/sugarIdService.php. Have a sugarIdService class extending from genIdService class and override GetNewID method.
- Create demoapp/metadata/service/genIdService.xml that is the metadata file of Id Generation Service plugin. Assign the class as sugarIdService.
- Assign BizDataObj's IdGeneration attribute as "sugarId". This attribute is used in GetNewId method of sugarIdService class. 1.4 Test viewsTo verify the your design works, open a browser and type in url http://localhost/demoapp/bin/controller.php?view=sugar.accounts.ViewAccounts http://localhost/demoapp/bin/controller.php?view=sugar.contacts.ViewContacts Verify the basic functionalities
1.5 Refine the metadata files
|
|||||||||||||||||||||||||||||||||||||||||||||





