From 632873595baef1de80d678572d34b6e40cd13e00 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 28 Aug 2015 23:45:16 +0200 Subject: [PATCH] show/activitylog: show object syntax, not props --- application/controllers/ShowController.php | 25 ++++++++++++ .../scripts/show/activitylog-create.phtml | 21 +--------- .../scripts/show/activitylog-modify.phtml | 40 ++++--------------- 3 files changed, 34 insertions(+), 52 deletions(-) diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php index 9782f28a..f811d8ee 100644 --- a/application/controllers/ShowController.php +++ b/application/controllers/ShowController.php @@ -1,6 +1,7 @@ view->entry = $this->db()->fetchActivityLogEntry(Util::hex2binary($checksum)); } + $entry = $this->view->entry; + + if ($entry->old_properties) { + $old = $this->createObject($entry->object_type, $entry->old_properties); + if ($entry->new_properties) { + $new = $this->createObject($entry->object_type, $entry->old_properties); + $new->setProperties((array) json_decode($entry->new_properties)); + } else { + $new = null; + } + } else { + $old = null; + $new = $this->createObject($entry->object_type, $entry->new_properties); + } + + $this->view->entry = $entry; + $this->view->newObject = $new; + $this->view->oldObject = $old; $this->view->title = $this->translate('Activity'); } + + protected function createObject($type, $props) + { + $props = json_decode($props); + return IcingaObject::createByType($type, (array) $props, $this->db()); + } } diff --git a/application/views/scripts/show/activitylog-create.phtml b/application/views/scripts/show/activitylog-create.phtml index 9820d101..54f8779e 100644 --- a/application/views/scripts/show/activitylog-create.phtml +++ b/application/views/scripts/show/activitylog-create.phtml @@ -4,24 +4,5 @@ $entry->object_name ) ?> -

translate('Properties') ?>

- - -new_properties); - -foreach ($new as $key => $value) { - if ($key === 'id') continue; - - if ($value === null) continue; - - if (is_array($value)) $value = implode(', ', $value); - if (is_object($value)) $value = json_encode($value); - - echo ' \n"; -} -?> -
' . $this->escape($key) . ''; - echo $this->escape($value); - echo "
+
escape((string) $this->newObject) ?>
diff --git a/application/views/scripts/show/activitylog-modify.phtml b/application/views/scripts/show/activitylog-modify.phtml index b392988c..4b53eaa4 100644 --- a/application/views/scripts/show/activitylog-modify.phtml +++ b/application/views/scripts/show/activitylog-modify.phtml @@ -4,38 +4,14 @@ $entry->object_name ) ?> -

translate('Properties') ?>

- -old_properties); -$new = json_decode($entry->new_properties); - -foreach ($old as $key => $value) { - if ($key === 'id') continue; - - $modified = array_key_exists($key, $new); - - if ($value === null && ! $modified) continue; - - if (is_array($value)) $value = implode(', ', $value); - if (is_object($value)) $value = json_encode($value); - - echo ' \n"; -} -?> + +
' . $this->escape($key) . ''; - if ($modified) { - $newval = $new->$key; - if (is_array($newval)) $newval = implode(', ', $newval); - if (is_object($newval)) $newval = json_encode($newval); - printf( - '%s %s', - $this->escape($value), - $this->escape($newval) - ); - } else { - echo $this->escape($value); - } - echo "
+

translate('Former state') ?>

+
escape((string) $this->oldObject) ?>
+
+

translate('New object') ?>

+
escape((string) $this->newObject) ?>
+