Jarves\Utils::generateDiff PHP Метод

generateDiff() защищенный Метод

protected generateDiff ( Objects $repo, $objectKey, $origItem ) : string
$repo Objects
$objectKey
$origItem
Результат string
    protected function generateDiff(Objects $repo, $objectKey, $origItem)
    {
        $pk = $repo->getObjectPk($objectKey, $origItem);
        $currentItem = $repo->get($objectKey, $pk);
        $definition = $repo->getDefinition($objectKey);
        $changes = [];
        foreach ($definition->getFields() as $field) {
            if ($field->hasFieldType() && !$field->getFieldType()->isDiffAllowed()) {
                //todo, check $field->isDiffAllowed() as well
                continue;
            }
            $k = $field->getId();
            if (!isset($origItem[$k]) || !isset($currentItem[$k])) {
                continue;
            }
            if (!is_string($origItem[$k]) && !is_numeric($origItem[$k])) {
                continue;
            }
            if (!is_string($currentItem[$k]) && !is_numeric($currentItem[$k])) {
                continue;
            }
            $from = strip_tags($origItem[$k]);
            $to = strip_tags($currentItem[$k]);
            if ($from != $to) {
                $htmlDiff = new HtmlDiff($from, $to, true);
                $out = $htmlDiff->outputDiff();
                $changes[$k] = $out->toString();
            }
        }
        $message = [];
        foreach ($changes as $changedKey => $diff) {
            if ($field = $definition->getField($changedKey)) {
                $message[] = ($field->getLabel() ?: $field->getId()) . ': ' . $diff;
            }
        }
        return $message ? '<div class="change">' . implode('</div><div class="change">', $message) . '</div>' : '';
    }