From ab19cc6149427ac991390b87839a58b997146ef6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 31 Jan 2019 10:05:43 +0100
Subject: [PATCH] :sparkles: feat(management) Add support for Unix Timestamp
 column

Used in alias plugin

issue #5135
---
 .../management/columns/class_LinkColumn.inc   | 19 +++++----
 .../columns/class_UnixTimestampColumn.inc     | 39 +++++++++++++++++++
 2 files changed, 51 insertions(+), 7 deletions(-)
 create mode 100644 include/management/columns/class_UnixTimestampColumn.inc

diff --git a/include/management/columns/class_LinkColumn.inc b/include/management/columns/class_LinkColumn.inc
index c6847b434..2fb06be0d 100644
--- a/include/management/columns/class_LinkColumn.inc
+++ b/include/management/columns/class_LinkColumn.inc
@@ -29,15 +29,20 @@ class LinkColumn extends Column
     if ($value == '') {
       return '&nbsp;';
     } else {
-      if ($this->parent->parent instanceof selectManagement) {
-        if ($this->parent->getMultiSelect()) {
-          return '<label title="'.$entry->dn.'" for="listing_selected_'.$entry->row.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</label>';
-        } else {
-          return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_select_'.$entry->row.'&amp;add_finish=1" title="'.$entry->dn.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</a>';
-        }
+      return $this->renderLink($entry, htmlentities($value, ENT_COMPAT, 'UTF-8'));
+    }
+  }
+
+  protected function renderLink(ListingEntry $entry, $htmlValue)
+  {
+    if ($this->parent->parent instanceof selectManagement) {
+      if ($this->parent->getMultiSelect()) {
+        return '<label title="'.$entry->dn.'" for="listing_selected_'.$entry->row.'">'.$htmlValue.'</label>';
       } else {
-        return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.htmlentities($value, ENT_COMPAT, 'UTF-8').'</a>';
+        return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_select_'.$entry->row.'&amp;add_finish=1" title="'.$entry->dn.'">'.$htmlValue.'</a>';
       }
+    } else {
+      return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$entry->getPid().'&amp;act=listing_edit_'.$entry->row.'" title="'.$entry->dn.'">'.$htmlValue.'</a>';
     }
   }
 }
diff --git a/include/management/columns/class_UnixTimestampColumn.inc b/include/management/columns/class_UnixTimestampColumn.inc
new file mode 100644
index 000000000..63e911fb4
--- /dev/null
+++ b/include/management/columns/class_UnixTimestampColumn.inc
@@ -0,0 +1,39 @@
+<?php
+/*
+  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
+  Copyright (C) 2018-2019  FusionDirectory
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+/*!
+ * \brief Column rendering unix timestamp
+ */
+class UnixTimestampColumn extends LinkColumn
+{
+  protected $type = 'integer';
+
+  function renderCell(ListingEntry $entry)
+  {
+    $value = $this->getAttributeValue($entry);
+    if ($value != '') {
+      $dateObject = DateTime::createFromFormat('U', $value, new DateTimeZone('UTC'));
+      if (is_object($dateObject)) {
+        return $this->renderLink($entry, $dateObject->format('d.m.Y'));
+      }
+    }
+    return '&nbsp;';
+  }
+}
-- 
GitLab