/**
  * returns a Tinebase_Record_Diff record with differences to the given record
  * 
  * @param Tinebase_Record_Interface $_record record for comparison
  * @param array $omitFields omit fields (for example modlog fields)
  * @return Tinebase_Record_Diff|NULL
  */
 public function diff($_record, $omitFields = array())
 {
     if (!$_record instanceof Tinebase_Record_Abstract) {
         return $_record;
     }
     $result = new Tinebase_Record_Diff(array('id' => $this->getId(), 'model' => get_class($_record)));
     $diff = array();
     foreach (array_keys($this->_validators) as $fieldName) {
         if (in_array($fieldName, $omitFields)) {
             continue;
         }
         $ownField = $this->__get($fieldName);
         $recordField = $_record->{$fieldName};
         if ($fieldName == 'customfields' && is_array($ownField) && is_array($recordField)) {
             // special handling for customfields, remove empty customfields from array
             foreach (array_keys($recordField, '', true) as $key) {
                 unset($recordField[$key]);
             }
             foreach (array_keys($ownField, '', true) as $key) {
                 unset($ownField[$key]);
             }
         }
         if (in_array($fieldName, $this->_datetimeFields)) {
             if ($ownField instanceof DateTime && $recordField instanceof DateTime) {
                 /** @var Tinebase_DateTime $recordField */
                 if (!$ownField instanceof Tinebase_DateTime) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Convert ' . $fieldName . ' to Tinebase_DateTime to make sure we have the compare() method');
                     }
                     $ownField = new Tinebase_DateTime($ownField);
                 }
                 if ($ownField->compare($recordField) === 0) {
                     continue;
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' datetime for field ' . $fieldName . ' is not equal: ' . $ownField->getIso() . ' != ' . $recordField->getIso());
                     }
                 }
             } else {
                 if (!$recordField instanceof DateTime && $ownField == $recordField) {
                     continue;
                 }
             }
         } else {
             if ($fieldName == $this->_identifier && $this->getId() == $_record->getId()) {
                 continue;
             } else {
                 if ($ownField instanceof Tinebase_Record_Abstract || $ownField instanceof Tinebase_Record_RecordSet) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Doing subdiff for field ' . $fieldName);
                     }
                     $subdiff = $ownField->diff($recordField);
                     if (is_object($subdiff) && !$subdiff->isEmpty()) {
                         $diff[$fieldName] = $subdiff;
                     }
                     continue;
                 } else {
                     if ($recordField instanceof Tinebase_Record_Abstract && is_scalar($ownField)) {
                         // maybe we have the id of the record -> just compare the id
                         if ($recordField->getId() == $ownField) {
                             continue;
                         } else {
                             $recordField = $recordField->getId();
                         }
                     } else {
                         if ($ownField == $recordField) {
                             continue;
                         } else {
                             if (empty($ownField) && empty($recordField)) {
                                 continue;
                             } else {
                                 if (empty($ownField) && $recordField instanceof Tinebase_Record_RecordSet && count($recordField) == 0 || empty($recordField) && $ownField instanceof Tinebase_Record_RecordSet && count($ownField) == 0) {
                                     continue;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Found diff for ' . $fieldName . '(this/other):' . print_r($ownField, true) . '/' . print_r($recordField, true));
         }
         $diff[$fieldName] = $recordField;
     }
     $result->diff = $diff;
     return $result;
 }