Handling Data

From No3wiki

back to Main Page > devguide

Handling Data

Mental note: This page is not complete. That db-layout has become more complex and I have to write something about the general db-layout and the item-table.

Flexiblity in handling the various fields of db-objects was one of the major topic while designing streber's framework. By now all db-querries are done by the classes in std/db_item.inc. To reduce the amount of code that is depending on certain db-fields, a complex interface is being provided by the dbItem-class. Look at these fragments from the task::__constructor in std/class_task.php:

   //====================================================================
   // Task
   //====================================================================
   class Task extends DbItem {
   
   
       //=== constructor ================================================
       function __construct ($array=false)
       {
           $this->_type="effort";
   
           #--- set up members-array ---
           #--- set up members ---
           # NOTE:
           # - we don't want the field-definition within every instance of task
           #   for initilizing inside DbItem we still need to define the fields,
           #   therefor we use a reference to an outside array.
           GLOBAL $effort_fields;
           if(!$effort_fields) {
               $effort_fields=array();
               foreach(array(
                   new FieldHidden(array('name'=>'id')),
                   new FieldString(array('name'=>'name','tooltip'=>'optional if tasks linked to this effort')),
                   new FieldDatetime(array('name'=>'time_start','default'=>FINIT_NOW)),
                   new FieldDatetime(array('name'=>'time_end','default'=>FINIT_NOW)),
                   new FieldUser(array('name'=>'user')),
                   new FieldDatetime(array('name'=>'created','view_in_forms'=>false,'default'=>FINIT_NOW)),
                   new FieldDatetime(array('name'=>'modified','view_in_forms'=>false,'default'=>FINIT_NOW)),
                   new FieldUser(array('name'=>'modified_by')),
                   new FieldProject(array('name'=>'project')),
                   new FieldText(array('name'=>'description')),
                   new FieldHidden(array('name'=>'state','default'=>1)),
               ) as $f) {
                   $effort_fields[$f->name]=$f;
               }
           $this->fields= &$task_fields;
   
   // additional setup follows...

Here we construct the complete interface to the db-format. The field-array allows us to automatically:

  • initializing a fresh sql-database
  • getting field-types of form-elements
  • converting database-style into readable code
  • checking validity of form-data
  • nicely setting default-values for new instances
  • querry db-attributes 'bydefault' and 'on demand'

In netoffice 2.x a change in the task-table had tremendous consequences through out the complete code. With this solution the changes are concentrated in the objectDefinintion.


What is necessary to create a form page

  1. add a new pageHandle to _handles.inc
  2. add an appropriate function to the required source-file in pages/
  3. add a basic framework of a page-function