本文整理汇总了PHP中Tinebase_DateTime::diff方法的典型用法代码示例。如果您正苦于以下问题:PHP Tinebase_DateTime::diff方法的具体用法?PHP Tinebase_DateTime::diff怎么用?PHP Tinebase_DateTime::diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tinebase_DateTime
的用法示例。
在下文中一共展示了Tinebase_DateTime::diff方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diff
/**
* 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;
}