Exemple #1
0
 /**
  *  do an integrity check on the fields
  *  
  *  @since  12-9-11      
  *  @param  MingoTable  $table
  *  @param  array $map  the key/value map that will be added to $table  
  *  @return array the $map with the best fields possible
  */
 protected function assureFields(MingoTable $table, array $map)
 {
     // do some checks on the fields...
     foreach ($table->getFields() as $field_name => $field) {
         if ($field->isRequired()) {
             if (!array_key_exists($field_name, $map)) {
                 $req_field_val = $field->getDefaultVal();
                 if ($req_field_val !== null) {
                     $map[$field_name] = $req_field_val;
                 } else {
                     throw new DomainException(sprintf('cannot set() because $map is missing required field: [%s]', $field_name));
                 }
                 //if/else
             }
             //if
         }
         //if
         if ($field->isUnique()) {
             if (isset($map[$field_name])) {
                 $where_criteria = new MingoCriteria();
                 $where_criteria->isField($field_name, $map[$field_name]);
                 if ($this->getOne($table, $where_criteria)) {
                     throw new DomainException(sprintf('cannot set() on table %s because field [%s] with value [%s] is not unique', $table->getName(), $field_name, $map[$field_name]));
                 }
                 //if
             }
             //if
         }
         //if
     }
     //foreach
     return $map;
 }