Example #1
0
 /**
  * This method checks if there is any data prepared for record or it uses
  * default data based on type of the field.
  *
  * It looks for data for each field in record in following order:
  * 1. Checks if data is set in DataObject
  * 2. Checks data from data container (@see setData())
  * 3. Checks data from $defaultValues variables defined in each DataObject
  * 4. Generate data based on type of the field
  *
  * It populates primary keys fields only if data for key field was specifically
  * set using any of methods defined in 1, 2 or 3 (it doesn't
  * populate it with default data based on field type)
  *
  * @param DataObject $do    DataObject to populate data in
  * @param int $counter      Used to generate a key for data container array to retreive data
  * @access package private
  * @static
  */
 function setDefaultValues(&$do, $counter = 0)
 {
     $fields = $do->table();
     $keys = $do->keys();
     $table = $do->getTableWithoutPrefix();
     foreach ($fields as $fieldName => $fieldType) {
         if (!isset($do->{$fieldName})) {
             if (!empty($this) && is_a($this, 'DataGenerator')) {
                 $fieldValue = $this->getFieldValueFromDataContainer($table, $fieldName, $counter);
             } else {
                 $fieldValue = DataGenerator::getFieldValueFromDataContainer($table, $fieldName, $counter);
             }
             if (!isset($fieldValue) && !in_array($fieldName, $keys)) {
                 $fieldValue = DataGenerator::defaultValueForObject($do, $fieldName, $fieldType);
                 if (!isset($fieldValue)) {
                     $fieldValue = DataGenerator::defaultValueByType($fieldType);
                 }
             }
             if (isset($fieldValue)) {
                 if ($fieldValue != OA_DATAOBJECT_DEFAULT_NULL) {
                     // exception for NULLs
                     $do->{$fieldName} = $fieldValue;
                 }
             }
         }
     }
 }